@champpaba/claude-agent-kit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +561 -0
  3. package/bin/cli.js +61 -0
  4. package/lib/init.js +52 -0
  5. package/lib/update.js +73 -0
  6. package/package.json +47 -0
  7. package/template/.claude/CHANGELOG-v1.1.1.md +259 -0
  8. package/template/.claude/CLAUDE.md +329 -0
  9. package/template/.claude/agents/01-integration.md +797 -0
  10. package/template/.claude/agents/02-uxui-frontend.md +899 -0
  11. package/template/.claude/agents/03-test-debug.md +759 -0
  12. package/template/.claude/agents/04-frontend.md +1099 -0
  13. package/template/.claude/agents/05-backend.md +1217 -0
  14. package/template/.claude/agents/06-database.md +969 -0
  15. package/template/.claude/commands/agentsetup.md +1464 -0
  16. package/template/.claude/commands/cdev.md +327 -0
  17. package/template/.claude/commands/csetup.md +447 -0
  18. package/template/.claude/commands/cstatus.md +60 -0
  19. package/template/.claude/commands/cview.md +364 -0
  20. package/template/.claude/commands/psetup.md +101 -0
  21. package/template/.claude/contexts/design/accessibility.md +611 -0
  22. package/template/.claude/contexts/design/box-thinking.md +553 -0
  23. package/template/.claude/contexts/design/color-theory.md +498 -0
  24. package/template/.claude/contexts/design/index.md +247 -0
  25. package/template/.claude/contexts/design/layout.md +400 -0
  26. package/template/.claude/contexts/design/responsive.md +551 -0
  27. package/template/.claude/contexts/design/shadows.md +522 -0
  28. package/template/.claude/contexts/design/spacing.md +428 -0
  29. package/template/.claude/contexts/design/typography.md +465 -0
  30. package/template/.claude/contexts/domain/README.md +164 -0
  31. package/template/.claude/contexts/patterns/agent-coordination.md +388 -0
  32. package/template/.claude/contexts/patterns/agent-discovery.md +182 -0
  33. package/template/.claude/contexts/patterns/change-workflow.md +538 -0
  34. package/template/.claude/contexts/patterns/code-standards.md +515 -0
  35. package/template/.claude/contexts/patterns/development-principles.md +513 -0
  36. package/template/.claude/contexts/patterns/error-handling.md +478 -0
  37. package/template/.claude/contexts/patterns/error-recovery.md +365 -0
  38. package/template/.claude/contexts/patterns/frontend-component-strategy.md +365 -0
  39. package/template/.claude/contexts/patterns/git-workflow.md +207 -0
  40. package/template/.claude/contexts/patterns/logging.md +424 -0
  41. package/template/.claude/contexts/patterns/task-breakdown.md +452 -0
  42. package/template/.claude/contexts/patterns/task-classification.md +523 -0
  43. package/template/.claude/contexts/patterns/tdd-classification.md +516 -0
  44. package/template/.claude/contexts/patterns/testing.md +413 -0
  45. package/template/.claude/contexts/patterns/ui-component-consistency.md +304 -0
  46. package/template/.claude/contexts/patterns/validation-framework.md +776 -0
  47. package/template/.claude/lib/README.md +39 -0
  48. package/template/.claude/lib/agent-executor.md +258 -0
  49. package/template/.claude/lib/agent-router.md +572 -0
  50. package/template/.claude/lib/flags-updater.md +469 -0
  51. package/template/.claude/lib/tdd-classifier.md +345 -0
  52. package/template/.claude/lib/validation-gates.md +484 -0
  53. package/template/.claude/settings.local.json +42 -0
  54. package/template/.claude/templates/context-template.md +45 -0
  55. package/template/.claude/templates/flags-template.json +42 -0
  56. package/template/.claude/templates/phase-templates.json +124 -0
  57. package/template/.claude/templates/phases-sections/accessibility-test.md +17 -0
  58. package/template/.claude/templates/phases-sections/api-design.md +37 -0
  59. package/template/.claude/templates/phases-sections/backend-tests.md +16 -0
  60. package/template/.claude/templates/phases-sections/backend.md +37 -0
  61. package/template/.claude/templates/phases-sections/business-logic-validation.md +16 -0
  62. package/template/.claude/templates/phases-sections/component-tests.md +17 -0
  63. package/template/.claude/templates/phases-sections/contract-backend.md +16 -0
  64. package/template/.claude/templates/phases-sections/contract-frontend.md +16 -0
  65. package/template/.claude/templates/phases-sections/database.md +35 -0
  66. package/template/.claude/templates/phases-sections/documentation.md +17 -0
  67. package/template/.claude/templates/phases-sections/e2e-tests.md +16 -0
  68. package/template/.claude/templates/phases-sections/fix-implementation.md +17 -0
  69. package/template/.claude/templates/phases-sections/frontend-integration.md +18 -0
  70. package/template/.claude/templates/phases-sections/frontend-mockup.md +123 -0
  71. package/template/.claude/templates/phases-sections/manual-flow-test.md +15 -0
  72. package/template/.claude/templates/phases-sections/manual-ux-test.md +16 -0
  73. package/template/.claude/templates/phases-sections/refactor-implementation.md +17 -0
  74. package/template/.claude/templates/phases-sections/refactor.md +16 -0
  75. package/template/.claude/templates/phases-sections/regression-tests.md +15 -0
  76. package/template/.claude/templates/phases-sections/report.md +16 -0
  77. package/template/.claude/templates/phases-sections/responsive-test.md +16 -0
  78. package/template/.claude/templates/phases-sections/script-implementation.md +43 -0
  79. package/template/.claude/templates/phases-sections/test-coverage.md +16 -0
  80. package/template/.claude/templates/phases-sections/user-approval.md +14 -0
