medusa-modules

Build custom Medusa v2 modules — DML data models, services extending MedusaService, loaders, module links, and container registration. Use when creating custom modules.

17 stars

Best use case

medusa-modules is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Build custom Medusa v2 modules — DML data models, services extending MedusaService, loaders, module links, and container registration. Use when creating custom modules.

Teams using medusa-modules should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/medusa-modules/SKILL.md --create-dirs "https://raw.githubusercontent.com/OrcaQubits/agentic-commerce-skills-plugins/main/dist/antigravity/medusa-commerce/.agent/skills/medusa-modules/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/medusa-modules/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How medusa-modules Compares

Feature / Agentmedusa-modulesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Build custom Medusa v2 modules — DML data models, services extending MedusaService, loaders, module links, and container registration. Use when creating custom modules.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Medusa v2 Custom Modules

## Before writing code

**Fetch live docs**:
1. Fetch `https://docs.medusajs.com/learn/fundamentals/modules` for module overview
2. Web-search `site:docs.medusajs.com DML data model reference` for model property types
3. Web-search `site:docs.medusajs.com MedusaService methods` for base service API
4. Web-search `site:docs.medusajs.com module links` for linking modules together
5. Web-search `site:docs.medusajs.com module container registration` for dependency injection

## Module Concept

A module is a self-contained package of functionality in Medusa v2:
- Encapsulates data models, services, and business logic
- Registered in `medusa-config.ts` under the `modules` array
- Accessed from workflows, API routes, and subscribers via the dependency container
- Modules communicate through links, not direct imports

## Module Directory Structure

| File | Purpose |
|------|---------|
| `src/modules/my-module/models/my-entity.ts` | DML data model |
| `src/modules/my-module/service.ts` | Service extending MedusaService |
| `src/modules/my-module/loaders/seed.ts` | Optional loader (runs on startup) |
| `src/modules/my-module/migrations/` | Auto-generated by CLI |
| `src/modules/my-module/index.ts` | Module definition export |

## DML Data Models

### Property Types

| DML Type | Database Column | Notes |
|----------|----------------|-------|
| `model.id()` | Primary key UUID | Auto-generated |
| `model.text()` | `text` / `varchar` | String fields |
| `model.number()` | `integer` | Numeric fields |
| `model.bigNumber()` | `numeric` | Precise decimals (prices) |
| `model.boolean()` | `boolean` | True/false |
| `model.dateTime()` | `timestamptz` | Date/time values |
| `model.json()` | `jsonb` | Arbitrary JSON |
| `model.enum()` | `enum` | Constrained values |
| `model.array()` | `array` | Array of primitives |

### Relationship Types

| Relationship | DML Method | Description |
|-------------|-----------|-------------|
| Has One | `model.hasOne()` | One-to-one owned |
| Has Many | `model.hasMany()` | One-to-many owned |
| Belongs To | `model.belongsTo()` | Inverse of hasOne/hasMany |
| Many to Many | `model.manyToMany()` | Junction table auto-created |

### Model Definition Skeleton

```typescript
// src/modules/my-module/models/my-entity.ts
// Fetch live docs for current DML model API
import { model } from "@medusajs/framework/utils"

const MyEntity = model.define("my_entity", {
  id: model.id(), name: model.text(),
  // Fetch live docs for property options and relationships
})
```

## Service Pattern

Every module exposes a service that extends `MedusaService`:

```typescript
// src/modules/my-module/service.ts
// Fetch live docs for MedusaService generic signature
import { MedusaService } from "@medusajs/framework/utils"
import MyEntity from "./models/my-entity"

class MyModuleService extends MedusaService({ MyEntity }) {}
export default MyModuleService // Add custom methods as needed
```

### Inherited MedusaService Methods

| Method Pattern | Purpose |
|---------------|---------|
| `create<Entity>(data)` | Create one or many records |
| `update<Entity>(data)` | Update records by selector or ID |
| `delete<Entity>(ids)` | Soft-delete records |
| `retrieve<Entity>(id, config)` | Retrieve single record by ID |
| `list<Entity>(filters, config)` | List with filters, pagination, relations |
| `softRestore<Entity>(ids)` | Restore soft-deleted records |

The method names are auto-generated from the model name (e.g., `createMyEntity`, `listMyEntities`).

## Module Definition Export

```typescript
// src/modules/my-module/index.ts
// Fetch live docs for Module definition shape
import { Module } from "@medusajs/framework/utils"
import MyModuleService from "./service"

export const MY_MODULE = Module("my-module", {
  service: MyModuleService,
})
```

## Registration in medusa-config.ts

```typescript
// Inside modules array
// Fetch live docs for module registration options
{ resolve: "./src/modules/my-module" }
```

