|
| 1 | +# Phase 1: Building the Tutorial Feature |
| 2 | + |
| 3 | +Follow these steps to build the tutorial's feature in the example project before writing any documentation. |
| 4 | + |
| 5 | +## Step 1 — Gather Requirements |
| 6 | + |
| 7 | +Ask the user the following before doing anything else: |
| 8 | + |
| 9 | +1. **Tutorial topic** — What feature or integration is being built? (e.g., "product reviews", "PayPal integration") |
| 10 | +2. **Tutorial type** — How-to tutorial or integration guide? |
| 11 | +3. **Example project path** — Where is the target Medusa example project? (e.g., `~/projects/my-medusa-app`) |
| 12 | +4. **Third-party services** — Are any external services involved? (e.g., PayPal, Segment, Stripe) |
| 13 | +5. **Scope** — Should the tutorial include Admin UI customizations? Storefront customizations? |
| 14 | + |
| 15 | +Do NOT proceed until all required information is collected. |
| 16 | + |
| 17 | +## Step 2 — Research & Plan |
| 18 | + |
| 19 | +Before writing any code: |
| 20 | + |
| 21 | +1. Load `medusa-dev:building-with-medusa` — required for all backend work |
| 22 | + - Also load `medusa-dev:building-admin-dashboard-customizations` if admin UI is in scope |
| 23 | + - Also load `medusa-dev:building-storefronts` if storefront is in scope |
| 24 | +2. Use `mcp__medusa__ask_medusa_question` for questions about Medusa APIs, modules, and patterns |
| 25 | +3. For integrations with third-party services: use `context7` MCP or skills to retrieve their documentation |
| 26 | + |
| 27 | +**Write a plan covering:** |
| 28 | +- Data models to create (custom module if needed) |
| 29 | +- Workflows and their steps |
| 30 | +- API routes (store and/or admin) |
| 31 | +- Admin UI widgets/pages (if applicable) |
| 32 | +- Storefront components/changes (if applicable) |
| 33 | +- Seed data or configuration needed |
| 34 | + |
| 35 | +> **CRITICAL:** Keep it simple. Tutorial code is for learning, not production. Avoid unnecessary abstractions, overly generic utilities, or complex patterns. One clear approach beats multiple flexible ones. |
| 36 | +
|
| 37 | +**Present the plan to the user and get explicit approval before writing any code.** |
| 38 | + |
| 39 | +## Step 3 — Build the Feature |
| 40 | + |
| 41 | +Follow the approved plan. Always follow the architecture layer order: |
| 42 | + |
| 43 | +``` |
| 44 | +Custom Module (data models + CRUD) |
| 45 | + ↓ |
| 46 | +Workflow (business logic, mutations) |
| 47 | + ↓ |
| 48 | +API Route (HTTP interface) |
| 49 | + ↓ |
| 50 | +Admin UI / Storefront |
| 51 | +``` |
| 52 | + |
| 53 | +**Useful commands:** |
| 54 | +- Generate migration: `/medusa-dev:db-generate <module-name>` |
| 55 | +- Run migrations: `/medusa-dev:db-migrate` |
| 56 | +- Create admin user: `/medusa-dev:new-user <email> <password>` |
| 57 | + |
| 58 | +Load reference files from `medusa-dev:building-with-medusa` for each component as you build it. |
| 59 | + |
| 60 | +## Step 4 — Add Tests |
| 61 | + |
| 62 | +Write tests to validate the implementation: |
| 63 | + |
| 64 | +- **Workflow steps** — Unit tests for each step's main logic |
| 65 | +- **API routes** — Integration tests covering success and error cases |
| 66 | +- **Custom module service methods** — Unit tests for any non-trivial service logic |
| 67 | + |
| 68 | +Place tests in: |
| 69 | +- `integration-tests/` for API/integration tests |
| 70 | +- `src/**/__tests__/` for unit tests |
| 71 | + |
| 72 | +Keep tests simple and focused on verifying the feature works as expected. These tests also serve as examples for tutorial readers. |
| 73 | + |
| 74 | +## Step 5 - Validate Implementation |
| 75 | + |
| 76 | +Before finishing up, make sure that: |
| 77 | + |
| 78 | +1. Build passes: `yarn build` |
| 79 | +2. Integration and unit tests pass |
| 80 | + |
| 81 | +Fix all issues before wrapping up. |
| 82 | + |
| 83 | +## Step 6 — Wrap Up |
| 84 | + |
| 85 | +1. Tell the user to test the feature manually: |
| 86 | + - Start the Medusa app and test relevant API routes |
| 87 | + - Verify in the Admin UI (if applicable) |
| 88 | + - Verify in the Storefront (if applicable) |
| 89 | +2. Ask the user: **"Does everything look good? Let me know when you're ready to write the tutorial documentation."** |
| 90 | +3. Once the user confirms, instruct them: **"Reload `/writing-tutorials` and I'll help you write the documentation."** |
| 91 | + |
| 92 | +> **IMPORTANT:** Do not start writing documentation until the user explicitly confirms the build is complete and working. |
0 commit comments