Home › Medusa (commerce) › Medusa v2 commerce AGENTS.md

Medusa v2 commerce AGENTS.md

AGENTS.md for Medusa v2 commerce backends: custom modules and data models, workflows with compensation, API routes, subscribers, module links, and admin widgets.

AGENTS.mdMedusa (commerce)

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

AGENTS.mdDownload  
# AGENTS.md: Medusa v2

## Commands
- `npx medusa develop` (server + admin) · `npm run build` · `npm test` (integration tests use the framework's test runner if configured)
- Migrations: `npx medusa db:generate <module>` after changing a data model, then `npx medusa db:migrate`. Never edit applied migrations or the database by hand.

## Where code goes
- Custom domain logic: modules in `src/modules/<name>/` (data models with `model.define`, a service extending `MedusaService`, `index.ts` exporting `Module(...)`), registered in `medusa-config.ts`.
- Relations between modules: module links in `src/links/` with `defineLink`. Modules never import each other's services or tables directly.
- Business flows: workflows in `src/workflows/` built with `createWorkflow` and `createStep`. Every step that changes data has a compensation function so failures roll back.
- HTTP: API routes in `src/api/**/route.ts` exporting `GET`/`POST`/etc. Routes validate input (zod schemas with the validation middleware in `src/api/middlewares.ts`) and run a workflow; they don't contain business logic.
- Reactions to events: subscribers in `src/subscribers/` (handler + `config.event`). Background schedules: `src/jobs/`.
- Admin UI: widgets and routes in `src/admin/` using the Medusa UI components and the JS SDK.

## Rules
- Read data across modules with Query (`query.graph({ entity, fields, filters })`), not by calling many services in a loop.
- Use the commerce modules' workflows (e.g. cart, order, inventory) instead of writing to their tables; extend them with hooks where provided.
- Money: store and compute amounts as the framework does (no floating-point math you invent); always carry currency codes.
- Secrets (`JWT_SECRET`, `COOKIE_SECRET`, DB, payment provider keys) in `.env`, never committed. Configure CORS for store/admin/auth explicitly.
- Store API responses only include fields the storefront needs; never expose admin data on `/store` routes.

## Done when
Build passes, migrations generated for model changes, and an integration test or manual request shows the route/workflow behaving, including the failure path.

More: all Medusa (commerce) rules · all AGENTS.md rules

Related rules

Sanity Studio + GROQ AGENTS.md

AGENTS.md for Sanity projects: schema types with defineType, typed GROQ queries via TypeGen, Portable Text, previews, and safe content migrations.

AGENTS.mdSanity

Shopify app AGENTS.md

AGENTS.md for Shopify apps built with Shopify CLI and the React Router template: auth, GraphQL Admin API, and webhooks.

AGENTS.mdShopify

Drupal 11 module development CLAUDE.md

CLAUDE.md for Drupal 11 sites and custom modules: Composer, Drush, services and dependency injection, config management, and PHPUnit.

Claude Code (CLAUDE.md)Drupal

Payload CMS 3 + Next.js Cursor rules

Cursor rules for Payload CMS 3 inside Next.js: collections and fields config, access control, hooks, Local API, generated types and migrations.

CursorPayload CMS

Shopify Hydrogen storefront Cursor rules

Cursor rules for Shopify Hydrogen storefronts: route loaders with the Storefront API, GraphQL fragments and codegen, caching strategies, cart actions, and SEO.

CursorShopify

Shopify Liquid theme rules

Cursor rules for Shopify Online Store 2.0 themes: sections and blocks, JSON templates, Liquid performance, Theme Check.

CursorShopify

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.