## Module Links

Links connect data models across different modules without coupling:

| Link Type | Purpose |
|-----------|---------|
| One-to-one link | Connect a custom entity to a core entity (e.g., product) |
| One-to-many link | One core entity linked to many custom entities |
| List link | Bidirectional many-to-many between modules |

### Link Definition Skeleton

```typescript
// src/links/product-my-entity.ts
// Fetch live docs for defineLink API
import { defineLink } from "@medusajs/framework/utils"
import ProductModule from "@medusajs/medusa/product"
import { MY_MODULE } from "../modules/my-module"
```

Links are queried using the `query` utility from the Medusa container, not through direct service calls.

## Loaders

Loaders run when the module initializes (server startup):
- Seed default data
- Register event listeners
- Validate configuration
- Set up external connections

## Container Resolution

Modules register their service in the dependency injection container:
- Resolved by module key: `container.resolve("my-module")`
- Available in workflows, API routes, subscribers, and other services
- Never import a module's service directly -- always resolve from the container

## Best Practices

- One module per bounded context -- keep modules focused and cohesive
- Use DML models exclusively -- never write raw SQL or use Mikro-ORM directly
- Extend `MedusaService` for CRUD -- only add custom methods for non-standard logic
- Use module links to connect to core entities -- never modify core module tables
- Run `npx medusa db:generate` after every model change to create migrations
- Export a constant for your module key (e.g., `MY_MODULE`) and reuse it everywhere

## Common Patterns

| Pattern | When to Use |
|---------|------------|
| Custom module + link to Product | Adding metadata/features to products |
| Custom module + link to Order | Order-related extensions (loyalty, tracking) |
| Standalone module | Independent domain (CMS, analytics, reviews) |
| Module with loader | Pre-seeding data or external service setup |

Fetch the Medusa module documentation for exact DML property options, MedusaService generics, and link definition patterns before implementing.

Related Skills

medusa-workflows

17
from OrcaQubits/agentic-commerce-skills-plugins

Build Medusa v2 workflows — steps with createStep, compensation/rollback, parallel execution, hooks for extending built-in workflows, and when conditions. Use when orchestrating multi-step operations.

medusa-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test Medusa v2 applications — Jest setup, module unit tests, workflow integration tests, API route tests, medusaIntegrationTestRunner, and mock patterns. Use when writing tests for Medusa projects.

medusa-subscribers

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Medusa v2 event subscribers — pub/sub event handling, subscriber handler functions, scheduled jobs with cron, and the event module (Redis or in-memory). Use when reacting to commerce events.

medusa-storefront

17
from OrcaQubits/agentic-commerce-skills-plugins

Build Medusa v2 storefronts with Next.js 15 — App Router, JS SDK client setup, Tanstack Query, server components, product pages, cart, and checkout flow. Use when developing headless storefronts.

medusa-setup

17
from OrcaQubits/agentic-commerce-skills-plugins

Set up a Medusa v2 development environment — CLI, PostgreSQL/Redis prerequisites, project creation, medusa-config.ts, directory structure, environment variables. Use when starting a new Medusa project.

medusa-security

17
from OrcaQubits/agentic-commerce-skills-plugins

Secure Medusa v2 applications — authentication strategies, API key types (publishable vs secret), CORS configuration, JWT and cookie secrets, admin vs store auth, and session management. Use when configuring security.

medusa-pricing

17
from OrcaQubits/agentic-commerce-skills-plugins

Configure Medusa v2 pricing — pricing module, price lists with rules, currencies, tax calculation, regions, and promotion campaigns. Use when setting up pricing and discounts.

medusa-plugins

17
from OrcaQubits/agentic-commerce-skills-plugins

Develop and publish Medusa v2 plugins — plugin structure, plugin vs module comparison, npm packaging, and reusable plugin template. Use when building distributable Medusa extensions.

medusa-payments

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Medusa v2 payment processing — payment module, provider abstraction, payment sessions, authorization/capture/refund lifecycle, and Stripe/PayPal integration. Use when adding payment providers.

medusa-orders

17
from OrcaQubits/agentic-commerce-skills-plugins

Manage Medusa v2 orders — order lifecycle and state machine, fulfillment workflows, returns, exchanges, claims, draft orders, and order editing. Use when working with order processing.

medusa-fulfillment

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Medusa v2 fulfillment — fulfillment module, provider interface, shipping options, fulfillment sets, shipping profiles, and multi-warehouse support. Use when adding fulfillment providers.

medusa-deploy

17
from OrcaQubits/agentic-commerce-skills-plugins

Deploy Medusa v2 to production — build process, server vs worker mode, environment variables, hosting options, Redis caching, database configuration, and production checklist. Use when deploying Medusa applications.