@@ -0,0 +1,1464 @@
1
+ # Agent Setup Command
2
+
3
+ > **Purpose:** Auto-detect tech stack and setup domain context for the project
4
+
5
+ ---
6
+
7
+ ## Your Task
8
+
9
+ You are the **Agent Setup Assistant**. Your job is to:
10
+
11
+ 1. Detect if this is a **greenfield** (new) or **brownfield** (existing) project
12
+ 2. Identify the tech stack
13
+ 3. Pull latest docs from Context7 MCP
14
+ 4. Create domain-specific context files
15
+
16
+ ---
17
+
18
+ ## Step 1: Check if Re-run
19
+
20
+ **FIRST, check if tech-stack.md already exists:**
21
+
22
+ ```bash
23
+ .claude/contexts/domain/{project}/tech-stack.md
24
+ ```
25
+
26
+ **Decision:**
27
+ - **IF tech-stack.md exists** → **RE-RUN MODE** (go to Step 1A)
28
+ - **ELSE** → **FIRST RUN** (go to Step 1B)
29
+
30
+ ---
31
+
32
+ ## Step 1A: Re-run Mode (tech-stack.md exists)
33
+
34
+ **This means user already ran `/agentsetup` before.**
35
+
36
+ ### 1. Read existing tech-stack.md
37
+
38
+ Parse the existing stack:
39
+ ```markdown
40
+ | Category | Library | Version | Context7 ID |
41
+ |----------|---------|---------|-------------|
42
+ | Frontend | Next.js | 15.5.0 | /vercel/next.js |
43
+ | Database | Prisma | 6.5.0 | /prisma/prisma |
44
+ ```
45
+
46
+ ### 2. Check for package files NOW
47
+
48
+ - `package.json` (Node.js/JS/TS)
49
+ - `requirements.txt` or `pyproject.toml` (Python)
50
+ - `composer.json` (PHP)
51
+ - `Cargo.toml` (Rust)
52
+ - `go.mod` (Go)
53
+ - `pom.xml` or `build.gradle` (Java)
54
+ - `Gemfile` (Ruby)
55
+
56
+ ### 3. Compare old vs new
57
+
58
+ **Scenario A: Package file found (Greenfield → Brownfield)**
59
+
60
+ ```
61
+ Old stack (from tech-stack.md):
62
+ - Frontend: Next.js (no version - was greenfield)
63
+ - Database: Prisma (no version)
64
+
65
+ New stack (from package.json):
66
+ - Frontend: Next.js 15.5.0 ✓ (version detected!)
67
+ - Database: Prisma 6.5.0 ✓ (version detected!)
68
+ - State: Zustand 5.0.0 🆕 (newly added!)
69
+ - Testing: Vitest 2.0.0 🆕 (newly added!)
70
+ ```
71
+
72
+ **Output:**
73
+ ```
74
+ 🔄 Tech stack update detected!
75
+
76
+ 📋 Changes:
77
+ ✓ Next.js: (no version) → 15.5.0
78
+ ✓ Prisma: (no version) → 6.5.0
79
+ 🆕 Zustand: 5.0.0 (newly added)
80
+ 🆕 Vitest: 2.0.0 (newly added)
81
+
82
+ ❓ Update tech-stack.md? (yes/no)
83
+ ```
84
+
85
+ **Scenario B: Package file found (Brownfield → Brownfield updated)**
86
+
87
+ ```
88
+ Old stack (from tech-stack.md):
89
+ - Frontend: Next.js 15.5.0
90
+ - Database: Prisma 6.5.0
91
+
92
+ New stack (from package.json):
93
+ - Frontend: Next.js 15.8.0 ⬆️ (upgraded!)
94
+ - Database: Prisma 6.7.0 ⬆️ (upgraded!)
95
+ - State: Zustand 5.0.0 🆕 (newly added!)
96
+ ```
97
+
98
+ **Output:**
99
+ ```
100
+ 🔄 Tech stack update detected!
101
+
102
+ 📋 Changes:
103
+ ⬆️ Next.js: 15.5.0 → 15.8.0 (upgraded)
104
+ ⬆️ Prisma: 6.5.0 → 6.7.0 (upgraded)
105
+ 🆕 Zustand: 5.0.0 (newly added)
106
+
107
+ ❓ Update tech-stack.md and re-fetch Context7 docs? (yes/no)
108
+ ```
109
+
110
+ **Scenario C: No package file (Greenfield → Greenfield still)**
111
+
112
+ ```
113
+ Old stack (from tech-stack.md):
114
+ - Frontend: Next.js (no version)
115
+ - Database: Prisma (no version)
116
+
117
+ New stack: (no package file found)
118
+ - Same as old
119
+ ```
120
+
121
+ **Output:**
122
+ ```
123
+ ℹ️ No changes detected.
124
+
125
+ Your project is still in greenfield mode (no package.json found).
126
+
127
+ Options:
128
+ 1. Keep existing tech-stack.md
129
+ 2. Re-run setup (ask questions again)
130
+
131
+ Choose: (1/2)
132
+ ```
133
+
134
+ ### 4. User confirms update
135
+
136
+ **If user says "yes":**
137
+ - Re-run Context7 searches with new versions
138
+ - Update tech-stack.md with new stack
139
+ - Show summary
140
+
141
+ **If user says "no":**
142
+ - Keep existing tech-stack.md
143
+ - Exit
144
+
145
+ ---
146
+
147
+ ## Step 1B: First Run (tech-stack.md does NOT exist)
148
+
149
+ **Check for these files in the project root:**
150
+
151
+ - `package.json` (Node.js/JS/TS)
152
+ - `requirements.txt` or `pyproject.toml` (Python)
153
+ - `composer.json` (PHP)
154
+ - `Cargo.toml` (Rust)
155
+ - `go.mod` (Go)
156
+ - `pom.xml` or `build.gradle` (Java)
157
+ - `Gemfile` (Ruby)
158
+
159
+ **Decision:**
160
+ - **IF any file found** → **BROWNFIELD** (existing project - go to Step 2B)
161
+ - **ELSE** → **GREENFIELD** (new project - go to Step 2A)
162
+
163
+ ---
164
+
165
+ ## Step 2A: Greenfield Flow
166
+
167
+ ### Ask User for Tech Stack
168
+
169
+ Use the **AskUserQuestion** tool:
170
+
171
+ ```markdown
172
+ **Question:** "What tech stack do you want to use for this project?"
173
+
174
+ **Options:**
175
+ 1. Next.js (React framework with SSR)
176
+ 2. FastAPI (Python async web framework)
177
+ 3. Django (Python full-stack framework)
178
+ 4. Express (Node.js minimal framework)
179
+ 5. Laravel (PHP full-stack framework)
180
+ 6. Ruby on Rails (Ruby full-stack framework)
181
+ ```
182
+
183
+ **Follow-up questions based on ecosystem:**
184
+
185
+ #### If JavaScript/TypeScript stack (Next.js, Express, etc.):
186
+ ```markdown
187
+ 1. Database: Prisma / Drizzle / TypeORM?
188
+ 2. Testing: Vitest / Jest / Playwright?
189
+ 3. State Management: Zustand / Redux / Jotai?
190
+ 4. **Package Manager:**
191
+ - pnpm (recommended - fast, disk efficient)
192
+ - npm (default - slower but universal)
193
+ - bun (experimental - fastest, some compatibility issues)
194
+ - yarn (classic - stable but slower than pnpm)
195
+ ```
196
+
197
+ #### If Python stack (FastAPI, Django, Flask):
198
+ ```markdown
199
+ 1. Database: SQLAlchemy / Prisma (via Python client) / Django ORM?
200
+ 2. Testing: Pytest / Unittest?
201
+ 3. **Package Manager:**
202
+ - uv (recommended - fastest, pip replacement)
203
+ - poetry (stable - dependency resolution + virtual envs)
204
+ - pip + venv (classic - simple but slow)
205
+ - pipenv (stable - older alternative to poetry)
206
+ ```
207
+
208
+ #### If PHP stack (Laravel):
209
+ ```markdown
210
+ 1. Testing: PHPUnit / Pest?
211
+ 2. **Package Manager:** composer (standard)
212
+ ```
213
+
214
+ #### If Ruby stack (Rails):
215
+ ```markdown
216
+ 1. Testing: RSpec / Minitest?
217
+ 2. **Package Manager:** bundler (standard)
218
+ ```
219
+
220
+ #### If Go stack:
221
+ ```markdown
222
+ **Package Manager:** go (standard go mod)
223
+ ```
224
+
225
+ #### If Rust stack:
226
+ ```markdown
227
+ **Package Manager:** cargo (standard)
228
+ ```
229
+
230
+ ### Example Interaction:
231
+
232
+ ```
233
+ User selects: Next.js
234
+ → Ask: "Which database ORM?"
235
+ - Prisma ✓
236
+ - Drizzle
237
+ - TypeORM
238
+
239
+ User selects: Prisma
240
+ → Ask: "Which testing framework?"
241
+ - Vitest ✓
242
+ - Jest
243
+ - Playwright (E2E)
244
+
245
+ User selects: Vitest
246
+ → Ask: "Which package manager?"
247
+ - pnpm (recommended - 3x faster than npm, disk efficient)
248
+ - npm (default - slower but works everywhere)
249
+ - bun (experimental - fastest but may have issues)
250
+ - yarn (stable alternative)
251
+
252
+ User selects: pnpm
253
+ ```
254
+
255
+ ```
256
+ User selects: FastAPI
257
+ → Ask: "Which database ORM?"
258
+ - SQLAlchemy ✓
259
+ - Prisma Python
260
+ - TortoiseORM
261
+
262
+ User selects: SQLAlchemy
263
+ → Ask: "Which testing framework?"
264
+ - Pytest ✓
265
+ - Unittest
266
+
267
+ User selects: Pytest
268
+ → Ask: "Which package manager?"
269
+ - uv (recommended - 10-100x faster than pip)
270
+ - poetry (stable - good dependency resolution)
271
+ - pip + venv (classic - simple but slow)
272
+ - pipenv (older alternative)
273
+
274
+ User selects: uv
275
+ ```
276
+
277
+ **Store selections for tech-stack.md:**
278
+ ```markdown
279
+ Selected Stack:
280
+ - Framework: FastAPI (latest)
281
+ - Database: SQLAlchemy (latest)
282
+ - Testing: Pytest (latest)
283
+ - Package Manager: uv (latest)
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Step 2B: Brownfield Flow
289
+
290
+ ### Auto-Detect Stack from Files
291
+
292
+ **Read the dependency file and extract versions:**
293
+
294
+ ### **FIRST: Detect Package Manager(s)**
295
+
296
+ Check for lock files to determine package manager:
297
+
298
+ #### JavaScript/TypeScript Package Managers:
299
+ ```bash
300
+ # Check in order:
301
+ 1. bun.lockb → bun
302
+ 2. pnpm-lock.yaml → pnpm
303
+ 3. yarn.lock → yarn (check version: yarn.lock v1 vs v3+)
304
+ 4. package-lock.json → npm
305
+ 5. package.json only → ask user (default: pnpm)
306
+ ```
307
+
308
+ #### Python Package Managers:
309
+ ```bash
310
+ # Check in order:
311
+ 1. uv.lock → uv
312
+ 2. poetry.lock → poetry
313
+ 3. Pipfile.lock → pipenv
314
+ 4. pdm.lock → pdm
315
+ 5. pyproject.toml:
316
+ - Has [tool.uv] → uv
317
+ - Has [tool.poetry] → poetry
318
+ - Has [tool.pdm] → pdm
319
+ 6. requirements.txt only → ask user (default: uv)
320
+ ```
321
+
322
+ #### Other Ecosystems:
323
+ ```bash
324
+ - composer.lock → composer (PHP)
325
+ - Gemfile.lock → bundler (Ruby)
326
+ - go.mod → go (Go ecosystem)
327
+ - Cargo.lock → cargo (Rust)
328
+ - pnpm-workspace.yaml → pnpm (monorepo)
329
+ ```
330
+
331
+ **Store detected package manager(s):**
332
+ ```markdown
333
+ Package Manager(s) Detected:
334
+ - JavaScript: pnpm 9.x (from pnpm-lock.yaml)
335
+ - Python: uv 0.4.x (from uv.lock)
336
+ ```
337
+
338
+ **If multiple ecosystems found (e.g., monorepo):**
339
+ ```markdown
340
+ Monorepo Detected:
341
+ - Frontend (JS): pnpm
342
+ - Backend (Python): uv
343
+ - Docs (Ruby): bundler
344
+ ```
345
+
346
+ ---
347
+
348
+ #### Node.js (package.json)
349
+ ```typescript
350
+ // Read package.json
351
+ {
352
+ "dependencies": {
353
+ "next": "15.5.0",
354
+ "@prisma/client": "6.5.0",
355
+ "zustand": "5.0.0"
356
+ },
357
+ "devDependencies": {
358
+ "vitest": "2.0.0",
359
+ "playwright": "1.40.0"
360
+ }
361
+ }
362
+
363
+ // Extract:
364
+ Stack detected:
365
+ - Frontend: Next.js 15.5.0
366
+ - Database: Prisma 6.5.0
367
+ - State: Zustand 5.0.0
368
+ - Testing: Vitest 2.0.0, Playwright 1.40.0
369
+ ```
370
+
371
+ #### Python (requirements.txt)
372
+ ```txt
373
+ fastapi==0.104.1
374
+ sqlalchemy==2.0.23
375
+ pytest==7.4.3
376
+ pydantic==2.5.0
377
+
378
+ // Extract:
379
+ Stack detected:
380
+ - Backend: FastAPI 0.104.1
381
+ - Database: SQLAlchemy 2.0.23
382
+ - Testing: Pytest 7.4.3
383
+ - Validation: Pydantic 2.5.0
384
+ ```
385
+
386
+ #### Python (pyproject.toml)
387
+ ```toml
388
+ [tool.poetry.dependencies]
389
+ python = "^3.11"
390
+ fastapi = "^0.104.1"
391
+ sqlalchemy = "^2.0.23"
392
+
393
+ // Extract same as above
394
+ ```
395
+
396
+ **Output to user:**
397
+ ```
398
+ 🔍 Detected tech stack:
399
+ - Frontend: Next.js 15.5.0
400
+ - Database: Prisma 6.5.0
401
+ - State: Zustand 5.0.0
402
+ - Testing: Vitest 2.0.0
403
+
404
+ Is this correct? (yes/no)
405
+ ```
406
+
407
+ If user says "no", switch to **Greenfield flow** (ask manually).
408
+
409
+ ---
410
+
411
+ ## Step 3: Pull Docs from Context7 MCP
412
+
413
+ For each detected library, use Context7 MCP to get latest docs.
414
+
415
+ ### Use Context7 MCP Tools
416
+
417
+ **Available tools:**
418
+ 1. `mcp__context7__resolve-library-id` - Find library ID
419
+ 2. `mcp__context7__get-library-docs` - Get documentation
420
+
421
+ ### Example: Next.js
422
+
423
+ ```typescript
424
+ // Step 1: Resolve library ID
425
+ mcp__context7__resolve-library-id({
426
+ libraryName: "Next.js"
427
+ })
428
+ → Response: { id: "/vercel/next.js", name: "Next.js", ... }
429
+
430
+ // Step 2: Get docs (latest version)
431
+ mcp__context7__get-library-docs({
432
+ context7CompatibleLibraryID: "/vercel/next.js",
433
+ topic: "App Router Server Components",
434
+ tokens: 5000
435
+ })
436
+ → Response: "Next.js 15 App Router documentation..."
437
+ ```
438
+
439
+ ### Example: Specific Version
440
+
441
+ ```typescript
442
+ // If detected version is 15.5.0
443
+ mcp__context7__get-library-docs({
444
+ context7CompatibleLibraryID: "/vercel/next.js/v15.5.0",
445
+ topic: "API Routes",
446
+ tokens: 5000
447
+ })
448
+ ```
449
+
450
+ ### Libraries to Search
451
+
452
+ For each major library in the stack, search Context7:
453
+
454
+ **Frontend:**
455
+ - Next.js → "/vercel/next.js"
456
+ - React → "/facebook/react"
457
+ - Vue → "/vuejs/vue"
458
+ - Svelte → "/sveltejs/svelte"
459
+
460
+ **Backend:**
461
+ - FastAPI → "/tiangolo/fastapi"
462
+ - Express → "/expressjs/express"
463
+ - NestJS → "/nestjs/nest"
464
+ - Django → Search "Django"
465
+
466
+ **Database:**
467
+ - Prisma → "/prisma/prisma"
468
+ - SQLAlchemy → Search "SQLAlchemy"
469
+ - TypeORM → "/typeorm/typeorm"
470
+ - Drizzle → "/drizzle-team/drizzle-orm"
471
+
472
+ **Testing:**
473
+ - Vitest → "/vitest-dev/vitest"
474
+ - Jest → "/jestjs/jest"
475
+ - Playwright → "/microsoft/playwright"
476
+ - Pytest → Search "Pytest"
477
+
478
+ **State Management:**
479
+ - Zustand → "/pmndrs/zustand"
480
+ - Redux → "/reduxjs/redux-toolkit"
481
+ - Pinia → "/vuejs/pinia"
482
+
483
+ ---
484
+
485
+ ## Step 3.5: Generate Framework Best Practices & Examples
486
+
487
+ **THIS IS THE NEW CRITICAL STEP!**
488
+
489
+ After pulling docs from Context7, use that knowledge to generate framework-specific best practices and code examples.
490
+
491
+ ### Create Directory Structure
492
+
493
+ ```bash
494
+ mkdir -p .claude/contexts/frameworks/examples
495
+ ```
496
+
497
+ ### For Each Major Framework in Stack
498
+
499
+ For each framework detected (React, Next.js, Vue, FastAPI, etc.), generate TWO things:
500
+
501
+ #### 1. Best Practices File: `{framework}-best-practices.md`
502
+
503
+ **Query Context7 for:**
504
+ - Best practices and patterns
505
+ - Common anti-patterns and mistakes
506
+ - DO's and DON'Ts
507
+ - Quick reference checklist
508
+
509
+ **Example Queries:**
510
+
511
+ ```typescript
512
+ // For React
513
+ mcp__context7__get-library-docs({
514
+ context7CompatibleLibraryID: "/facebook/react",
515
+ topic: "hooks best practices, common mistakes, anti-patterns, rules of hooks",
516
+ tokens: 8000
517
+ })
518
+
519
+ // For Next.js
520
+ mcp__context7__get-library-docs({
521
+ context7CompatibleLibraryID: "/vercel/next.js",
522
+ topic: "App Router best practices, Server Components vs Client Components, common mistakes, data fetching patterns",
523
+ tokens: 8000
524
+ })
525
+
526
+ // For FastAPI
527
+ mcp__context7__get-library-docs({
528
+ context7CompatibleLibraryID: "/tiangolo/fastapi",
529
+ topic: "endpoint patterns, validation best practices, error handling, dependency injection",
530
+ tokens: 8000
531
+ })
532
+
533
+ // For Prisma
534
+ mcp__context7__get-library-docs({
535
+ context7CompatibleLibraryID: "/prisma/prisma",
536
+ topic: "schema design patterns, query optimization, transaction handling, common mistakes",
537
+ tokens: 8000
538
+ })
539
+ ```
540
+
541
+ **File Structure Template:**
542
+
543
+ ```markdown
544
+ # {Framework} Best Practices
545
+
546
+ **Source:** Context7 - {Framework} Documentation
547
+ **Last Updated:** {date}
548
+ **Version:** {detected_version}
549
+
550
+ ---
551
+
552
+ ## ✅ DO (Best Practices)
553
+
554
+ ### 1. {Best Practice Category}
555
+ - {Practice 1}
556
+ - {Practice 2}
557
+ - {Practice 3}
558
+
559
+ ### 2. {Another Category}
560
+ - {Practice 1}
561
+ - {Practice 2}
562
+
563
+ ---
564
+
565
+ ## ❌ DON'T (Anti-Patterns)
566
+
567
+ ### 🚫 Critical Mistakes (Check Before Committing):
568
+
569
+ - [ ] ❌ **{Anti-pattern 1}**
570
+ ```code
571
+ // ❌ BAD - {why it's bad}
572
+ {bad example}
573
+
574
+ // ✅ GOOD - {why it's good}
575
+ {good example}
576
+ ```
577
+
578
+ - [ ] ❌ **{Anti-pattern 2}**
579
+ ```code
580
+ // ❌ BAD
581
+ {bad example}
582
+
583
+ // ✅ GOOD
584
+ {good example}
585
+ ```
586
+
587
+ ---
588
+
589
+ ## 🔧 Common Mistakes & How to Fix
590
+
591
+ ### 1. {Common Mistake Title}
592
+
593
+ ```code
594
+ // ❌ BAD - {description}
595
+ {bad code}
596
+
597
+ // ✅ GOOD - {description}
598
+ {good code}
599
+ ```
600
+
601
+ ### 2. {Another Common Mistake}
602
+
603
+ {explanation and fix}
604
+
605
+ ---
606
+
607
+ ## 🎯 Quick Checklist
608
+
609
+ Before committing {framework} code:
610
+
611
+ **{Category 1}:**
612
+ - [ ] {check 1}
613
+ - [ ] {check 2}
614
+
615
+ **{Category 2}:**
616
+ - [ ] {check 1}
617
+ - [ ] {check 2}
618
+
619
+ ---
620
+
621
+ **⚠️ All agents MUST read this file before writing {framework} code!**
622
+ ```
623
+
624
+ **Save to:** `.claude/contexts/frameworks/{framework}-best-practices.md`
625
+
626
+ ---
627
+
628
+ #### 2. Example Code Files: `examples/{example-name}.{ext}`
629
+
630
+ **Query Context7 for code examples:**
631
+
632
+ ```typescript
633
+ // For React - Custom Hook Example
634
+ mcp__context7__get-library-docs({
635
+ context7CompatibleLibraryID: "/facebook/react",
636
+ topic: "custom hooks example for data fetching with loading error states and cleanup",
637
+ tokens: 5000
638
+ })
639
+
640
+ // For React - Error Boundary Example
641
+ mcp__context7__get-library-docs({
642
+ context7CompatibleLibraryID: "/facebook/react",
643
+ topic: "Error Boundary component implementation with TypeScript, reset functionality",
644
+ tokens: 5000
645
+ })
646
+ ```
647
+
648
+ **Generate 1-2 Complete, Working Examples Per Framework:**
649
+
650
+ **For React:**
651
+ - `examples/use-fetch.tsx` - Custom hook with loading/error/cleanup
652
+ - `examples/error-boundary.tsx` - Error boundary with reset
653
+
654
+ **For Next.js:**
655
+ - `examples/server-component.tsx` - Async Server Component with data fetching
656
+ - `examples/route-handler.ts` - API Route Handler with validation
657
+
658
+ **For FastAPI:**
659
+ - `examples/endpoint-pattern.py` - REST endpoint with validation/error handling
660
+ - `examples/dependency-injection.py` - Dependency injection pattern
661
+
662
+ **For Prisma:**
663
+ - `examples/transaction-pattern.ts` - Safe transaction handling
664
+ - `examples/query-optimization.ts` - Optimized queries with relations
665
+
666
+ **Example File Template:**
667
+
668
+ ```typescript
669
+ /**
670
+ * {Example Title}
671
+ *
672
+ * Purpose: {What this example demonstrates}
673
+ * Source: Context7 - {Framework} Best Practices
674
+ *
675
+ * Features:
676
+ * - {Feature 1}
677
+ * - {Feature 2}
678
+ * - {Feature 3}
679
+ *
680
+ * Usage:
681
+ * {usage example}
682
+ */
683
+
684
+ {Complete working code from Context7}
685
+
686
+ /**
687
+ * ✅ GOOD Example: {What makes this good}
688
+ */
689
+ {good example code}
690
+
691
+ /**
692
+ * ❌ BAD Example: Common Mistakes to Avoid
693
+ */
694
+ {bad example code with comments explaining why it's bad}
695
+ ```
696
+
697
+ ---
698
+
699
+ ### Framework Detection → Files to Generate
700
+
701
+ **If React detected:**
702
+ - `react-best-practices.md`
703
+ - `examples/use-fetch.tsx`
704
+ - `examples/error-boundary.tsx`
705
+
706
+ **If Next.js detected:**
707
+ - `nextjs-best-practices.md`
708
+ - `examples/server-component.tsx`
709
+ - `examples/route-handler.ts`
710
+
711
+ **If Vue detected:**
712
+ - `vue-best-practices.md`
713
+ - `examples/composable.ts`
714
+
715
+ **If FastAPI detected:**
716
+ - `fastapi-best-practices.md`
717
+ - `examples/endpoint-pattern.py`
718
+
719
+ **If Express detected:**
720
+ - `express-best-practices.md`
721
+ - `examples/middleware-pattern.ts`
722
+
723
+ **If Prisma detected:**
724
+ - `prisma-best-practices.md`
725
+ - `examples/transaction-pattern.ts`
726
+
727
+ **If SQLAlchemy detected:**
728
+ - `sqlalchemy-best-practices.md`
729
+ - `examples/model-pattern.py`
730
+
731
+ **If Tailwind CSS detected:**
732
+ - `tailwind-best-practices.md`
733
+
734
+ ---
735
+
736
+ ### Output to User
737
+
738
+ After generating files:
739
+
740
+ ```
741
+ 📚 Generating framework best practices from Context7...
742
+
743
+ ✅ React Best Practices
744
+ - Queried Context7 for hooks patterns... ✓
745
+ - Generated: react-best-practices.md
746
+ - Generated: examples/use-fetch.tsx
747
+ - Generated: examples/error-boundary.tsx
748
+
749
+ ✅ Next.js Best Practices
750
+ - Queried Context7 for App Router patterns... ✓
751
+ - Generated: nextjs-best-practices.md
752
+ - Generated: examples/server-component.tsx
753
+ - Generated: examples/route-handler.ts
754
+
755
+ ✅ Prisma Best Practices
756
+ - Queried Context7 for schema patterns... ✓
757
+ - Generated: prisma-best-practices.md
758
+ - Generated: examples/transaction-pattern.ts
759
+
760
+ 📁 Framework contexts created:
761
+ - .claude/contexts/frameworks/react-best-practices.md
762
+ - .claude/contexts/frameworks/nextjs-best-practices.md
763
+ - .claude/contexts/frameworks/prisma-best-practices.md
764
+ - .claude/contexts/frameworks/examples/ (5 files)
765
+ ```
766
+
767
+ ---
768
+
769
+ ## Step 4: Create Domain Context Files
770
+
771
+ **CRITICAL: You MUST create files in this exact order for proper indexing!**
772
+
773
+ ### Create Directory Structure
774
+
775
+ ```bash
776
+ mkdir -p .claude/contexts/domain/{project-name}/best-practices
777
+ ```
778
+
779
+ ---
780
+
781
+ ## 📋 Files to Create (in order)
782
+
783
+ ### File 1: `domain/index.md` (🔑 Level 1 Index - Project Registry)
784
+
785
+ **Purpose:** Central registry of all projects. Tells agents which project is current.
786
+
787
+ ```markdown
788
+ # Domain Contexts Registry
789
+
790
+ > **Auto-generated by `/agentsetup`**
791
+ > **Last updated:** {current-date}
792
+
793
+ ---
794
+
795
+ ## 📋 Available Projects
796
+
797
+ | Project | Tech Stack | Location | Last Setup |
798
+ |---------|------------|----------|------------|
799
+ | **{project-name}** | {tech-stack-summary} | [→](./{project-name}/) | {current-date} |
800
+
801
+ ---
802
+
803
+ ## 🎯 Current Working Project
804
+
805
+ **Name:** `{project-name}`
806
+ **Location:** `.claude/contexts/domain/{project-name}/`
807
+
808
+ **Quick Links:**
809
+ - [Tech Stack](./{project-name}/tech-stack.md)
810
+ - [Best Practices](./{project-name}/best-practices/)
811
+ - [Project README](./{project-name}/README.md)
812
+
813
+ ---
814
+
815
+ ## 🔍 For Agents
816
+
817
+ **To discover project context, read this file first!**
818
+
819
+ \`\`\`bash
820
+ # Step 1: Read this file
821
+ Read: .claude/contexts/domain/index.md
822
+
823
+ # Step 2: Extract current project name
824
+ Current project: {project-name}
825
+
826
+ # Step 3: Navigate to project directory
827
+ Path: .claude/contexts/domain/{project-name}/
828
+ \`\`\`
829
+
830
+ ---
831
+
832
+ **⚠️ This file is auto-managed by `/agentsetup`. Do not edit manually.**
833
+ ```
834
+
835
+ **Example values:**
836
+ - `{project-name}`: claude-multi-agent-template
837
+ - `{tech-stack-summary}`: Next.js 15, React 18, Prisma 6
838
+ - `{current-date}`: 2025-10-30
839
+
840
+ ---
841
+
842
+ ### File 2: `domain/{project-name}/README.md` (🔑 Level 2 Index - Project Overview)
843
+
844
+ **Purpose:** Project overview. Tells agents what contexts are available and quick discovery paths.
845
+
846
+ ```markdown
847
+ # {project-name}
848
+
849
+ > **Project Type:** {Greenfield/Brownfield}
850
+ > **Last Setup:** {current-date} (via `/agentsetup`)
851
+
852
+ ---
853
+
854
+ ## 📁 Available Contexts
855
+
856
+ | Context | Description | Location |
857
+ |---------|-------------|----------|
858
+ | **Tech Stack** | Versions, package managers, installation commands | [tech-stack.md](./tech-stack.md) |
859
+ | **Best Practices** | Framework-specific guidelines from Context7 | [best-practices/](./best-practices/) |
860
+
861
+ ---
862
+
863
+ ## 🛠️ Tech Stack Summary
864
+
865
+ **Detected on:** {current-date}
866
+
867
+ | Category | Library | Version | Context7 ID |
868
+ |----------|---------|---------|-------------|
869
+ {tech-stack-table-rows}
870
+
871
+ **Package Manager:** {package-manager}
872
+
873
+ ---
874
+
875
+ ## 📚 Available Best Practices
876
+
877
+ **Location:** [best-practices/](./best-practices/)
878
+
879
+ {best-practices-summary}
880
+
881
+ ---
882
+
883
+ ## 🔍 For Agents
884
+
885
+ ### Quick Discovery:
886
+
887
+ \`\`\`bash
888
+ {agent-reading-guide}
889
+ \`\`\`
890
+
891
+ ### Full discovery flow:
892
+
893
+ \`\`\`bash
894
+ 1. Read: domain/index.md (get current project)
895
+ 2. Read: domain/{project-name}/README.md (this file - get overview)
896
+ 3. Read: domain/{project-name}/best-practices/index.md (get detailed registry)
897
+ 4. Read: domain/{project-name}/best-practices/{relevant-files}
898
+ \`\`\`
899
+
900
+ ---
901
+
902
+ **⚠️ All agents MUST read relevant best practices before writing code!**
903
+ ```
904
+
905
+ **Example values:**
906
+ - `{tech-stack-table-rows}`:
907
+ ```
908
+ | Frontend | Next.js | 15.5.0 | /vercel/next.js |
909
+ | Frontend | React | 18.3.0 | /facebook/react |
910
+ | Database | Prisma | 6.5.0 | /prisma/prisma |
911
+ ```
912
+ - `{best-practices-summary}`:
913
+ ```
914
+ **Frontend:**
915
+ - [React 18](./best-practices/react-18.md) - Hooks, components
916
+ - [Next.js 15](./best-practices/nextjs-15.md) - App Router, Server Components
917
+
918
+ **Database:**
919
+ - [Prisma 6](./best-practices/prisma-6.md) - Schema, queries, transactions
920
+ ```
921
+ - `{agent-reading-guide}`:
922
+ ```
923
+ # If you're a frontend agent (uxui-frontend, frontend):
924
+ Read: ./best-practices/react-18.md
925
+ Read: ./best-practices/nextjs-15.md
926
+
927
+ # If you're a backend agent:
928
+ Read: ./best-practices/prisma-6.md
929
+ ```
930
+
931
+ ---
932
+
933
+ ### File 3: `domain/{project-name}/tech-stack.md`
934
+
935
+ ```markdown
936
+ # Tech Stack - {Project Name}
937
+
938
+ > **Auto-detected on:** {date}
939
+
940
+ ## Stack Overview
941
+
942
+ | Category | Library | Version | Context7 ID |
943
+ |----------|---------|---------|-------------|
944
+ | Frontend | Next.js | 15.5.0 | /vercel/next.js |
945
+ | Database | Prisma | 6.5.0 | /prisma/prisma |
946
+ | State | Zustand | 5.0.0 | /pmndrs/zustand |
947
+ | Testing | Vitest | 2.0.0 | /vitest-dev/vitest |
948
+
949
+ ## Package Manager(s)
950
+
951
+ ### JavaScript/TypeScript
952
+ - **Tool:** pnpm
953
+ - **Version:** 9.x
954
+ - **Detected from:** pnpm-lock.yaml
955
+ - **Install:** `pnpm install`
956
+ - **Add package:** `pnpm add <package>`
957
+ - **Run script:** `pnpm run <script>`
958
+ - **Remove:** `pnpm remove <package>`
959
+
960
+ ### Python (if applicable)
961
+ - **Tool:** uv
962
+ - **Version:** 0.4.x
963
+ - **Detected from:** uv.lock
964
+ - **Install:** `uv pip install -r requirements.txt`
965
+ - **Add package:** `uv pip install <package>`
966
+ - **Run script:** `uv run <script>`
967
+
968
+ ### PHP (if applicable)
969
+ - **Tool:** composer
970
+ - **Install:** `composer install`
971
+ - **Add package:** `composer require <package>`
972
+
973
+ ### Ruby (if applicable)
974
+ - **Tool:** bundler
975
+ - **Install:** `bundle install`
976
+ - **Add gem:** `bundle add <gem>`
977
+
978
+ ## Installation Commands
979
+
980
+ **IMPORTANT:** All agents MUST use the package manager(s) specified above.
981
+
982
+ \`\`\`bash
983
+ # JavaScript/TypeScript (use pnpm as specified)
984
+ pnpm install
985
+ pnpm add <package>
986
+ pnpm run dev
987
+
988
+ # Python (use uv as specified)
989
+ uv pip install -r requirements.txt
990
+ uv pip install <package>
991
+ uv run <script>
992
+
993
+ # Monorepo Example (if multiple ecosystems):
994
+ # Frontend: pnpm install
995
+ # Backend: uv pip install -r requirements.txt
996
+ \`\`\`
997
+
998
+ ## 📚 Best Practices Reference
999
+
1000
+ **IMPORTANT:** Detailed best practices are in separate files for better organization.
1001
+
1002
+ **Location:** `.claude/contexts/domain/{project-name}/best-practices/`
1003
+
1004
+ **Available guides:**
1005
+ - [React 18](./best-practices/react-18.md) - Hooks, components, state management
1006
+ - [Next.js 15](./best-practices/nextjs-15.md) - App Router, Server Components, data fetching
1007
+ - [Prisma 6](./best-practices/prisma-6.md) - Schema design, queries, transactions
1008
+ - [Zustand 5](./best-practices/zustand-5.md) - Store creation, persistence
1009
+ - [Vitest 2](./best-practices/vitest-2.md) - Unit tests, mocks, coverage
1010
+
1011
+ **Registry:** [best-practices/index.md](./best-practices/index.md) (see which agent reads what)
1012
+
1013
+ ---
1014
+
1015
+ **⚠️ All agents MUST read relevant best practices before coding!**
1016
+ ```
1017
+
1018
+ ---
1019
+
1020
+ ### File 4: `domain/{project-name}/best-practices/index.md` (🔑 Level 3 Index - Best Practices Registry)
1021
+
1022
+ **Purpose:** Registry of all best practices files. Tells agents which files to read based on their role.
1023
+
1024
+ ```markdown
1025
+ # Best Practices Registry
1026
+
1027
+ > **Project:** {project-name}
1028
+ > **Generated:** {current-date} via Context7 MCP
1029
+ > **Total files:** {total-count}
1030
+
1031
+ ---
1032
+
1033
+ ## 📋 Available Best Practices
1034
+
1035
+ | Framework | Version | File | For Agents | Last Updated |
1036
+ |-----------|---------|------|------------|--------------|
1037
+ {best-practices-table-rows}
1038
+
1039
+ ---
1040
+
1041
+ ## 🎯 Agent Reading Guide
1042
+
1043
+ ### For `uxui-frontend` agent:
1044
+ **Must read:**
1045
+ {uxui-must-read-list}
1046
+
1047
+ **Optional:**
1048
+ {uxui-optional-list}
1049
+
1050
+ ---
1051
+
1052
+ ### For `frontend` agent:
1053
+ **Must read:**
1054
+ {frontend-must-read-list}
1055
+
1056
+ ---
1057
+
1058
+ ### For `backend` agent:
1059
+ **Must read:**
1060
+ {backend-must-read-list}
1061
+
1062
+ **Optional:**
1063
+ {backend-optional-list}
1064
+
1065
+ ---
1066
+
1067
+ ### For `database` agent:
1068
+ **Must read:**
1069
+ {database-must-read-list}
1070
+
1071
+ ---
1072
+
1073
+ ### For `test-debug` agent:
1074
+ **Must read:**
1075
+ {test-must-read-list}
1076
+
1077
+ **Optional:**
1078
+ {test-optional-list}
1079
+
1080
+ ---
1081
+
1082
+ ## 📊 Content Summary
1083
+
1084
+ {content-summaries-per-file}
1085
+
1086
+ ---
1087
+
1088
+ ## 🔄 Update History
1089
+
1090
+ | Date | Action | Details |
1091
+ |------|--------|---------|
1092
+ | {current-date} | Initial setup | Generated {count} files from Context7 |
1093
+
1094
+ ---
1095
+
1096
+ **⚠️ To update these files, run `/agentsetup` again.**
1097
+ ```
1098
+
1099
+ **Example values:**
1100
+ - `{best-practices-table-rows}`:
1101
+ ```
1102
+ | React | 18.3 | [react-18.md](./react-18.md) | uxui-frontend, frontend | 2025-10-30 |
1103
+ | Next.js | 15.5 | [nextjs-15.md](./nextjs-15.md) | uxui-frontend, frontend | 2025-10-30 |
1104
+ | Prisma | 6.5 | [prisma-6.md](./prisma-6.md) | backend, database | 2025-10-30 |
1105
+ ```
1106
+ - `{uxui-must-read-list}`:
1107
+ ```
1108
+ - ✅ [react-18.md](./react-18.md) - Component patterns, hooks rules
1109
+ - ✅ [nextjs-15.md](./nextjs-15.md) - App Router, Server vs Client Components
1110
+ ```
1111
+ - `{content-summaries-per-file}`:
1112
+ ```
1113
+ ### [react-18.md](./react-18.md)
1114
+ **Topics covered:**
1115
+ - ✅ Hooks rules (must call at top level, deps arrays)
1116
+ - ✅ Custom hooks patterns
1117
+ - ❌ Common anti-patterns (conditional hooks, state mutation)
1118
+
1119
+ **Key sections:**
1120
+ - DO's: 15 best practices
1121
+ - DON'Ts: 10 anti-patterns with code examples
1122
+ - Quick Checklist: 8 items
1123
+ ```
1124
+
1125
+ ---
1126
+
1127
+ ### File 5: `domain/{project-name}/best-practices/{framework}-{version}.md`
1128
+
1129
+ **Purpose:** Actual best practices content from Context7. One file per major framework.
1130
+
1131
+ **Template structure:**
1132
+
1133
+ ```markdown
1134
+ # {Framework} Best Practices
1135
+
1136
+ **Source:** Context7 - {Framework} Documentation
1137
+ **Last Updated:** {current-date}
1138
+ **Version:** {detected-version}
1139
+
1140
+ ---
1141
+
1142
+ ## ✅ DO (Best Practices)
1143
+
1144
+ ### 1. {Best Practice Category}
1145
+ - {Practice 1}
1146
+ - {Practice 2}
1147
+ - {Practice 3}
1148
+
1149
+ ```code
1150
+ // ✅ GOOD - {explanation}
1151
+ {good-example}
1152
+ ```
1153
+
1154
+ ### 2. {Another Category}
1155
+ - {Practice 1}
1156
+ - {Practice 2}
1157
+
1158
+ ---
1159
+
1160
+ ## ❌ DON'T (Anti-Patterns)
1161
+
1162
+ ### 🚫 Critical Mistakes (Check Before Committing):
1163
+
1164
+ - [ ] ❌ **{Anti-pattern 1}**
1165
+ ```code
1166
+ // ❌ BAD - {why it's bad}
1167
+ {bad-example}
1168
+
1169
+ // ✅ GOOD - {why it's good}
1170
+ {good-example}
1171
+ ```
1172
+
1173
+ - [ ] ❌ **{Anti-pattern 2}**
1174
+ ```code
1175
+ // ❌ BAD
1176
+ {bad-example}
1177
+
1178
+ // ✅ GOOD
1179
+ {good-example}
1180
+ ```
1181
+
1182
+ ---
1183
+
1184
+ ## 🔧 Common Mistakes & How to Fix
1185
+
1186
+ ### 1. {Common Mistake Title}
1187
+
1188
+ ```code
1189
+ // ❌ BAD - {description}
1190
+ {bad-code}
1191
+
1192
+ // ✅ GOOD - {description}
1193
+ {good-code}
1194
+ ```
1195
+
1196
+ ### 2. {Another Common Mistake}
1197
+
1198
+ {explanation-and-fix}
1199
+
1200
+ ---
1201
+
1202
+ ## 🎯 Quick Checklist
1203
+
1204
+ Before committing {framework} code:
1205
+
1206
+ **{Category 1}:**
1207
+ - [ ] {check-1}
1208
+ - [ ] {check-2}
1209
+
1210
+ **{Category 2}:**
1211
+ - [ ] {check-1}
1212
+ - [ ] {check-2}
1213
+
1214
+ ---
1215
+
1216
+ **⚠️ All agents MUST read this file before writing {framework} code!**
1217
+ ```
1218
+
1219
+ **Query Context7 for each framework:**
1220
+
1221
+ ```typescript
1222
+ // Example: React
1223
+ mcp__context7__get-library-docs({
1224
+ context7CompatibleLibraryID: "/facebook/react",
1225
+ topic: "hooks best practices, common mistakes, anti-patterns, rules of hooks, custom hooks patterns, component composition",
1226
+ tokens: 8000
1227
+ })
1228
+
1229
+ // Example: Next.js
1230
+ mcp__context7__get-library-docs({
1231
+ context7CompatibleLibraryID: "/vercel/next.js",
1232
+ topic: "App Router best practices, Server Components vs Client Components, common mistakes, data fetching patterns, route handlers",
1233
+ tokens: 8000
1234
+ })
1235
+
1236
+ // Example: Prisma
1237
+ mcp__context7__get-library-docs({
1238
+ context7CompatibleLibraryID: "/prisma/prisma",
1239
+ topic: "schema design patterns, query optimization, transaction handling, common mistakes, N+1 problem, migration best practices",
1240
+ tokens: 8000
1241
+ })
1242
+ ```
1243
+
1244
+ **Format Context7 response into the template above.**
1245
+
1246
+ ---
1247
+
1248
+ ### File 6: architecture.md (Optional)
1249
+
1250
+ Only create if spec has architecture info:
1251
+
1252
+ ```markdown
1253
+ # Architecture - {Project Name}
1254
+
1255
+ ## System Overview
1256
+ {From spec - system diagram, components, data flow}
1257
+
1258
+ ## Database Schema
1259
+ {From spec - ER diagram, table descriptions}
1260
+
1261
+ ## API Endpoints
1262
+ {From spec - REST/GraphQL endpoints}
1263
+
1264
+ ## Key Workflows
1265
+ {From spec - user flows, business processes}
1266
+ ```
1267
+
1268
+ ### File 3: business-rules.md (Optional)
1269
+
1270
+ Only create if spec has business logic:
1271
+
1272
+ ```markdown
1273
+ # Business Rules - {Project Name}
1274
+
1275
+ ## Domain Rules
1276
+ {From spec - validation rules, calculations, constraints}
1277
+
1278
+ ## Invariants
1279
+ {From spec - must-be-true conditions}
1280
+
1281
+ ## Edge Cases
1282
+ {From spec - special handling scenarios}
1283
+ ```
1284
+
1285
+ ### File 4: design-tokens.md (Optional)
1286
+
1287
+ Only create if spec has brand colors:
1288
+
1289
+ ```markdown
1290
+ # Design Tokens - {Project Name}
1291
+
1292
+ ## Brand Colors
1293
+ - Primary: rgb(59, 130, 246) (Blue - Trust)
1294
+ - Secondary: rgb(16, 185, 129) (Green - Success)
1295
+ - Accent: rgb(251, 146, 60) (Orange - Energy)
1296
+
1297
+ ## Usage
1298
+ - Primary: CTA buttons, links
1299
+ - Secondary: Success states
1300
+ - Accent: Highlights, badges
1301
+ ```
1302
+
1303
+ ---
1304
+
1305
+ ## Step 5: Summary Output
1306
+
1307
+ After creating all files, output a summary:
1308
+
1309
+ ```markdown
1310
+ ✅ Agent Setup Complete!
1311
+
1312
+ 📦 Project Type: {Greenfield / Brownfield}
1313
+ 📁 Project Name: {project-name}
1314
+
1315
+ 🛠️ Tech Stack Detected:
1316
+ - Frontend: Next.js 15.5.0
1317
+ - Database: Prisma 6.5.0
1318
+ - State: Zustand 5.0.0
1319
+ - Testing: Vitest 2.0.0
1320
+
1321
+ 📦 Package Manager(s):
1322
+ - JavaScript: pnpm 9.x (detected from pnpm-lock.yaml)
1323
+ - Python: uv 0.4.x (detected from uv.lock) [if applicable]
1324
+
1325
+ 📁 Files Created:
1326
+
1327
+ **Index Files (3-level discovery):**
1328
+ ✓ .claude/contexts/domain/index.md (Level 1 - Project Registry)
1329
+ ✓ .claude/contexts/domain/{project}/README.md (Level 2 - Project Overview)
1330
+ ✓ .claude/contexts/domain/{project}/best-practices/index.md (Level 3 - Best Practices Registry)
1331
+
1332
+ **Context Files:**
1333
+ ✓ .claude/contexts/domain/{project}/tech-stack.md
1334
+ ✓ .claude/contexts/domain/{project}/architecture.md (if applicable)
1335
+ ✓ .claude/contexts/domain/{project}/business-rules.md (if applicable)
1336
+ ✓ .claude/contexts/domain/{project}/design-tokens.md (if applicable)
1337
+
1338
+ **Best Practices (from Context7):**
1339
+ ✓ .claude/contexts/domain/{project}/best-practices/react-18.md (8000 tokens)
1340
+ ✓ .claude/contexts/domain/{project}/best-practices/nextjs-15.md (8000 tokens)
1341
+ ✓ .claude/contexts/domain/{project}/best-practices/prisma-6.md (8000 tokens)
1342
+ ✓ .claude/contexts/domain/{project}/best-practices/zustand-5.md (8000 tokens)
1343
+ ✓ .claude/contexts/domain/{project}/best-practices/vitest-2.md (8000 tokens)
1344
+
1345
+ 📚 Context7 Docs Retrieved: {total-tokens} tokens
1346
+
1347
+ 🚀 Ready to start! Use:
1348
+ - /agents uxui-frontend → Design UI components with mock data
1349
+ - /agents frontend → Connect UI to APIs
1350
+ - /agents backend → Create API endpoints
1351
+ - /agents database → Design schemas
1352
+ - /agents test-debug → Run tests and fix bugs
1353
+
1354
+ 💡 Note: All agents will automatically:
1355
+ - Discover project via domain/index.md
1356
+ - Read relevant best practices before coding
1357
+ - Use detected package manager(s)
1358
+ ```
1359
+
1360
+ ---
1361
+
1362
+ ## Error Handling
1363
+
1364
+ ### If Context7 search fails:
1365
+
1366
+ ```
1367
+ ⚠️ Could not find docs for: {library}
1368
+
1369
+ Fallback options:
1370
+ 1. Use general patterns from .claude/contexts/patterns/
1371
+ 2. Search manually: "Please search for {library} best practices"
1372
+ 3. Skip this library and continue
1373
+ ```
1374
+
1375
+ ### If no stack detected (brownfield):
1376
+
1377
+ ```
1378
+ ⚠️ Could not detect tech stack from project files.
1379
+
1380
+ Switching to Greenfield flow...
1381
+ What tech stack do you want to use?
1382
+ ```
1383
+
1384
+ ---
1385
+
1386
+ ## Important Rules
1387
+
1388
+ 1. **ALWAYS use Context7 MCP** for latest docs (never hardcode docs)
1389
+ 2. **ALWAYS create index files** in order: domain/index.md → {project}/README.md → best-practices/index.md
1390
+ 3. **ALWAYS create tech-stack.md** (mandatory)
1391
+ 4. **ALWAYS generate best practices** files from Context7 for detected frameworks
1392
+ 5. **ALWAYS detect and store package manager(s)** in tech-stack.md
1393
+ 6. **ONLY create architecture/business-rules/design-tokens** if spec provides info
1394
+ 7. **NEVER guess versions** - read from package files or ask user
1395
+ 8. **NEVER hardcode package manager commands** - always read from tech-stack.md
1396
+ 9. **ALWAYS confirm detected stack** with user before proceeding
1397
+ 10. **Store Context7 library IDs** in tech-stack.md for future reference
1398
+ 11. **Format best practices** with ✅ DO's, ❌ DON'Ts, and 🎯 Quick Checklist sections
1399
+
1400
+ ### Critical: Package Manager Usage
1401
+
1402
+ **All agents (backend, frontend, database, test-debug) MUST:**
1403
+ 1. Read `.claude/contexts/domain/{project}/tech-stack.md` BEFORE running any install/run commands
1404
+ 2. Use the package manager specified in tech-stack.md
1405
+ 3. Never assume npm/pip - always check tech-stack.md first
1406
+
1407
+ **Example:**
1408
+ ```
1409
+ Agent reads tech-stack.md:
1410
+ - Package Manager: pnpm
1411
+
1412
+ Agent runs:
1413
+ ✅ pnpm add fastapi (correct)
1414
+ ❌ npm install fastapi (wrong - ignored tech-stack.md!)
1415
+ ```
1416
+
1417
+ **For monorepo projects:**
1418
+ ```
1419
+ Agent reads tech-stack.md:
1420
+ - JavaScript: pnpm
1421
+ - Python: uv
1422
+
1423
+ Agent working on backend (Python):
1424
+ ✅ uv pip install fastapi (correct - uses Python package manager)
1425
+ ❌ pnpm add fastapi (wrong - fastapi is Python, not JS!)
1426
+ ```
1427
+
1428
+ ---
1429
+
1430
+ ## Example Full Flow (Brownfield - Next.js)
1431
+
1432
+ ```
1433
+ 1. User runs: /agentsetup
1434
+
1435
+ 2. Read package.json:
1436
+ {
1437
+ "dependencies": {
1438
+ "next": "15.5.0",
1439
+ "@prisma/client": "6.5.0"
1440
+ }
1441
+ }
1442
+
1443
+ 3. Output:
1444
+ 🔍 Detected: Next.js 15.5.0, Prisma 6.5.0
1445
+ Is this correct? (yes/no)
1446
+
1447
+ 4. User: yes
1448
+
1449
+ 5. Search Context7:
1450
+ - resolve-library-id("Next.js") → "/vercel/next.js"
1451
+ - get-library-docs("/vercel/next.js/v15.5.0", "App Router")
1452
+ - resolve-library-id("Prisma") → "/prisma/prisma"
1453
+ - get-library-docs("/prisma/prisma/v6.5.0", "Client API")
1454
+
1455
+ 6. Create files:
1456
+ - .claude/contexts/domain/myproject/tech-stack.md
1457
+
1458
+ 7. Output summary:
1459
+ ✅ Setup complete! Ready to build.
1460
+ ```
1461
+
1462
+ ---
1463
+
1464
+ **Now execute this workflow!**