| name | spec-writing |
|---|---|
| description | Guide for creating high-quality, architecturally compliant specifications for this Medusa.js project. Use when starting a new spec or reviewing one against staff-engineer standards. |
Design and review specifications against this project's Medusa architecture, naming, and quality rules.
- Load Context — Read
AGENTS.mdTask Router. Load the relevant spec from.ai/specs/if one exists for this topic. Check.ai/specs/references/for any additional data files (field mappings, data exports, design docs) — read all files found there before proceeding. - Initialize — Create an empty file:
.ai/specs/YYYY-MM-DD-kebab-case-title.md - Start Minimal — Write a Skeleton Spec first: TLDR + 2–3 key sections. Do NOT write the full spec in one pass.
- Before the skeleton, scan the brief for critical unknowns — decisions that block architecture, data model, or scope.
- If unknowns exist, add a numbered Open Questions block (
Q1,Q2, …) right after the TLDR. - STOP after presenting the skeleton. Do not proceed to Research or beyond until the user answers all questions. This is a hard gate.
- Iterate — Apply answers to fill in the skeleton. Remove resolved questions. Repeat the gate for any new unknowns.
- Research — Validate requirements against Medusa's built-in capabilities and official patterns. Check if a built-in workflow already exists before designing a custom one.
- Design — Architecture, data flow, module structure, workflow steps, API contracts.
- Implementation Breakdown — Break into Phases (stories) and Steps (testable tasks). Each step must result in a runnable application.
- Review — Apply the Spec Checklist.
- Compliance Gate — Apply the Compliance Review.
- Output — Finalize the spec file.
Use Specification Template. Adapt structure as needed, but always cover:
- TLDR & Overview — what and why
- Problem Statement — what are we solving
- Proposed Solution — high-level approach
- Architecture — module → workflow → route layers
- Data Mapping — external source → Medusa fields
- Phasing — delivery breakdown
- Implementation Plan — concrete steps
- Open Questions — unresolved decisions
When reviewing an existing spec:
# Architectural Review: {Spec Title}
## Summary
{1–3 sentences: what the spec proposes and overall health}
## Findings
### Critical
{Medusa layer violations, workflow bypasses, wrong HTTP methods, module name with dashes}
### High
{Missing idempotency, no error handling strategy, missing data mapping gaps}
### Medium
{Missing failure scenarios, ambiguous field names, missing pagination strategy}
### Low
{Stylistic nits, minor inconsistencies}
## Checklist
See references/spec-checklist.md
- Layer Order — Does the spec follow Module → Workflow → Route? No layer may be bypassed.
- Idempotency — Is there an
external_idor equivalent key to prevent duplicate imports on re-run? - Transform vs. Step — Is data mapping done in a
transform()block (correct) or in a workflow step (wrong)? - Built-in First — Does the spec use
createProductsWorkflow/updateProductsWorkflowinstead of reinventing them? - Open Questions Gate — Are all architectural unknowns resolved before design proceeds?
camelCasemodule names — never dashes (structPim✓,struct-pim✗)GET,POST,DELETEonly — neverPUTorPATCH- All mutations through a workflow — never call module service from a route
- Prices stored as-is — never multiply or divide by 100
- Static imports only — no
await import()inside route handlers transform()for data manipulation inside workflows — not plain steps- Use
external_idfor idempotency on all migration/sync operations - Zod validation for all API route inputs
- Spec Checklist
- Compliance Review — dispatcher — load first, then load the stack-specific file below
- Compliance Review — Medusa.js — for Medusa.js projects
- Compliance Review — Payload CMS — for Payload CMS / Next.js projects
- Specification Template
- Root AGENTS.md
- Medusa Magento Example