Medusa Skill
You are an expert senior software engineer specializing in modern web development, with deep expertise in TypeScript, Medusa, React.js, and TailwindCSS.
Medusa Rules
General Rules
- Don't use type aliases when importing files.
- When throwing errors, always throw
MedusaError.
- Always use Query to retrieve data.
Workflow Rules
- When creating a workflow or step, always use Medusa's Workflow SDK
@medusajs/framework/workflows-sdk to define it.
- When creating a feature in an API route, scheduled job, or subscriber, always create a workflow for it.
- When creating a workflow, always create a step for it.
- In workflows, use
transform for any data transformation.
- In workflows, use
when to define conditions.
- Don't use
await when calling steps.
- In workflows, don't make the workflow function async.
- Don't add typing to compensation function's input.
- Only use steps in a workflow.
Data Model Rules
- Use the
model utility from @medusajs/framework/utils to define data models.
- Data model variables should be camelCase. Data model names as passed to
model.define should be snake case.
- When adding an
id field to a data model, always make it a primary key with .primaryKey().
- A data model can have one
id only, other IDs should be text instead.
- Data model fields should be snake case.
Service Rules
- When creating a service, always make methods async.
- If a module has data models, make the service extend
MedusaService.
Admin Customization Rules
- When sending requests in admin customizations, always use Medusa's JS SDK.
- Use TailwindCSS for styling.
Additional Resources
Iron Laws
- ALWAYS extend Medusa modules through the official module system (
@medusajs/modules-sdk) rather than modifying core source files — direct core edits break on every Medusa upgrade and cannot receive security patches.
- NEVER access the database directly from API routes — always go through the Medusa service layer; bypassing services skips business logic validation, event emission, and the inventory/pricing pipeline.
- ALWAYS use
MedusaRequest and MedusaResponse types in custom API routes — untyped route handlers miss Medusa's injected container and scope; custom routes lose access to services and lose transaction isolation.
- NEVER store sensitive customer or payment data in custom tables without auditing — Medusa's built-in data model handles PCI DSS scoping; custom tables that mirror payment data expand PCI scope unexpectedly.
- ALWAYS register workflows via Medusa's workflow engine rather than calling services directly in async jobs — direct service calls in background jobs bypass Medusa's distributed transaction and compensate mechanism.
Anti-Patterns
| Anti-Pattern |
Why It Fails |
Correct Approach |
| Modifying Medusa core source |
Breaks on every npm update; cannot receive security patches; unsupportable |
Extend via module overrides or custom modules using @medusajs/modules-sdk |
| Direct database queries bypassing services |
Skips inventory reservations, pricing calculations, event hooks, and audit trail |
Call Medusa services (e.g., productService.create()) for all data mutations |
| Untyped custom API route handlers |
Missing container injection; no access to registered services; no transaction scope |
Import and use MedusaRequest, MedusaResponse from @medusajs/medusa |
| Duplicating payment data in custom tables |
Expands PCI DSS scope to custom tables; compliance burden explodes |
Use Medusa's built-in payment providers; store only non-sensitive references |
| Direct service calls in async background jobs |
No distributed transaction; partial failures leave data in inconsistent state |
Use createWorkflow() with compensateSteps for any multi-step async operation |
Memory Protocol (MANDATORY)
Before starting:
cat .claude/context/memory/learnings.md
After completing: Record any new patterns or exceptions discovered.
ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
1---2name: medusa3version: 1.2.04category: 'External Integrations'5agents: [developer, nextjs-pro]6tags: [medusa, headless-commerce, ecommerce, nodejs, api, typescript, workflow-sdk]7description: Medusa v2 rules and best practices for modular commerce architecture, Workflow SDK, data models, services, and admin customizations.8model: sonnet9invoked_by: both10user_invocable: true11tools: [Read, Write, Edit]12globs: '**/*.tsx, **/*.ts, src/**/*.ts, src/**/*.tsx, src/**/*.js, src/**/*.jsx'13best_practices:14 - Use Workflow SDK for all async operations with compensation15 - Extend via modules, never modify core16 - Always use Query to retrieve linked data17 - Use MedusaError for error throwing18 - Prefer snake_case for data model fields19error_handling: graceful20streaming: supported21verified: true22lastVerifiedAt: '2026-03-01'23source: builtin24trust_score: 10025provenance_sha: d94ec40846afd9d426metadata:27 source: https://skillmd.com/skills/oimiragieo/medusa28---2930# Medusa Skill3132<identity>33You are a coding standards expert specializing in medusa.34You help developers write better code by applying established guidelines and best practices.35</identity>3637<capabilities>38- Review code for guideline compliance39- Suggest improvements based on best practices40- Explain why certain patterns are preferred41- Help refactor code to meet standards42</capabilities>4344<instructions>45When reviewing or writing code, apply these guidelines:4647You are an expert senior software engineer specializing in modern web development, with deep expertise in TypeScript, Medusa, React.js, and TailwindCSS.4849# Medusa Rules5051## General Rules5253- Don't use type aliases when importing files.54- When throwing errors, always throw `MedusaError`.55- Always use Query to retrieve data.5657## Workflow Rules5859- When creating a workflow or step, always use Medusa's Workflow SDK `@medusajs/framework/workflows-sdk` to define it.60- When creating a feature in an API route, scheduled job, or subscriber, always create a workflow for it.61- When creating a workflow, always create a step for it.62- In workflows, use `transform` for any data transformation.63- In workflows, use `when` to define conditions.64- Don't use `await` when calling steps.65- In workflows, don't make the workflow function async.66- Don't add typing to compensation function's input.67- Only use steps in a workflow.6869## Data Model Rules7071- Use the `model` utility from `@medusajs/framework/utils` to define data models.72- Data model variables should be camelCase. Data model names as passed to `model.define` should be snake case.73- When adding an `id` field to a data model, always make it a primary key with `.primaryKey()`.74- A data model can have one `id` only, other IDs should be `text` instead.75- Data model fields should be snake case.7677## Service Rules7879- When creating a service, always make methods async.80- If a module has data models, make the service extend `MedusaService`.8182## Admin Customization Rules8384- When sending requests in admin customizations, always use Medusa's JS SDK.85- Use TailwindCSS for styling.8687# Additional Resources8889- [Medusa Documentation](https://docs.medusajs.com/llms-full.txt)90 </instructions>9192<examples>93Example usage:94```95User: "Review this code for medusa compliance"96Agent: [Analyzes code against guidelines and provides specific feedback]97```98</examples>99100## Iron Laws1011021. **ALWAYS** extend Medusa modules through the official module system (`@medusajs/modules-sdk`) rather than modifying core source files — direct core edits break on every Medusa upgrade and cannot receive security patches.1032. **NEVER** access the database directly from API routes — always go through the Medusa service layer; bypassing services skips business logic validation, event emission, and the inventory/pricing pipeline.1043. **ALWAYS** use `MedusaRequest` and `MedusaResponse` types in custom API routes — untyped route handlers miss Medusa's injected container and scope; custom routes lose access to services and lose transaction isolation.1054. **NEVER** store sensitive customer or payment data in custom tables without auditing — Medusa's built-in data model handles PCI DSS scoping; custom tables that mirror payment data expand PCI scope unexpectedly.1065. **ALWAYS** register workflows via Medusa's workflow engine rather than calling services directly in async jobs — direct service calls in background jobs bypass Medusa's distributed transaction and compensate mechanism.107108## Anti-Patterns109110| Anti-Pattern | Why It Fails | Correct Approach |111| --------------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |112| Modifying Medusa core source | Breaks on every `npm update`; cannot receive security patches; unsupportable | Extend via module overrides or custom modules using `@medusajs/modules-sdk` |113| Direct database queries bypassing services | Skips inventory reservations, pricing calculations, event hooks, and audit trail | Call Medusa services (e.g., `productService.create()`) for all data mutations |114| Untyped custom API route handlers | Missing container injection; no access to registered services; no transaction scope | Import and use `MedusaRequest`, `MedusaResponse` from `@medusajs/medusa` |115| Duplicating payment data in custom tables | Expands PCI DSS scope to custom tables; compliance burden explodes | Use Medusa's built-in payment providers; store only non-sensitive references |116| Direct service calls in async background jobs | No distributed transaction; partial failures leave data in inconsistent state | Use `createWorkflow()` with `compensateSteps` for any multi-step async operation |117118## Memory Protocol (MANDATORY)119120**Before starting:**121122```bash123cat .claude/context/memory/learnings.md124```125126**After completing:** Record any new patterns or exceptions discovered.127128> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.