medusajs/medusa-agent-skills/building-with-medusa
Claude Code and agent skill by medusajs/medusa-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Load automatically when planning, researching, or implementing ANY Medusa backend features (custom modules, API routes, workflows, data models, module links, business logic). REQUIRED for all Medusa backend work in ALL modes (planning, implementation, exploration). Contains architectural patterns, best practices, and critical rules that MCP servers don't provide.
Install
npx vskill@latest install medusajs/medusa-agent-skills/building-with-medusaSKILL.md
Medusa Backend Development
Comprehensive backend development guide for Medusa applications. Contains patterns across 6 categories covering architecture, type safety, business logic placement, and common pitfalls.
When to Apply
Load this skill for ANY backend development task, including:
- Creating or modifying custom modules and data models
- Implementing workflows for mutations
- Building API routes (store or admin)
- Defining module links between entities
- Writing business logic or validation
- Querying data across modules
- Implementing authentication/authorization
Also load these skills when:
- building-admin-dashboard-customizations: Building admin UI (widgets, pages, forms)
- building-storefronts: Calling backend API routes from storefronts (SDK integration)
CRITICAL: Load Reference Files When Needed
The quick reference below is NOT sufficient for implementation. You MUST load relevant reference files before writing code for that component.
Load these references based on what you're implementing:
- Creating a module? → MUST load
reference/custom-modules.mdfirst - Creating workflows? → MUST load
reference/workflows.mdfirst - Creating API routes? → MUST load
reference/api-routes.mdfirst - Creating module links? → MUST load
reference/module-links.mdfirst - Querying data? → MUST load
reference/querying-data.mdfirst - Adding authentication? → MUST load
reference/authentication.mdfirst
Minimum requirement: Load at least 1-2 reference files relevant to your specific task before implementing.
Critical Architecture Pattern
ALWAYS follow this flow - never bypass layers:
Key conventions:
- Only GET, POST, DELETE methods (never PUT/PATCH)
- Workflows are required for ALL mutations
- Business logic belongs in workflow steps, NOT routes
- Query with
query.graph()for cross-module data retrieval - Query with
query.index()(Index Module) for filtering across separate modules with links - Module links maintain isolation between modules
Rule Categories by Priority
| Priority | Category | Impact | Prefix | |
|---|---|---|---|---|
| 1 | Architecture Violations | CRITICAL | arch- | |
| 2 | Type Safety | CRITICAL | type- | |
| 3 | Business Logic Placement | HIGH | logic- | |
| 4 | Import & Code Organization | HIGH | import- | |
| 5 | Data Access Patterns | MEDIUM (includes CRITICAL price rule) | data- | |
| 6 | File Organization | MEDIUM | file- |
Quick Reference
1. Architecture Violations (CRITICAL)
arch-workflow-required- Use workflows for ALL mutations, never call module services from routesarch-layer-bypass- Never bypass layers (route → service without workflow)arch-http-methods- Use only GET, POST, DELETE (never PUT/PATCH)arch-module-isolation- Use module links, not direct cross-module service callsarch-query-config-fields- Don't set explicitfieldswhen usingreq.queryConfig
2. Type Safety (CRITICAL)
type-request-schema- Pass Zod inferred type toMedusaRequest<T>when usingreq.validatedBodytype-authenticated-request- UseAuthenticatedMedusaRequestfor protected routes (notMedusaRequest)type-export-schema- Export both Zod schema AND inferred type from middlewarestype-linkable-auto- Never add.linkable()to data models (automatically added)type-module-name-camelcase- Module names MUST be camelCase, never use dashes (causes runtime errors)
3. Business Logic Placement (HIGH)
logic-workflow-validation- Put business validation in workflow steps, not API routeslogic-ownership-checks- Validate ownership/permissions in workflows, not routeslogic-module-service- Keep modules simple (CRUD only), put logic in workflows
4. Import & Code Organization (HIGH)
import-top-level- Import workflows/modules at file top, never useawait import()in route bodyimport-static-only- Use static imports for all dependenciesimport-no-dynamic-routes- Dynamic imports add overhead and break type checkingimport-zod-framework- Import Zod from@medusajs/framework/zod, never fromzoddirectly. Medusa is on Zod v4 (since v2.14.0): usez.email()/z.url()/z.uuid()instead ofz.string().email()etc.,.extend(other.shape)instead of.merge(other),z.strictObject()/z.looseObject()instead of.strict()/.passthrough(),z.enum(MyEnum)instead ofz.nativeEnum(), andz.record(z.string(), value)instead ofz.record(value)
5. Data Access Patterns (MEDIUM)
data-price-format- CRITICAL: Prices are stored as-is in Medusa (49.99 stored as 49.99, NOT in cents). Never multiply by 100 when saving or divide by 100 when displayingdata-query-method- Usequery.graph()for retrieving data; usequery.index()(Index Module) for filtering across linked modulesdata-query-graph- Usequery.graph()for cross-module queries with dot notation (without cross-module filtering)data-query-index- Usequery.index()when filtering by properties of linked data models in separate modulesdata-list-and-count- UselistAndCountfor single-module paginated queriesdata-linked-filtering-query.graph()can't filter by linked module fields - usequery.index()or query from that entity directlydata-no-js-filter- Don't use JavaScript.filter()on linked data - use database filters (query.index()or query the entity)data-same-module-ok- Can filter by same-module relations withquery.graph()(e.g., product.variants)data-auth-middleware- Trustauthenticatemiddleware, don't manually checkreq.auth_context
6. File Organization (MEDIUM)
file-workflow-steps- Recommended: Create steps insrc/workflows/steps/[name].tsfile-workflow-composition- Composition functions insrc/workflows/[name].tsfile-middleware-exports- Export schemas and types from middleware filesfile-links-directory- Define module links insrc/links/[name].ts
Workflow Composition Rules
The workflow function has critical constraints:
Constraints:
- No async/await (runs at load time)
- No arrow functions (use
function) - No conditionals/ternaries (use
when()) - No variable manipulation (use
transform()) - No date creation (use
transform()) - Multiple step calls need
.config({ name: "unique-name" })to avoid conflicts
Common Mistakes Checklist
Before implementing, verify you're NOT doing these:
Architecture:
- [ ] Calling module services directly from API routes
- [ ] Using PUT or PATCH methods
- [ ] Bypassing workflows for mutations
- [ ] Setting
fieldsexplicitly withreq.queryConfig - [ ] Skipping migrations after creating module links
Type Safety:
- [ ] Forgetting
MedusaRequest<SchemaType>type argument - [ ] Using
MedusaRequestinstead ofAuthenticatedMedusaRequestfor protected routes - [ ] Not exporting Zod inferred type from middlewares
- [ ] Adding
.linkable()to data models - [ ] Using dashes in module names (must be camelCase)
Business Logic:
- [ ] Validating business rules in API routes
- [ ] Checking ownership in routes instead of workflows
- [ ] Manually checking
req.auth_context?.actor_idwhen middleware already applied
Imports:
- [ ] Using
await import()in route handler bodies - [ ] Dynamic imports for workflows or modules
Data Access:
- [ ] CRITICAL: Multiplying prices by 100 when saving or dividing by 100 when displaying (prices are stored as-is: $49.99 = 49.99)
- [ ] Filtering by linked module fields with
query.graph()(usequery.index()or query from other side instead) - [ ] Using JavaScript
.filter()on linked data (usequery.index()or query the linked entity directly) - [ ] Not using
query.graph()for cross-module data retrieval - [ ] Using
query.graph()when you need to filter across separate modules (usequery.index()instead)
Validating Implementation
CRITICAL: Always run the build command after completing implementation to catch type errors and runtime issues.
When to Validate
- After implementing any new feature
- After making changes to modules, workflows, or API routes
- Before marking tasks as complete
- Proactively, without waiting for the user to ask
How to Run Build
Detect the package manager and run the appropriate command:
Handling Build Errors
If the build fails:
- Read the error messages carefully
- Fix type errors, import issues, and syntax errors
- Run the build again to verify the fix
- Do NOT mark implementation as complete until build succeeds
Common build errors:
- Missing imports or exports
- Type mismatches (e.g., missing
MedusaRequest<T>type argument) - Incorrect workflow composition (async functions, conditionals)
Linting
Since Medusa v2.16.0, projects can install @medusajs/eslint-plugin, which catches violations of Medusa conventions (API routes, subscribers, scheduled jobs, admin customizations, module patterns) that a type check won't.
- If the project has an
eslint.config.*with@medusajs/eslint-plugin, `medusa build` and `medusa develop` run linting by default and fail on lint errors. Fix lint errors rather than passing--no-lint. - Run linting explicitly with
npx medusa lint(supports--fixand--quiet). Run it after implementing a feature, alongside the build. - If the project has no ESLint config, suggest adding it (
@medusajs/eslint-plugin,eslint, andjitias dev dependencies, then aneslint.config.tsexportingdefineConfig([...medusa.configs.recommended])) — but don't add it unprompted.
Next Steps - Testing Your Implementation
After successfully implementing a feature, always provide these next steps to the user:
1. Start the Development Server
If the server isn't already running, start it:
2. Access the Admin Dashboard
Open your browser and navigate to:
- Admin Dashboard: http://localhost:9000/app
Log in with your admin credentials to test any admin-related features.
3. Test API Routes
If you implemented custom API routes, list them for the user to test:
Admin Routes (require authentication):
POST http://localhost:9000/admin/[your-route]- Description of what it doesGET http://localhost:9000/admin/[your-route]- Description of what it does
Store Routes (public or customer-authenticated):
POST http://localhost:9000/store/[your-route]- Description of what it doesGET http://localhost:9000/store/[your-route]- Description of what it does
Testing with cURL example:
4. Additional Testing Steps
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/medusa-dev/skills/building-with-medusa/SKILL.md
Popularity
- Repository stars
- 123
- Repository forks
- 12
- 7-day trend score
- 24
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 1 Apr 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/medusajs/medusa-agent-skills/building-with-medusa)