Skip to main content
rule

medusa — Cursor rule: building Medusa apps

A Cursor rule that keeps Medusa code on one pattern: workflows, data models, services and admin customizations.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/medusa.mdc
Open on GitHub

What medusa does

The rule lives in Cursor and applies to **/*.tsx, **/*.ts, src/**/*.ts, src/**/*.tsx, src/**/*.js, src/**/*.jsx. Auto-apply is off, so it kicks in on matching paths rather than on every file.

Four areas are covered. General: throw MedusaError for failures, fetch data through Query, skip type aliases on imports. Workflows: define them with @medusajs/framework/workflows-sdk, give each workflow its own step, use transform for data changes and when for conditions, call steps without await, and keep the workflow function non-async. Data models come from the model utility in @medusajs/framework/utils — camelCase variables, snake case fields, a single id marked with .primaryKey() while other identifiers stay text. Services that own models extend MedusaService and expose async methods. Admin requests go through the JS SDK, styling through TailwindCSS.

This assumes Medusa is already in the project and its Workflow SDK is the way you build features. Code that defines workflows differently will fight the rule, so expect to edit parts of it to match your existing style.

What it helps with

  • define workflows and steps with the Medusa Workflow SDK
  • declare data models through the model utility
  • extend MedusaService in module services
  • throw MedusaError instead of plain errors
  • route admin requests through the JS SDK

Example prompts for the agent

  • Create a workflow for checkout with a step that checks stock
  • Define a data model for a warehouse with snake case fields
  • Rewrite the module service so it extends MedusaService

How to install medusa

Manually: put the files in place

.cursor/rules/medusa.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about medusa

How do I install medusa in Cursor?

Create .cursor/rules/medusa.mdc and paste the rule contents into it.

What does the medusa rule do?

It sets Cursor conventions for Medusa code: workflows, data models, services and admin customization.

Which files does the rule cover?

**/*.tsx, **/*.ts, src/**/*.ts, src/**/*.tsx, src/**/*.js, src/**/*.jsx. Auto-apply is off.

Source text

medusa.mdc · CC0-1.0
---
description: "Medusa rules and best practices. These rules should be used when building applications with Medusa."
globs: **/*.tsx, **/*.ts, src/**/*.ts, src/**/*.tsx, src/**/*.js, src/**/*.jsx
alwaysApply: false
---
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

- [Medusa Documentation](https://docs.medusajs.com/llms-full.txt)

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set210

nestjs-anti-hallucination-cursorrules-prompt-file Cursor rule that stops AI models from generating fake NestJS imports, legacy TypeORM calls, and untyped code. ★ 41,024repo stars nativescript This rule guides NativeScript work across TypeScript, Vue, and related stacks. Use it when shaping mobile UI, platform code, and native delegates. ★ 41,024repo stars nativescript-cursorrules-prompt-file A Cursor rule that tells the agent how to structure a NativeScript project and which libraries to reach for. ★ 41,024repo stars momen-cursurrules-prompt-file Instructs Cursor on building custom frontends on top of Momen.app headless BaaS. Guides GraphQL queries, Actionflow tasks, and WebSocket subscriptions. ★ 41,024repo stars manifest-yaml-cursorrules-prompt-file A Cursor rule that tells the agent how to scaffold a small Manifest backend: project setup, the manifest/backend.yml file and limits on entities. ★ 41,024repo stars linux-nvidia-cuda-python-cursorrules-prompt-file Sets Cursor agent guidelines for the Hugging Face model quantization pipeline on Linux servers with Nvidia CUDA or AMD ROCm GPUs. ★ 41,024repo stars laravel-tall-stack-best-practices-cursorrules-prom A Cursor rule for Laravel and the TALL Stack. It guides PHP, Livewire, Alpine.js, and Tailwind CSS work in application code. ★ 41,024repo stars laravel-php-83-cursorrules-prompt-file A Cursor rule that walks the agent through building Laravel packages: plan, directory layout, naming standards, tests and docs. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor