medusa-development
Installation
SKILL.md
Medusa Development
Medusa is a headless commerce framework built around modules, data models, and workflows; almost every piece of business logic — from an API route to a scheduled job — should be expressed as a workflow made of discrete, composable steps.
Workflow for Building a Medusa Feature
- Define or extend the data model — Use the
modelutility from@medusajs/framework/utilsto declare the module's data model(s) undersrc/modules/<module>/models/. - Write the module service — Create a service in
src/modules/<module>/service.tsthat extendsMedusaServicewhen the module has data models, exposing async methods for domain operations. - Register the module — Add the module to
medusa-config.tsso Medusa's container can resolve it. - Build steps — Define each unit of work as a step with
createStepfrom@medusajs/framework/workflows-sdk, including a compensation function for anything that needs to be undone on failure. - Compose the workflow — Wire steps together with
createWorkflow, usingtransformfor data shaping andwhenfor conditional branches. - Expose the workflow — Call the workflow from an API route, a scheduled job, or a subscriber — never put business logic directly in the route/job/subscriber handler.
- Read data with Query — Use Medusa's Query (
req.scope.resolve("query")or the workflow-leveluseQueryGraphStep) to fetch data instead of calling module services directly for reads.
General Rules
- Don't use type aliases when importing files — import types and values directly from their source module rather than re-exporting through a local alias.
- When throwing errors, always throw
MedusaError(from@medusajs/framework/utils) instead of a plainError, so the API layer can map it to the correct HTTP status and error code. - Always use Query to retrieve data rather than calling a module's service methods directly for reads — Query understands module links and can join data across modules in one call.