|
1
|
# Medusa Tutorial Structure Rules |
|
2
|
|
|
3
|
## Overview |
|
4
|
|
|
5
|
This file defines the structure and formatting requirements for creating Medusa tutorials in the `/app/how-to-tutorials/tutorials/` directory. All tutorials must follow this structure to ensure consistency and quality. |
|
6
|
|
|
7
|
## File Structure |
|
8
|
|
|
9
|
### 1. Frontmatter (Required) |
|
10
|
|
|
11
|
Every tutorial must start with YAML frontmatter containing: |
|
12
|
|
|
13
|
```yaml |
|
14
|
--- |
|
15
|
sidebar_label: "Tutorial Name" # Display name in sidebar |
|
16
|
tags: |
|
17
|
- name: product_name # Product tags (e.g., cart, order, customer) |
|
18
|
label: "Implement Feature" |
|
19
|
- server # Always include if server-side code |
|
20
|
- tutorial # Always include |
|
21
|
- nextjs # Include if storefront customization |
|
22
|
products: |
|
23
|
- product_name # Array of product names used |
|
24
|
--- |
|
25
|
``` |
|
26
|
|
|
27
|
**Additional frontmatter options:** |
|
28
|
|
|
29
|
- `keywords`: Array of keywords for SEO (optional) |
|
30
|
- `ogImage`: Export for Open Graph image (optional) |
|
31
|
|
|
32
|
### 2. Imports |
|
33
|
|
|
34
|
After frontmatter, include necessary imports: |
|
35
|
|
|
36
|
- `Github`, `PlaySolid` from `@medusajs/icons` (if needed) |
|
37
|
- `Prerequisites`, `WorkflowDiagram`, `CardList`, `Card` from `docs-ui` |
|
38
|
- Other necessary components |
|
39
|
|
|
40
|
### 3. Metadata Export |
|
41
|
|
|
42
|
```typescript |
|
43
|
export const metadata = { |
|
44
|
title: `Implement Feature Name in Medusa`, |
|
45
|
// Optional: openGraph and twitter metadata |
|
46
|
} |
|
47
|
``` |
|
48
|
|
|
49
|
### 4. Title Section |
|
50
|
|
|
51
|
```markdown |
|
52
|
# {metadata.title} |
|
53
|
|
|
54
|
In this tutorial, you'll learn how to [brief description]. |
|
55
|
``` |
|
56
|
|
|
57
|
### 5. Context Paragraph |
|
58
|
|
|
59
|
Include 1-2 paragraphs explaining: |
|
60
|
|
|
61
|
- What Medusa provides out-of-the-box |
|
62
|
- What the tutorial will teach |
|
63
|
- Context about the feature being implemented |
|
64
|
|
|
65
|
### 6. Summary Section |
|
66
|
|
|
67
|
```markdown |
|
68
|
## Summary |
|
69
|
|
|
70
|
By following this tutorial, you will learn how to: |
|
71
|
|
|
72
|
- Install and set up Medusa. |
|
73
|
- [Feature 1] |
|
74
|
- [Feature 2] |
|
75
|
- [Feature 3] |
|
76
|
``` |
|
77
|
|
|
78
|
### 7. Visual Elements |
|
79
|
|
|
80
|
- Include diagrams/images when helpful (use Cloudinary URLs) |
|
81
|
- Use `WorkflowDiagram` component for workflow visualizations |
|
82
|
- Use `CardList` or `Card` components for GitHub links and OpenAPI specs |
|
83
|
|
|
84
|
### 8. Step Structure |
|
85
|
|
|
86
|
#### Step 1: Install a Medusa Application (Always Required) |
|
87
|
|
|
88
|
```markdown |
|
89
|
## Step 1: Install a Medusa Application |
|
90
|
|
|
91
|
<Prerequisites items={[ |
|
92
|
{ |
|
93
|
text: "Node.js v20+", |
|
94
|
link: "https://nodejs.org/en/download" |
|
95
|
}, |
|
96
|
{ |
|
97
|
text: "Git CLI tool", |
|
98
|
link: "https://git-scm.com/downloads" |
|
99
|
}, |
|
100
|
{ |
|
101
|
text: "PostgreSQL", |
|
102
|
link: "https://www.postgresql.org/download/" |
|
103
|
} |
|
104
|
]} /> |
|
105
|
|
|
106
|
Start by installing the Medusa application on your machine with the following command: |
|
107
|
|
|
108
|
\`\`\`bash |
|
109
|
npx create-medusa-app@latest |
|
110
|
\`\`\` |
|
111
|
|
|
112
|
[Instructions about installation...] |
|
113
|
|
|
114
|
<Note title="Why is the storefront installed separately"> |
|
115
|
|
|
116
|
[Explanation] |
|
117
|
|
|
118
|
</Note> |
|
119
|
|
|
120
|
<Note title="Ran into Errors"> |
|
121
|
|
|
122
|
Check out the [troubleshooting guides](../../../troubleshooting/create-medusa-app-errors/page.mdx) for help. |
|
123
|
|
|
124
|
</Note> |
|
125
|
``` |
|
126
|
|
|
127
|
#### Subsequent Steps |
|
128
|
|
|
129
|
Each step should: |
|
130
|
|
|
131
|
- Have a clear, descriptive title: `## Step N: [Title]` |
|
132
|
- Start with context explaining what will be done |
|
133
|
- Break into subsections (a, b, c) if needed |
|
134
|
- Include code examples with proper formatting |
|
135
|
- Include Notes and Tips where helpful |
|
136
|
- End with "Test it Out" sections when applicable |
|
137
|
|
|
138
|
### 9. Code Block Formatting |
|
139
|
|
|
140
|
#### Basic Code Block |
|
141
|
|
|
142
|
```markdown |
|
143
|
\`\`\`ts title="src/path/to/file.ts" |
|
144
|
[code] |
|
145
|
\`\`\` |
|
146
|
``` |
|
147
|
|
|
148
|
#### Code Block with Highlights |
|
149
|
|
|
150
|
```markdown |
|
151
|
export const highlights = [ |
|
152
|
["line_number", "variable_name", "Description of what this does"], |
|
153
|
] |
|
154
|
|
|
155
|
\`\`\`ts title="src/path/to/file.ts" highlights={highlights} |
|
156
|
[code] |
|
157
|
\`\`\` |
|
158
|
``` |
|
159
|
|
|
160
|
#### Code Block with Collapsible Lines |
|
161
|
|
|
162
|
```markdown |
|
163
|
\`\`\`ts title="src/path/to/file.ts" collapsibleLines="1-10" expandButtonLabel="Show Imports" |
|
164
|
[code] |
|
165
|
\`\`\` |
|
166
|
``` |
|
167
|
|
|
168
|
#### Badge Labels |
|
169
|
|
|
170
|
- Use `badgeLabel="Storefront" badgeColor="blue"` for storefront code |
|
171
|
- Use `badgeLabel="Medusa Application" badgeColor="green"` for server code |
|
172
|
|
|
173
|
#### Example |
|
174
|
|
|
175
|
```markdown |
|
176
|
\`\`\`ts title="src/lib/data/cart.ts" badgeLabel="Storefront" badgeColor="blue" |
|
177
|
[code] |
|
178
|
\`\`\` |
|
179
|
``` |
|
180
|
|
|
181
|
### 10. Workflow Diagrams |
|
182
|
|
|
183
|
When documenting workflows, use the `WorkflowDiagram` component: |
|
184
|
|
|
185
|
```markdown |
|
186
|
<WorkflowDiagram |
|
187
|
workflow={{ |
|
188
|
name: "workflowName", |
|
189
|
steps: [ |
|
190
|
{ |
|
191
|
type: "step", |
|
192
|
name: "stepName", |
|
193
|
description: "Description of step", |
|
194
|
link: "/references/path/to/step", |
|
195
|
depth: 1 |
|
196
|
}, |
|
197
|
{ |
|
198
|
type: "when", |
|
199
|
condition: "Condition description", |
|
200
|
steps: [...], |
|
201
|
depth: 1 |
|
202
|
} |
|
203
|
] |
|
204
|
}} |
|
205
|
/> |
|
206
|
``` |
|
207
|
|
|
208
|
### 11. Notes and Tips |
|
209
|
|
|
210
|
Use consistently: |
|
211
|
|
|
212
|
- `<Note>` for general notes |
|
213
|
- `<Note title="Title">` for titled notes |
|
214
|
- `<Note title="Tip">` for tips |
|
215
|
- `<Note title="Reminder" forceMultiline>` for reminders |
|
216
|
|
|
217
|
### 12. Links to Documentation |
|
218
|
|
|
219
|
Use the special link syntax: |
|
220
|
|
|
221
|
- `!docs!/path/to/doc` for documentation links |
|
222
|
- `!api!/path/to/api` for API reference links |
|
223
|
- `!user-guide!/path/to/guide` for user guide links |
|
224
|
- `!ui!/path/to/component` for UI component links |
|
225
|
- `!cloud!/path/to/doc` for cloud documentation |
|
226
|
|
|
227
|
### 13. Test Sections |
|
228
|
|
|
229
|
Include "Test it Out" sections after major implementations: |
|
230
|
|
|
231
|
```markdown |
|
232
|
### Test it Out |
|
233
|
|
|
234
|
To test out [feature], start the Medusa application: |
|
235
|
|
|
236
|
\`\`\`bash npm2yarn badgeLabel="Medusa Application" badgeColor="green" |
|
237
|
npm run dev |
|
238
|
\`\`\` |
|
239
|
|
|
240
|
[Additional testing instructions...] |
|
241
|
``` |
|
242
|
|
|
243
|
### 14. Next Steps Section |
|
244
|
|
|
245
|
End every tutorial with: |
|
246
|
|
|
247
|
```markdown |
|
248
|
## Next Steps |
|
249
|
|
|
250
|
You've now implemented [feature] in Medusa. [Optional: suggest related features or improvements] |
|
251
|
|
|
252
|
If you're new to Medusa, check out the [main documentation](!docs!/learn), where you'll get a more in-depth understanding of all the concepts you've used in this guide and more. |
|
253
|
|
|
254
|
To learn more about the commerce features that Medusa provides, check out Medusa's [Commerce Modules](../../../commerce-modules/page.mdx). |
|
255
|
``` |
|
256
|
|
|
257
|
### 15. Optional Sections |
|
258
|
|
|
259
|
#### Troubleshooting |
|
260
|
|
|
261
|
```markdown |
|
262
|
### Troubleshooting |
|
263
|
|
|
264
|
If you encounter issues during your development, check out the [troubleshooting guides](../../../troubleshooting/page.mdx). |
|
265
|
``` |
|
266
|
|
|
267
|
#### Getting Help |
|
268
|
|
|
269
|
```markdown |
|
270
|
### Getting Help |
|
271
|
|
|
272
|
If you encounter issues not covered in the troubleshooting guides: |
|
273
|
|
|
274
|
1. Visit the [Medusa GitHub repository](https://github.com/medusajs/medusa) to report issues or ask questions. |
|
275
|
2. Join the [Medusa Discord community](https://discord.gg/medusajs) for real-time support from community members. |
|
276
|
``` |
|
277
|
|
|
278
|
## Code Organization Guidelines |
|
279
|
|
|
280
|
### File Paths |
|
281
|
|
|
282
|
- Always use absolute paths or paths relative to the workspace root |
|
283
|
- Use `src/` prefix for source files |
|
284
|
- Specify file paths clearly in code block titles |
|
285
|
|
|
286
|
### Naming Conventions |
|
287
|
|
|
288
|
- Use descriptive variable and function names |
|
289
|
- Follow TypeScript/JavaScript conventions |
|
290
|
- Use camelCase for variables and functions |
|
291
|
- Use PascalCase for components and classes |
|
292
|
|
|
293
|
### Code Comments |
|
294
|
|
|
295
|
- Add comments explaining complex logic |
|
296
|
- Use highlights arrays to explain important lines |
|
297
|
- Include context about why code is structured a certain way |
|
298
|
|
|
299
|
## Content Guidelines |
|
300
|
|
|
301
|
### Clarity |
|
302
|
|
|
303
|
- Write in second person ("you'll learn", "you'll create") |
|
304
|
- Use active voice |
|
305
|
- Be specific and concrete |
|
306
|
- Avoid jargon without explanation |
|
307
|
|
|
308
|
### Completeness |
|
309
|
|
|
310
|
- Include all necessary code |
|
311
|
- Explain each step thoroughly |
|
312
|
- Provide context for decisions |
|
313
|
- Include error handling where relevant |
|
314
|
|
|
315
|
### Consistency |
|
316
|
|
|
317
|
- Use consistent terminology throughout |
|
318
|
- Follow the same structure for similar steps |
|
319
|
- Use the same formatting for code blocks |
|
320
|
- Maintain consistent tone |
|
321
|
|
|
322
|
## Common Patterns |
|
323
|
|
|
324
|
### Module Creation Steps |
|
325
|
|
|
326
|
1. Create module directory |
|
327
|
2. Create data models |
|
328
|
3. Create module service |
|
329
|
4. Export module definition |
|
330
|
5. Add module to config |
|
331
|
6. Generate migrations |
|
332
|
|
|
333
|
### Workflow Creation Steps |
|
334
|
|
|
335
|
1. Create workflow steps |
|
336
|
2. Create workflow |
|
337
|
3. Create API route (if needed) |
|
338
|
4. Add middleware (if needed) |
|
339
|
5. Test |
|
340
|
|
|
341
|
### Storefront Customization Steps |
|
342
|
|
|
343
|
1. Add types/interfaces |
|
344
|
2. Add data fetching functions |
|
345
|
3. Create components |
|
346
|
4. Integrate into existing pages |
|
347
|
5. Test |
|
348
|
|
|
349
|
## Checklist for Tutorial Creation |
|
350
|
|
|
351
|
- [ ] Frontmatter with all required fields |
|
352
|
- [ ] Metadata export |
|
353
|
- [ ] Title section |
|
354
|
- [ ] Context paragraph |
|
355
|
- [ ] Summary section |
|
356
|
- [ ] Step 1: Install Medusa Application |
|
357
|
- [ ] Subsequent steps with clear titles |
|
358
|
- [ ] Code blocks with proper formatting |
|
359
|
- [ ] Highlights arrays for important code |
|
360
|
- [ ] Notes and Tips where helpful |
|
361
|
- [ ] Test sections after major implementations |
|
362
|
- [ ] Workflow diagrams for workflows |
|
363
|
- [ ] Links to documentation using special syntax |
|
364
|
- [ ] Next Steps section |
|
365
|
- [ ] Optional: Troubleshooting section |
|
366
|
- [ ] Optional: Getting Help section |
|
367
|
- [ ] All code examples are complete and runnable |
|
368
|
- [ ] File paths are correct |
|
369
|
- [ ] Badge labels for storefront vs server code |
|
370
|
- [ ] Consistent formatting throughout |
|
371
|
|
|
372
|
## Special Considerations |
|
373
|
|
|
374
|
### Storefront vs Server Code |
|
375
|
|
|
376
|
- Always use badge labels to distinguish storefront and server code |
|
377
|
- Storefront code: `badgeLabel="Storefront" badgeColor="blue"` |
|
378
|
- Server code: `badgeLabel="Medusa Application" badgeColor="green"` |
|
379
|
|
|
380
|
### Workflow Documentation |
|
381
|
|
|
382
|
- Always include WorkflowDiagram for complex workflows |
|
383
|
- Explain each step clearly |
|
384
|
- Show the flow of data |
|
385
|
- Include compensation functions when relevant |
|
386
|
|
|
387
|
### API Routes |
|
388
|
|
|
389
|
- Show request/response examples |
|
390
|
- Include authentication requirements |
|
391
|
- Show middleware configuration |
|
392
|
- Include validation schemas |
|
393
|
|
|
394
|
### Admin Customizations |
|
395
|
|
|
396
|
- Show UI route or widget creation |
|
397
|
- Include configuration exports |
|
398
|
- Show how to test in admin dashboard |
|
399
|
|
|
400
|
## Examples of Good Tutorial Structure |
|
401
|
|
|
402
|
### Example Step |
|
403
|
|
|
404
|
```markdown |
|
405
|
## Step 2: Create Custom Module |
|
406
|
|
|
407
|
In this step, you'll create a custom module to [purpose]. |
|
408
|
|
|
409
|
<Note> |
|
410
|
|
|
411
|
Refer to the [Modules documentation](!docs!/learn/fundamentals/modules) to learn more. |
|
412
|
|
|
413
|
</Note> |
|
414
|
|
|
415
|
### Create Module Directory |
|
416
|
|
|
417
|
Modules are created under the `src/modules` directory. So, create the directory `src/modules/custom-module`. |
|
418
|
|
|
419
|
### Create Data Models |
|
420
|
|
|
421
|
[Explanation of data models...] |
|
422
|
|
|
423
|
\`\`\`ts title="src/modules/custom-module/models/model.ts" |
|
424
|
[code] |
|
425
|
\`\`\` |
|
426
|
|
|
427
|
[Explanation of code...] |
|
428
|
|
|
429
|
### Test it Out |
|
430
|
|
|
431
|
To test [feature]: |
|
432
|
|
|
433
|
\`\`\`bash npm2yarn badgeLabel="Medusa Application" badgeColor="green" |
|
434
|
npm run dev |
|
435
|
\`\`\` |
|
436
|
|
|
437
|
[Testing instructions...] |
|
438
|
``` |
|
439
|
|
|
440
|
## Final Notes |
|
441
|
|
|
442
|
- Always prioritize clarity and completeness |
|
443
|
- Include all necessary context |
|
444
|
- Test all code examples |
|
445
|
- Follow the established patterns |
|
446
|
- Maintain consistency with existing tutorials |
|
447
|
- Update this file if new patterns emerge |