medusa-development
БесплатноБез исполняемых скриптовНе проверенBest practices for building commerce applications with Medusa v2, the headless e-commerce framework. Use when defining Medusa data models, writing workflows…
от Mindrally★ 323 звезды на GitHubОб этом скилле
Medusa Development
Medusa is a headless commerce framework built around modules, data models, and workflows; almost every piece of business logic — from an API route to a scheduled job — should be expressed as a workflow made of discrete, composable steps.
Workflow for Building a Medusa Feature
- Define or extend the data model — Use the
modelutility from@medusajs/framework/utilsto declare the module's data model(s) undersrc/modules/<module>/models/. - Write the module service — Create a service in
src/modules/<module>/service.tsthat extendsMedusaServicewhen the module has data models, exposing async methods for domain operations. - Register the module — Add the module to
medusa-config.tsso Medusa's container can resolve it. - Build steps — Define each unit of work as a step with
createStepfrom@medusajs/framework/workflows-sdk, including a compensation function for anything that needs to be undone on failure. - Compose the workflow — Wire steps together with
createWorkflow, usingtransformfor data shaping andwhenfor conditional branches. - Expose the workflow — Call the workflow from an API route, a scheduled job, or a subscriber — never put business logic directly in the route/job/subscriber handler.
- Read data with Query — Use Medusa's Query (
req.scope.resolve("query")or the workflow-leveluseQueryGraphStep) to fetch data instead of calling module services directly for reads.
General Rules
- Don't use type aliases when importing files — import types and values directly from their source module rather than re-exporting through a local alias.
- When throwing errors, always throw
MedusaError(from@medusajs/framework/utils) instead of a plainError, so the API layer can map it to the correct HTTP status and error code. - Always use Query to retrieve data rather than calling a module's service methods directly for reads — Query understands module links and can join data across modules in one call.
import { MedusaError } from "@medusajs/framework/utils"
if (!product) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Product with id "${productId}" was not found`
)
}
Data Model Rules
- Use the
modelutility from@medusajs/framework/utilsto define data models. - Data model variables should be camelCase; the name passed to
model.defineshould be snake_case. - When adding an
idfield to a data model, always make it a primary key with.primaryKey(). - A data model can have only one
idfield — any other identifier should be atextfield instead. - Data model fields should be snake_case.
// src/modules/loyalty/models/loyalty-account.ts
import { model } from "@medusajs/framework/utils"
const LoyaltyAccount = model.define("loyalty_account", {
id: model.id().primaryKey(),
customer_id: model.text(),
points_balance: model.number().default(0),
tier: model.enum(["bronze", "silver", "gold"]).default("bronze"),
})
export default LoyaltyAccount
Service Rules
- When creating a service, always make its methods async.
- If a module has data models, make the service extend
MedusaServiceso it inherits generated CRUD methods for each model.
// src/modules/loyalty/service.ts
import { MedusaService } from "@medusajs/framework/utils"
import LoyaltyAccount from "./models/loyalty-account"
class LoyaltyModuleService extends MedusaService({
LoyaltyAccount,
}) {
async addPoints(accountId: string, points: number) {
const account = await this.retrieveLoyaltyAccount(accountId)
return await this.updateLoyaltyAccounts({
id: account.id,
points_balance: account.points_balance + points,
})
}
}
export default LoyaltyModuleService
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 rather than inlining the logic in the handler.
- When creating a workflow, always create a step for each discrete unit of work in it.
- In workflows, use
transformfor any data transformation between steps — don't manipulate step output directly in the workflow function body. - In workflows, use
whento define conditional branches instead of a plainifaround step calls. - Don't use
awaitwhen calling steps inside a workflow — step invocation returns a special reference the workflow engine resolves, andawait-ing it breaks the workflow's ability to orchestrate compensation and retries. - In workflows, don't make the workflow function itself
async— the function body only describes the step graph, it doesn't execute imperatively. - Don't add typing to a compensation function's input — the compensation function receives whatever the step's invoke function returned, and Medusa infers this automatically.
- Only use steps in a workflow — don't call services, Query,
Установить medusa-development в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл medusa-development?
Best practices for building commerce applications with Medusa v2, the headless e-commerce framework. Use when defining Medusa data models, writing workflows and steps with the Workflow SDK, creating API routes or subscribers, building module services that extend MedusaService, throwing MedusaError, or customizing the Medusa admin dashboard.
Как установить скилл medusa-development?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл medusa-development запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic