medusa-setup
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.
Best use case
medusa-setup is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
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.
Teams using medusa-setup 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
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/medusa-setup/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How medusa-setup Compares
| Feature / Agent | medusa-setup | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
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.
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 Development Setup
## Before writing code
**Fetch live docs**:
1. Fetch `https://docs.medusajs.com/learn/installation` for installation guide
2. Web-search `site:docs.medusajs.com create medusa starter` for project scaffolding
3. Web-search `site:docs.medusajs.com medusa-config reference` for configuration options
4. Web-search `site:docs.medusajs.com project directory structure` for v2 layout
## Prerequisites
### Required Software
| Software | Minimum Version | Purpose |
|----------|----------------|---------|
| Node.js | v20+ | Runtime |
| PostgreSQL | — (see docs) | Primary database |
| Redis | v6+ | Event bus, caching (optional for dev) |
| Git | any | Version control |
| npm / yarn / pnpm | latest | Package manager |
### PostgreSQL Setup
- Create a dedicated database: `CREATE DATABASE medusa_db;`
- Create a user with full privileges on that database
- Connection string format: `postgres://user:password@localhost:5432/medusa_db`
### Redis Setup (Optional for Development)
- Default connection: `redis://localhost:6379`
- Required in production for the event bus module and caching
- In development, Medusa falls back to an in-memory event bus
## Project Creation
### CLI Scaffolding
```bash
npx create-medusa-app@latest my-store
# Prompts: project name, PostgreSQL credentials
# Creates: backend + Next.js storefront starter
```
### Backend Only
```bash
npx create-medusa-app@latest my-store --skip-client
# Fetch live docs for current CLI flags
```
## Project Directory Structure
| Directory | Purpose |
|-----------|---------|
| `src/modules/` | Custom modules (DML data models, services) |
| `src/workflows/` | Custom workflows and steps |
| `src/api/store/`, `src/api/admin/` | Custom API routes + `middlewares.ts` |
| `src/subscribers/`, `src/jobs/` | Event subscribers, scheduled jobs |
| `src/admin/widgets/`, `src/admin/routes/` | Admin UI extensions |
| `src/links/` | Module link definitions |
| Root | `medusa-config.ts`, `package.json`, `tsconfig.json`, `.env` |
## medusa-config.ts Key Fields
| Field | Purpose |
|-------|---------|
| `projectConfig.databaseUrl` | PostgreSQL connection string |
| `projectConfig.redisUrl` | Redis connection (optional) |
| `projectConfig.http.adminCors` | Allowed origins for admin API |
| `projectConfig.http.storeCors` | Allowed origins for store API |
| `projectConfig.http.authCors` | Allowed origins for auth routes |
| `projectConfig.workerMode` | `shared`, `worker`, or `server` |
| `modules` | Array of module configurations |
| `plugins` | Array of plugin configurations |
### Minimal Configuration Skeleton
```typescript
// medusa-config.ts — Fetch live docs for current defineConfig shape
import { defineConfig } from "@medusajs/framework/utils"
export default defineConfig({
projectConfig: { databaseUrl: process.env.DATABASE_URL },
// Fetch live docs for modules, plugins, http config
})
```
## Environment Variables
```
DATABASE_URL=postgres://user:password@localhost:5432/medusa_db
REDIS_URL=redis://localhost:6379
COOKIE_SECRET=your-cookie-secret
JWT_SECRET=your-jwt-secret
STORE_CORS=http://localhost:8000
ADMIN_CORS=http://localhost:5173
AUTH_CORS=http://localhost:5173
```
Never hardcode secrets -- always use `.env` files excluded from version control.
## CLI Commands
| Command | Purpose |
|---------|---------|
| `npx medusa develop` | Start dev server with hot reload |
| `npx medusa build` | Build for production |
| `npx medusa start` | Start production server |
| `npx medusa worker` | Start background worker process |
| `npx medusa db:migrate` | Run database migrations |
| `npx medusa db:generate` | Generate migration files |
| `npx medusa db:rollback` | Rollback last migration |
| `npx medusa user --email admin@example.com` | Create admin user |
| `npx medusa exec ./src/scripts/seed.ts` | Run seed script |
## Worker Mode
Medusa supports three worker modes for handling background jobs:
| Mode | Description |
|------|-------------|
| `shared` | Single process handles HTTP and background jobs (default) |
| `worker` | Dedicated process for background jobs only |
| `server` | HTTP-only, no background job processing |
In production, run one `server` instance and one or more `worker` instances.
## Database Migrations
- Medusa v2 auto-generates migrations from DML model changes
- Run `npx medusa db:generate` after modifying data models
- Run `npx medusa db:migrate` to apply pending migrations
- Always commit migration files to version control
## Best Practices
- Use `npx create-medusa-app@latest` to scaffold -- do not set up manually
- Always run `npx medusa db:migrate` after pulling changes that include new migrations
- Keep `.env` in `.gitignore` and provide `.env.template` for team members
- Use `shared` worker mode in development, separate `server` + `worker` in production
- Pin your Medusa version in `package.json` to avoid unexpected breaking changes
- Run `npx medusa user` to create the first admin user after initial setup
## Common Issues
| Issue | Resolution |
|-------|-----------|
| Database connection refused | Verify PostgreSQL is running and `DATABASE_URL` is correct |
| Migrations fail | Ensure database exists and user has DDL privileges |
| Admin dashboard blank | Check `ADMIN_CORS` matches the admin URL |
| Store API 403 | Check `STORE_CORS` matches the storefront URL |
| Redis connection error | Either start Redis or remove `redisUrl` from config |
Fetch the Medusa installation guide and CLI reference for exact commands, flags, and latest configuration options before setting up.Related Skills
woo-setup
Install WooCommerce, configure the development stack, and set up a local dev environment with WP-CLI, Docker, or wp-env. Use when setting up a new WooCommerce project or development environment.
webmcp-setup
Set up a WebMCP project — enable Chrome flags, install MCP-B polyfill, scaffold tool registration, and configure development environment. Use when starting a new WebMCP-enabled website from scratch.
ucp-setup
Set up a UCP project — scaffold a merchant server or platform client with discovery profile, SDK installation, and project structure. Use when starting a new UCP implementation.
mpp-setup
Scaffold an MPP project — install mppx SDK, configure payment methods, set up server middleware, and create a basic paid API endpoint. Use when starting a new MPP machine payments project from scratch.
spree-setup
Bootstrap a new Spree project — `create-spree-app` CLI (v5.2+), `spree-starter` Rails backend, the Next.js storefront repo, `bin/rails g spree:install`, sample data, Docker Compose, and the PostgreSQL + Redis + Sidekiq prerequisites. Use when starting a new Spree project from scratch or onboarding an existing repo.
shopify-setup
Set up a Shopify development environment — Shopify CLI installation, Partner account, development stores, environment variables, project structures for themes, apps, and Hydrogen. Use when starting a new Shopify project.
sf-setup
Set up a Salesforce Commerce development environment — sfcc-ci CLI for B2C, sf CLI for B2B, Business Manager access, sandbox management, dw.json configuration, .sfdx project setup, and project structures for SFRA, PWA Kit, and Lightning. Use when starting a new Salesforce Commerce project.
saleor-setup
Set up a Saleor development environment — saleor-platform Docker Compose, CLI, PostgreSQL/Redis prerequisites, manage.py commands, environment variables, project structure. Use when starting a new Saleor project.
nlweb-setup
Bootstrap a local NLWeb development environment from scratch — clone the repo, configure .env, install Python deps via `nlweb init-python`, run `nlweb init` for interactive LLM/retrieval selection, load sample Schema.org data, and verify with `nlweb check`. Use when starting a new NLWeb deployment from zero.
medusa-workflows
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
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
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.