cc-devflow 1.0.1

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 (277) hide show
  1. package/.claude/CLAUDE.md +83 -0
  2. package/.claude/agents/architecture-designer.md +443 -0
  3. package/.claude/agents/bug-analyzer.md +382 -0
  4. package/.claude/agents/checklist-agent.md +175 -0
  5. package/.claude/agents/clarify-analyst.md +50 -0
  6. package/.claude/agents/code-reviewer.md +71 -0
  7. package/.claude/agents/codex-analyzer.md +39 -0
  8. package/.claude/agents/compatibility-checker.md +580 -0
  9. package/.claude/agents/consistency-checker.md +532 -0
  10. package/.claude/agents/impact-analyzer.md +441 -0
  11. package/.claude/agents/planner.md +230 -0
  12. package/.claude/agents/prd-writer.md +320 -0
  13. package/.claude/agents/project-guidelines-generator.md +1329 -0
  14. package/.claude/agents/qa-tester.md +313 -0
  15. package/.claude/agents/release-manager.md +295 -0
  16. package/.claude/agents/security-reviewer.md +314 -0
  17. package/.claude/agents/style-guide-generator.md +458 -0
  18. package/.claude/agents/tech-architect.md +516 -0
  19. package/.claude/agents/ui-designer.md +485 -0
  20. package/.claude/commands/code-review-high.md +58 -0
  21. package/.claude/commands/core-architecture.md +429 -0
  22. package/.claude/commands/core-guidelines.md +486 -0
  23. package/.claude/commands/core-roadmap.md +439 -0
  24. package/.claude/commands/core-style.md +293 -0
  25. package/.claude/commands/flow-archive.md +245 -0
  26. package/.claude/commands/flow-checklist.md +260 -0
  27. package/.claude/commands/flow-clarify.md +136 -0
  28. package/.claude/commands/flow-constitution.md +82 -0
  29. package/.claude/commands/flow-dev.md +134 -0
  30. package/.claude/commands/flow-epic.md +150 -0
  31. package/.claude/commands/flow-fix.md +104 -0
  32. package/.claude/commands/flow-ideate.md +214 -0
  33. package/.claude/commands/flow-init.md +313 -0
  34. package/.claude/commands/flow-new.md +394 -0
  35. package/.claude/commands/flow-prd.md +131 -0
  36. package/.claude/commands/flow-qa.md +93 -0
  37. package/.claude/commands/flow-release.md +92 -0
  38. package/.claude/commands/flow-restart.md +98 -0
  39. package/.claude/commands/flow-status.md +64 -0
  40. package/.claude/commands/flow-tech.md +142 -0
  41. package/.claude/commands/flow-ui.md +189 -0
  42. package/.claude/commands/flow-update.md +111 -0
  43. package/.claude/commands/flow-upgrade.md +115 -0
  44. package/.claude/commands/flow-verify.md +96 -0
  45. package/.claude/commands/problem-analyzer.md +60 -0
  46. package/.claude/config/quality-rules.yml +161 -0
  47. package/.claude/docs/SPEC_KIT_CONSTITUTION_ANALYSIS.md +426 -0
  48. package/.claude/docs/design/consistency-conflict-detection-algorithms.md +658 -0
  49. package/.claude/docs/design/intent-driven-input-design.md +380 -0
  50. package/.claude/docs/design/prd-version-management-design.md +437 -0
  51. package/.claude/docs/guides/INIT_TROUBLESHOOTING.md +117 -0
  52. package/.claude/docs/guides/NEW_TROUBLESHOOTING.md +151 -0
  53. package/.claude/docs/guides/ROADMAP_TROUBLESHOOTING.md +188 -0
  54. package/.claude/docs/guides/TASK_COMPLETION_MARKING.md +338 -0
  55. package/.claude/docs/templates/ARCHITECTURE_TEMPLATE.md +633 -0
  56. package/.claude/docs/templates/BACKLOG_TEMPLATE.md +261 -0
  57. package/.claude/docs/templates/CHECKLIST_TEMPLATE.md +52 -0
  58. package/.claude/docs/templates/CLARIFICATION_REPORT_TEMPLATE.md +206 -0
  59. package/.claude/docs/templates/CODE_REVIEW_TEMPLATE.md +71 -0
  60. package/.claude/docs/templates/EPIC_TEMPLATE.md +805 -0
  61. package/.claude/docs/templates/INIT_FLOW_TEMPLATE.md +213 -0
  62. package/.claude/docs/templates/INTENT_CLARIFICATION_TEMPLATE.md +57 -0
  63. package/.claude/docs/templates/NEW_ORCHESTRATION_TEMPLATE.md +148 -0
  64. package/.claude/docs/templates/PRD_TEMPLATE.md +562 -0
  65. package/.claude/docs/templates/RESEARCH_TEMPLATE.md +276 -0
  66. package/.claude/docs/templates/REVIEW-HIGH.md +57 -0
  67. package/.claude/docs/templates/ROADMAP_DIALOGUE_TEMPLATE.md +198 -0
  68. package/.claude/docs/templates/ROADMAP_TEMPLATE.md +310 -0
  69. package/.claude/docs/templates/STYLE_TEMPLATE.md +1266 -0
  70. package/.claude/docs/templates/TASKS_TEMPLATE.md +523 -0
  71. package/.claude/docs/templates/TECH_DESIGN_TEMPLATE.md +1019 -0
  72. package/.claude/docs/templates/UI_PROTOTYPE_TEMPLATE.md +1436 -0
  73. package/.claude/guides/agent-guides/agent-coordination-guide.md +459 -0
  74. package/.claude/guides/project-guidelines-system.md +463 -0
  75. package/.claude/guides/technical-guides/datetime-handling-guide.md +563 -0
  76. package/.claude/guides/technical-guides/git-github-guide.md +642 -0
  77. package/.claude/guides/technical-guides/test-execution-guide.md +618 -0
  78. package/.claude/guides/workflow-guides/bug-fix-orchestrator.md +217 -0
  79. package/.claude/guides/workflow-guides/flow-orchestrator.md +282 -0
  80. package/.claude/hooks/checklist-gate.js +397 -0
  81. package/.claude/hooks/error-handling-reminder.sh +12 -0
  82. package/.claude/hooks/error-handling-reminder.ts +459 -0
  83. package/.claude/hooks/post-tool-use-tracker.sh +280 -0
  84. package/.claude/hooks/pre-tool-use-guardrail.sh +36 -0
  85. package/.claude/hooks/pre-tool-use-guardrail.ts +342 -0
  86. package/.claude/hooks/skill-activation-prompt.sh +36 -0
  87. package/.claude/hooks/skill-activation-prompt.ts +214 -0
  88. package/.claude/hooks/state/skills-used-test-guard.json +3 -0
  89. package/.claude/rules/devflow-conventions.md +305 -0
  90. package/.claude/rules/project-constitution.md +748 -0
  91. package/.claude/schemas/constitution.schema.json +43 -0
  92. package/.claude/scripts/analyze-upgrade-impact.sh +200 -0
  93. package/.claude/scripts/archive-requirement.sh +351 -0
  94. package/.claude/scripts/calculate-checklist-completion.sh +243 -0
  95. package/.claude/scripts/calculate-quarter.sh +206 -0
  96. package/.claude/scripts/check-dependencies.sh +409 -0
  97. package/.claude/scripts/check-prerequisites.sh +232 -0
  98. package/.claude/scripts/check-task-status.sh +264 -0
  99. package/.claude/scripts/checklist-errors.sh +131 -0
  100. package/.claude/scripts/common.sh +570 -0
  101. package/.claude/scripts/consolidate-research.sh +182 -0
  102. package/.claude/scripts/create-requirement.sh +426 -0
  103. package/.claude/scripts/export-contracts.sh +117 -0
  104. package/.claude/scripts/extract-data-model.sh +78 -0
  105. package/.claude/scripts/generate-clarification-questions.sh +377 -0
  106. package/.claude/scripts/generate-clarification-report.sh +463 -0
  107. package/.claude/scripts/generate-quickstart.sh +146 -0
  108. package/.claude/scripts/generate-research-tasks.sh +157 -0
  109. package/.claude/scripts/generate-status-report.sh +523 -0
  110. package/.claude/scripts/generate-tech-analysis.sh +46 -0
  111. package/.claude/scripts/locate-requirement-in-roadmap.sh +233 -0
  112. package/.claude/scripts/manage-constitution.sh +602 -0
  113. package/.claude/scripts/mark-task-complete.sh +198 -0
  114. package/.claude/scripts/populate-research-tasks.sh +259 -0
  115. package/.claude/scripts/recover-workflow.sh +460 -0
  116. package/.claude/scripts/run-clarify-scan.sh +601 -0
  117. package/.claude/scripts/run-high-review.sh +62 -0
  118. package/.claude/scripts/run-problem-analysis.sh +68 -0
  119. package/.claude/scripts/setup-epic.sh +173 -0
  120. package/.claude/scripts/sync-roadmap-progress.sh +300 -0
  121. package/.claude/scripts/sync-task-marks.sh +199 -0
  122. package/.claude/scripts/test-clarify-scan.sh +515 -0
  123. package/.claude/scripts/update-agent-context.sh +806 -0
  124. package/.claude/scripts/validate-constitution.sh +567 -0
  125. package/.claude/scripts/validate-hooks.sh +487 -0
  126. package/.claude/scripts/validate-research.sh +332 -0
  127. package/.claude/scripts/validate-scope-boundary.sh +493 -0
  128. package/.claude/scripts/verify-setup.sh +37 -0
  129. package/.claude/settings.json +76 -0
  130. package/.claude/skills/_reference-implementations/README.md +96 -0
  131. package/.claude/skills/_reference-implementations/backend-express-prisma/SKILL.md +302 -0
  132. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/architecture-overview.md +451 -0
  133. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/async-and-errors.md +307 -0
  134. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/complete-examples.md +638 -0
  135. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/configuration.md +275 -0
  136. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/database-patterns.md +224 -0
  137. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/middleware-guide.md +213 -0
  138. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/routing-and-controllers.md +756 -0
  139. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/sentry-and-monitoring.md +336 -0
  140. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/services-and-repositories.md +789 -0
  141. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/testing-guide.md +235 -0
  142. package/.claude/skills/_reference-implementations/backend-express-prisma/resources/validation-patterns.md +754 -0
  143. package/.claude/skills/_reference-implementations/frontend-react-mui/SKILL.md +399 -0
  144. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/common-patterns.md +331 -0
  145. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/complete-examples.md +872 -0
  146. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/component-patterns.md +502 -0
  147. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/data-fetching.md +767 -0
  148. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/file-organization.md +502 -0
  149. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/loading-and-error-states.md +501 -0
  150. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/performance.md +406 -0
  151. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/routing-guide.md +364 -0
  152. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/styling-guide.md +428 -0
  153. package/.claude/skills/_reference-implementations/frontend-react-mui/resources/typescript-standards.md +418 -0
  154. package/.claude/skills/cc-devflow-orchestrator/SKILL.md +229 -0
  155. package/.claude/skills/constitution-guardian/SKILL.md +306 -0
  156. package/.claude/skills/devflow-constitution-quick-ref/SKILL.md +374 -0
  157. package/.claude/skills/devflow-file-standards/SKILL.md +353 -0
  158. package/.claude/skills/devflow-tdd-enforcer/SKILL.md +192 -0
  159. package/.claude/skills/skill-developer/ADVANCED.md +197 -0
  160. package/.claude/skills/skill-developer/HOOK_MECHANISMS.md +306 -0
  161. package/.claude/skills/skill-developer/PATTERNS_LIBRARY.md +152 -0
  162. package/.claude/skills/skill-developer/SKILL.md +426 -0
  163. package/.claude/skills/skill-developer/SKILL_RULES_REFERENCE.md +315 -0
  164. package/.claude/skills/skill-developer/TRIGGER_TYPES.md +305 -0
  165. package/.claude/skills/skill-developer/TROUBLESHOOTING.md +514 -0
  166. package/.claude/skills/skill-rules.json +213 -0
  167. package/.claude/tests/README.md +300 -0
  168. package/.claude/tests/TODO.md +69 -0
  169. package/.claude/tests/__pycache__/test_analyze_upgrade_impact.cpython-311-pytest-7.2.2.pyc +0 -0
  170. package/.claude/tests/__pycache__/test_consolidate_research.cpython-311-pytest-7.2.2.pyc +0 -0
  171. package/.claude/tests/__pycache__/test_export_contracts.cpython-311-pytest-7.2.2.pyc +0 -0
  172. package/.claude/tests/__pycache__/test_extract_data_model.cpython-311-pytest-7.2.2.pyc +0 -0
  173. package/.claude/tests/__pycache__/test_generate_quickstart.cpython-311-pytest-7.2.2.pyc +0 -0
  174. package/.claude/tests/__pycache__/test_generate_research_tasks.cpython-311-pytest-7.2.2.pyc +0 -0
  175. package/.claude/tests/constitution/run_all_constitution_tests.sh +111 -0
  176. package/.claude/tests/constitution/test_agent_assignment.sh +207 -0
  177. package/.claude/tests/constitution/test_article_coverage.sh +201 -0
  178. package/.claude/tests/constitution/test_template_completeness.sh +150 -0
  179. package/.claude/tests/constitution/test_version_consistency.sh +120 -0
  180. package/.claude/tests/fixtures/spec_delta_full.md +16 -0
  181. package/.claude/tests/fixtures/tasks_progress_sample.md +5 -0
  182. package/.claude/tests/run-all-tests.sh +229 -0
  183. package/.claude/tests/scripts/run.sh +30 -0
  184. package/.claude/tests/scripts/test-framework.sh +128 -0
  185. package/.claude/tests/scripts/test_check_prerequisites.sh +511 -0
  186. package/.claude/tests/scripts/test_check_prerequisites.sh.bak +504 -0
  187. package/.claude/tests/scripts/test_check_prerequisites.sh.bak2 +505 -0
  188. package/.claude/tests/scripts/test_check_prerequisites.sh.bak3 +506 -0
  189. package/.claude/tests/scripts/test_check_prerequisites.sh.bak4 +507 -0
  190. package/.claude/tests/scripts/test_check_prerequisites.sh.bak5 +508 -0
  191. package/.claude/tests/scripts/test_check_task_status.sh +499 -0
  192. package/.claude/tests/scripts/test_common.sh +244 -0
  193. package/.claude/tests/scripts/test_generate_status_report.sh +71 -0
  194. package/.claude/tests/scripts/test_mark_task_complete.sh +441 -0
  195. package/.claude/tests/scripts/test_mark_task_complete.sh.backup +410 -0
  196. package/.claude/tests/scripts/test_recover_workflow.sh +304 -0
  197. package/.claude/tests/scripts/test_setup_epic.sh +437 -0
  198. package/.claude/tests/scripts/test_sync_task_marks.sh +196 -0
  199. package/.claude/tests/scripts/test_validate_constitution.sh +74 -0
  200. package/.claude/tests/scripts/test_validate_research.sh +462 -0
  201. package/.claude/tests/slugify.bats +82 -0
  202. package/.claude/tests/test-framework.sh +732 -0
  203. package/.claude/tests/test_analyze_upgrade_impact.py +34 -0
  204. package/.claude/tests/test_consolidate_research.py +48 -0
  205. package/.claude/tests/test_export_contracts.py +43 -0
  206. package/.claude/tests/test_extract_data_model.py +33 -0
  207. package/.claude/tests/test_generate_quickstart.py +50 -0
  208. package/.claude/tests/test_generate_research_tasks.py +52 -0
  209. package/.claude/tsc-cache/6e64f818-6398-49ca-8623-581a9af85c44/edited-files.log +1 -0
  210. package/.claude/tsc-cache/795ba6e3-b98a-423b-bab2-51aa62812569/affected-repos.txt +1 -0
  211. package/.claude/tsc-cache/795ba6e3-b98a-423b-bab2-51aa62812569/edited-files.log +1 -0
  212. package/.claude/tsc-cache/ae335694-be5a-4ba4-a1a0-b676c09a7906/affected-repos.txt +1 -0
  213. package/.claude/tsc-cache/ae335694-be5a-4ba4-a1a0-b676c09a7906/edited-files.log +1 -0
  214. package/CHANGELOG.md +507 -0
  215. package/LICENSE +21 -0
  216. package/README.md +534 -0
  217. package/README.zh-CN.md +530 -0
  218. package/bin/adapt.js +240 -0
  219. package/bin/cc-devflow-cli.js +185 -0
  220. package/bin/cc-devflow.js +78 -0
  221. package/config/adapters.yml +5 -0
  222. package/config/schema/adapters.schema.json +44 -0
  223. package/docs/CLAUDE.md +26 -0
  224. package/docs/commands/README.md +61 -0
  225. package/docs/commands/README.zh-CN.md +55 -0
  226. package/docs/commands/core-roadmap.md +106 -0
  227. package/docs/commands/core-roadmap.zh-CN.md +102 -0
  228. package/docs/commands/core-style.md +405 -0
  229. package/docs/commands/core-style.zh-CN.md +405 -0
  230. package/docs/commands/flow-init.md +134 -0
  231. package/docs/commands/flow-init.zh-CN.md +163 -0
  232. package/docs/commands/flow-new.md +274 -0
  233. package/docs/commands/flow-new.zh-CN.md +270 -0
  234. package/docs/guides/getting-started.md +204 -0
  235. package/docs/guides/getting-started.zh-CN.md +152 -0
  236. package/lib/adapters/adapter-interface.js +57 -0
  237. package/lib/adapters/claude-adapter.js +74 -0
  238. package/lib/adapters/codex-adapter.js +40 -0
  239. package/lib/adapters/config-validator.js +68 -0
  240. package/lib/adapters/logger.js +42 -0
  241. package/lib/adapters/registry.js +153 -0
  242. package/lib/compiler/CLAUDE.md +92 -0
  243. package/lib/compiler/__tests__/drift.test.js +215 -0
  244. package/lib/compiler/__tests__/errors.test.js +184 -0
  245. package/lib/compiler/__tests__/incremental.test.js +174 -0
  246. package/lib/compiler/__tests__/integration.test.js +174 -0
  247. package/lib/compiler/__tests__/manifest.test.js +233 -0
  248. package/lib/compiler/__tests__/parser.test.js +456 -0
  249. package/lib/compiler/__tests__/schemas.test.js +301 -0
  250. package/lib/compiler/__tests__/skills-registry.test.js +125 -0
  251. package/lib/compiler/__tests__/transformer.test.js +286 -0
  252. package/lib/compiler/emitters/antigravity-emitter.js +171 -0
  253. package/lib/compiler/emitters/base-emitter.js +73 -0
  254. package/lib/compiler/emitters/codex-emitter.js +52 -0
  255. package/lib/compiler/emitters/cursor-emitter.js +31 -0
  256. package/lib/compiler/emitters/index.js +50 -0
  257. package/lib/compiler/emitters/qwen-emitter.js +39 -0
  258. package/lib/compiler/errors.js +119 -0
  259. package/lib/compiler/index.js +256 -0
  260. package/lib/compiler/manifest.js +242 -0
  261. package/lib/compiler/parser.js +258 -0
  262. package/lib/compiler/platforms.js +113 -0
  263. package/lib/compiler/resource-copier.js +320 -0
  264. package/lib/compiler/rules-emitters/__tests__/antigravity-rules-emitter.test.js +191 -0
  265. package/lib/compiler/rules-emitters/__tests__/codex-rules-emitter.test.js +109 -0
  266. package/lib/compiler/rules-emitters/__tests__/cursor-rules-emitter.test.js +123 -0
  267. package/lib/compiler/rules-emitters/__tests__/qwen-rules-emitter.test.js +123 -0
  268. package/lib/compiler/rules-emitters/antigravity-rules-emitter.js +253 -0
  269. package/lib/compiler/rules-emitters/base-rules-emitter.js +83 -0
  270. package/lib/compiler/rules-emitters/codex-rules-emitter.js +116 -0
  271. package/lib/compiler/rules-emitters/cursor-rules-emitter.js +98 -0
  272. package/lib/compiler/rules-emitters/index.js +71 -0
  273. package/lib/compiler/rules-emitters/qwen-rules-emitter.js +70 -0
  274. package/lib/compiler/schemas.js +144 -0
  275. package/lib/compiler/skills-registry.js +225 -0
  276. package/lib/compiler/transformer.js +236 -0
  277. package/package.json +50 -0
@@ -0,0 +1,1019 @@
1
+ # TECH_DESIGN_TEMPLATE.md
2
+
3
+ **Purpose**: Self-executable template for generating comprehensive technical design documents that ensure complete task breakdown in EPIC/TASKS phase.
4
+
5
+ **Usage**: tech-architect agent MUST follow the Execution Flow below step-by-step to generate TECH_DESIGN.md.
6
+
7
+ ---
8
+
9
+ ## Execution Flow
10
+
11
+ ### Step 1: Load Context and Prerequisites
12
+
13
+ ```yaml
14
+ Inputs Required:
15
+ - CLAUDE.md: Tech stack baseline (ANTI-TECH-CREEP enforcement)
16
+ - PRD.md: Functional requirements, user stories, acceptance criteria
17
+ - UI_PROTOTYPE.html: (Optional) UI design if exists
18
+ - Codebase Analysis: Existing patterns, technologies, reusable components
19
+ - orchestration_status.json: Current requirement status
20
+
21
+ Actions:
22
+ 1. Run: .claude/scripts/check-prerequisites.sh --json --paths-only
23
+ 2. Parse: REQ_ID, REQ_DIR, PRD_FILE paths
24
+ 3. **Load Tech Stack Baseline (CRITICAL)**:
25
+ - Read: CLAUDE.md → "## Technical Architecture" section
26
+ - Extract: Frontend, Backend, Database, ORM, Key libraries (with versions)
27
+ - Store as BASELINE_TECH_STACK for later validation
28
+ - Example baseline:
29
+ ```
30
+ Frontend: React 18 with TypeScript 5.0
31
+ Backend: Express 4.18 with TypeScript
32
+ Database: PostgreSQL 15
33
+ ORM: Prisma 5.0
34
+ Authentication: JWT with bcrypt
35
+ Validation: Zod 3.22
36
+ Testing: Jest 29 with supertest
37
+ ```
38
+ - If section missing: ERROR "CLAUDE.md missing tech architecture (Stage 0 should have updated it)"
39
+ 4. Read: PRD.md content
40
+ 5. Read: research/codebase-analysis.md (if exists)
41
+ 6. Read: UI_PROTOTYPE.html summary (if exists)
42
+ 7. Extract: Functional requirements from PRD
43
+ 8. Extract: Non-functional requirements (performance, security, scalability)
44
+
45
+ Validation:
46
+ - PRD.md exists and is complete (no {{PLACEHOLDER}})
47
+ - Functional requirements are clear
48
+ - User stories have acceptance criteria
49
+ ```
50
+
51
+ ### Step 2: Analyze Existing Codebase Patterns
52
+
53
+ ```yaml
54
+ Purpose: Understand existing technical stack and reusable components
55
+
56
+ Actions:
57
+ 1. Identify project type:
58
+ - Search: package.json (Node.js)
59
+ - Search: go.mod (Go)
60
+ - Search: pom.xml (Java)
61
+ - Search: requirements.txt, pyproject.toml (Python)
62
+
63
+ 2. Analyze existing data models:
64
+ - Grep: "class.*Model", "interface.*Entity", "type.*Schema"
65
+ - Locations: models/, entities/, schemas/, database/
66
+ - Extract: Naming patterns, ORM usage
67
+
68
+ 3. Analyze existing API patterns:
69
+ - Grep: "router\.", "app\.(get|post)", "@(Get|Post|Put|Delete)"
70
+ - Locations: routes/, controllers/, handlers/, api/
71
+ - Extract: REST/GraphQL conventions, middleware patterns
72
+
73
+ 4. Analyze existing security:
74
+ - Grep: "authenticate", "authorize", "jwt", "oauth"
75
+ - Locations: auth/, middleware/, security/
76
+ - Extract: Auth strategy, secret management
77
+
78
+ 5. Analyze existing database:
79
+ - Grep: "createConnection", "mongoose", "prisma", "typeorm"
80
+ - Locations: database/, db/, config/
81
+ - Extract: Database type, ORM, migration strategy
82
+
83
+ Output:
84
+ - Codebase Patterns Summary (for Section 1.4 and reuse in design)
85
+ ```
86
+
87
+ ### Step 3: Design System Architecture
88
+
89
+ ```yaml
90
+ Purpose: Define high-level system architecture and module breakdown
91
+
92
+ Actions:
93
+ 1. Define architecture layers:
94
+ - Frontend: User interface layer (if applicable)
95
+ - API Gateway: Request routing and middleware
96
+ - Business Logic: Core services
97
+ - Data Layer: Database and cache
98
+ - External Services: Third-party integrations
99
+
100
+ 2. Create architecture diagram (text-based):
101
+ Example:
102
+ ```
103
+ [Frontend] <--HTTPS--> [API Gateway] <---> [Service A]
104
+ | |
105
+ v v
106
+ [Service B] [Database]
107
+ |
108
+ v
109
+ [Cache]
110
+ ```
111
+
112
+ 3. Define module breakdown:
113
+ - List all modules/services
114
+ - Define responsibility for each
115
+ - Identify dependencies between modules
116
+
117
+ 4. Define data flow:
118
+ - User Request → Frontend → API → Service → Database
119
+ - Include error handling flow
120
+ - Include authentication flow
121
+
122
+ Output:
123
+ - Section 1: System Architecture (Overview, Modules, Data Flow)
124
+
125
+ Validation:
126
+ - ≤3 major modules (Constitution Article VII: Simplicity Gate)
127
+ - Clear separation of concerns
128
+ - No circular dependencies
129
+ ```
130
+
131
+ ### Step 4: Select Technologies with Justification (ENFORCE BASELINE)
132
+
133
+ ```yaml
134
+ Purpose: Choose specific technologies for each layer with clear reasoning
135
+ CRITICAL: Use BASELINE_TECH_STACK from Step 1 (ANTI-TECH-CREEP enforcement)
136
+
137
+ Actions:
138
+ 0. **Load Baseline Constraints**:
139
+ - Retrieve: BASELINE_TECH_STACK from Step 1
140
+ - Default Policy: Use baseline tech stack for all layers
141
+ - Deviation Policy: Only add new tech if PRD explicitly requires it
142
+ - Rejection Examples:
143
+ * ❌ "Replace Express with NestJS" (unnecessary refactoring)
144
+ * ❌ "Add GraphQL" (PRD doesn't require it, YAGNI)
145
+ * ❌ "Switch from Prisma to TypeORM" (no justification)
146
+ - Approval Examples:
147
+ * ✅ "Add Redis for caching" (PRD requires <500ms API response)
148
+ * ✅ "Add Zod for validation" (already in baseline, reuse)
149
+
150
+ 1. Frontend technology selection (if applicable):
151
+ - **ENFORCE BASELINE**: Use baseline frontend framework from CLAUDE.md
152
+ - Framework: ${BASELINE.frontend} (e.g., React 18 with TypeScript 5.0)
153
+ * Justification: "Using existing ${BASELINE.frontend} from CLAUDE.md baseline"
154
+ - State Management: ${BASELINE.state_mgmt or "lightweight option"}
155
+ * If not in baseline: Justify why needed for PRD requirements
156
+ - UI Library: ${BASELINE.ui_library or "framework defaults"}
157
+ * Only add if PRD requires specific UI components
158
+ - Build Tool: ${BASELINE.build_tool or "framework defaults"}
159
+ * Use existing tooling
160
+
161
+ 2. Backend technology selection:
162
+ - **ENFORCE BASELINE**: Use baseline backend framework from CLAUDE.md
163
+ - Framework: ${BASELINE.backend} (e.g., Express 4.18 with TypeScript)
164
+ * Justification: "Using existing ${BASELINE.backend} from CLAUDE.md baseline"
165
+ - ORM: ${BASELINE.orm} (e.g., Prisma 5.0)
166
+ * Justification: "Using existing ${BASELINE.orm} from CLAUDE.md baseline"
167
+ - Validation: ${BASELINE.validation} (e.g., Zod 3.22)
168
+ * Justification: "Using existing ${BASELINE.validation} from CLAUDE.md baseline"
169
+ - If new library needed:
170
+ * Justification format: "Adding ${lib} because ${prd_requirement} requires ${capability}"
171
+ * Example: "Adding express-rate-limit because PRD requires protection against brute-force attacks"
172
+
173
+ 3. Database selection:
174
+ - **ENFORCE BASELINE**: Use baseline database from CLAUDE.md
175
+ - Primary DB: ${BASELINE.database} (e.g., PostgreSQL 15)
176
+ * Justification: "Using existing ${BASELINE.database} from CLAUDE.md baseline"
177
+ - Cache: ${BASELINE.cache or "Add if needed"}
178
+ * If not in baseline: Justify with PRD performance requirements
179
+ * Example: "Adding Redis 7.0 because PRD requires <500ms API response time"
180
+
181
+ 4. Infrastructure selection:
182
+ - **ENFORCE BASELINE**: Use existing deployment approach
183
+ - Deployment: ${BASELINE.deployment or "Docker + Docker Compose"}
184
+ * Justification: "Using existing deployment approach"
185
+ - CI/CD: ${BASELINE.cicd or "GitHub Actions"}
186
+ * Justification: "Using existing CI/CD pipeline"
187
+ - Hosting: ${BASELINE.hosting or "[TBD based on requirements]"}
188
+
189
+ 5. **Deviation Tracking**:
190
+ - Compare selected tech stack with BASELINE_TECH_STACK
191
+ - Document all deviations in a "Deviation from Baseline" list
192
+ - Format: `| New Technology | PRD Requirement | Justification | Approved? |`
193
+ - Example: `| Redis Cache | <500ms API response | High-frequency reads require caching | YES |`
194
+
195
+ Output:
196
+ - Section 2: Technology Stack (Frontend, Backend, Database, Infrastructure)
197
+ - Each technology with version number and justification
198
+ - **NEW**: "Deviation from Baseline" subsection (if any deviations)
199
+
200
+ Validation:
201
+ - **Baseline Adherence**: All baseline technologies reused (no replacements)
202
+ - All technologies are specific with versions (no "modern framework")
203
+ - Direct framework usage (Constitution Article VIII: Anti-Abstraction Gate)
204
+ - All deviations explicitly justified with PRD requirements
205
+ - No over-engineering (Constitution Article II)
206
+ ```
207
+
208
+ ### Step 5: Define Data Models and Relationships
209
+
210
+ ```yaml
211
+ Purpose: Design complete database schema with all tables, fields, and relationships
212
+
213
+ Actions:
214
+ 1. Extract data entities from PRD user stories:
215
+ - Identify nouns in user stories (User, Order, Product, etc.)
216
+ - Map to database tables
217
+
218
+ 2. Define table schemas:
219
+ For each table:
220
+ - Table name (plural, snake_case)
221
+ - Columns:
222
+ * Column name (snake_case)
223
+ * Data type (UUID, VARCHAR, INTEGER, TIMESTAMP, etc.)
224
+ * Constraints (PRIMARY KEY, UNIQUE, NOT NULL, FOREIGN KEY)
225
+ * Description
226
+ - Primary key
227
+ - Foreign keys
228
+
229
+ 3. Define entity relationships:
230
+ - One-to-One (1:1)
231
+ - One-to-Many (1:N)
232
+ - Many-to-Many (M:N) with junction tables
233
+ - Example: User 1:N Orders, Order N:M Products (through order_items)
234
+
235
+ 4. Define indexes for performance:
236
+ - Unique indexes for unique constraints
237
+ - Indexes on frequently queried fields
238
+ - Composite indexes for multi-column queries
239
+ - Example: users(email), orders(user_id, created_at)
240
+
241
+ 5. Define constraints:
242
+ - Foreign key constraints with ON DELETE/UPDATE actions
243
+ - Check constraints (if needed)
244
+ - Default values
245
+
246
+ Output:
247
+ - Section 3: Data Model Design
248
+ - 3.1: Database Schema (all tables with columns)
249
+ - 3.2: Entity Relationships (visual text representation)
250
+ - 3.3: Indexes and Constraints
251
+
252
+ Validation:
253
+ - All entities from PRD are represented
254
+ - All tables have primary keys
255
+ - All foreign keys are defined
256
+ - Indexes on frequently queried fields
257
+ - No redundant data (normalized to 3NF unless justified)
258
+ ```
259
+
260
+ ### Step 6: Design API Contracts
261
+
262
+ ```yaml
263
+ Purpose: Define all API endpoints with request/response schemas BEFORE implementation
264
+
265
+ Actions:
266
+ 1. Extract API requirements from PRD:
267
+ - Identify all user actions (register, login, create order, etc.)
268
+ - Map to CRUD operations
269
+
270
+ 2. Define API endpoints:
271
+ For each endpoint:
272
+ - HTTP Method: GET, POST, PUT, PATCH, DELETE
273
+ - Path: /api/resource or /api/resource/:id
274
+ - Purpose: 1 sentence description
275
+ - Authentication: Required? (Yes/No, Role required)
276
+ - Request:
277
+ * Query params (if GET)
278
+ * Path params (if /:id)
279
+ * Request body (JSON schema)
280
+ * Validation rules
281
+ - Response:
282
+ * Success (200/201/204): JSON schema
283
+ * Errors: 400, 401, 403, 404, 409, 500 with messages
284
+
285
+ 3. Define data validation rules:
286
+ - Email: valid format, max length
287
+ - Password: min length, complexity requirements
288
+ - Required fields
289
+ - Optional fields with defaults
290
+ - Array min/max length
291
+ - Number min/max values
292
+
293
+ 4. Define error response format:
294
+ Standard error schema:
295
+ ```json
296
+ {
297
+ "error": {
298
+ "code": "VALIDATION_ERROR",
299
+ "message": "Human-readable message",
300
+ "details": [
301
+ {
302
+ "field": "email",
303
+ "issue": "Invalid email format"
304
+ }
305
+ ]
306
+ }
307
+ }
308
+ ```
309
+
310
+ 5. Group endpoints by resource:
311
+ - Auth endpoints: /api/auth/*
312
+ - User endpoints: /api/users/*
313
+ - Order endpoints: /api/orders/*
314
+ - etc.
315
+
316
+ Output:
317
+ - Section 4: API Design
318
+ - 4.1: API Endpoints (grouped by resource)
319
+ - Each endpoint with method, path, request, response, errors
320
+ - 4.2: Validation Rules
321
+ - 4.3: Error Response Format
322
+
323
+ Validation:
324
+ - All user stories map to API endpoints
325
+ - All endpoints have request/response schemas
326
+ - All endpoints have error handling
327
+ - RESTful conventions followed (unless GraphQL)
328
+ - Constitution Article IX: Integration-First Gate (Contracts defined first)
329
+ ```
330
+
331
+ ### Step 7: Plan Security Strategy
332
+
333
+ ```yaml
334
+ Purpose: Define authentication, authorization, secret management, and input validation
335
+
336
+ Actions:
337
+ 1. Define authentication strategy:
338
+ - Strategy: JWT/OAuth2/Session-based/API Keys
339
+ - Token expiry: Access token TTL, Refresh token TTL
340
+ - Token storage: Where tokens are stored (database, Redis, etc.)
341
+ - Token refresh mechanism
342
+
343
+ 2. Define authorization model:
344
+ - Model: RBAC (Role-Based) / ABAC (Attribute-Based) / ACL
345
+ - Roles: admin, user, guest, etc.
346
+ - Permissions per role
347
+ - Implementation: Middleware checks
348
+
349
+ 3. Define secret management:
350
+ - ✅ **NO HARDCODED SECRETS** (Constitution Article III)
351
+ - Strategy: Environment variables (.env file)
352
+ - Required secrets:
353
+ * JWT_SECRET or equivalent
354
+ * DATABASE_URL
355
+ * REDIS_URL
356
+ * API keys for third-party services
357
+ - Secret rotation: Every 90 days or per security policy
358
+ - Secret storage: .env file (not committed), CI/CD secrets
359
+
360
+ 4. Define input validation:
361
+ - Tool: Zod/Joi/class-validator/express-validator
362
+ - Validation points: All API endpoints
363
+ - SQL injection prevention: Use ORM (parameterized queries)
364
+ - XSS prevention: React escapes by default, CSP headers
365
+ - CSRF prevention: SameSite cookies, CSRF tokens
366
+
367
+ 5. Define rate limiting:
368
+ - Login attempts: Max attempts per IP/user per time window
369
+ - API requests: Max requests per user/IP per time window
370
+ - Tool: express-rate-limit or equivalent
371
+
372
+ 6. Define security headers:
373
+ - Helmet.js or equivalent
374
+ - CSP (Content Security Policy)
375
+ - HSTS (Strict Transport Security)
376
+ - X-Frame-Options
377
+
378
+ Output:
379
+ - Section 5: Security Design
380
+ - 5.1: Authentication (strategy, tokens, refresh)
381
+ - 5.2: Authorization (model, roles, permissions)
382
+ - 5.3: Secret Management (NO HARDCODED SECRETS, env vars, rotation)
383
+ - 5.4: Input Validation (tool, SQL/XSS/CSRF prevention)
384
+ - 5.5: Rate Limiting (rules, tool)
385
+ - 5.6: Security Headers
386
+
387
+ Validation:
388
+ - ✅ NO HARDCODED SECRETS (Constitution Article III)
389
+ - All secrets in environment variables
390
+ - Input validation on all endpoints
391
+ - SQL/XSS/CSRF prevention measures defined
392
+ ```
393
+
394
+ ### Step 8: Plan Performance and Scalability
395
+
396
+ ```yaml
397
+ Purpose: Define caching, optimization, and scalability strategies
398
+
399
+ Actions:
400
+ 1. Define caching strategy:
401
+ - Cache layer: Redis/Memcached/In-memory
402
+ - What to cache:
403
+ * User sessions: TTL (e.g., 15min)
404
+ * User profiles: TTL (e.g., 5min)
405
+ * Product catalog: TTL (e.g., 10min)
406
+ - Cache key patterns: user:{userId}:profile, product:{productId}
407
+ - Cache invalidation: On data update (write-through/write-behind)
408
+
409
+ 2. Define database optimization:
410
+ - Indexes: On frequently queried fields
411
+ - Query optimization: Use ORM's select to fetch only needed fields
412
+ - Connection pooling: Max connections (e.g., 20)
413
+ - Read replicas: For read-heavy operations (if needed)
414
+
415
+ 3. Define scalability approach:
416
+ - Horizontal scaling: Stateless API servers behind load balancer
417
+ - Database: Read replicas, sharding (if needed)
418
+ - Cache: Redis cluster for high availability
419
+ - CDN: For static assets (if applicable)
420
+
421
+ 4. Define performance targets:
422
+ - API Response Time (p95): < 200ms
423
+ - Database Query Time (p95): < 50ms
424
+ - Concurrent Users: 100 / 1000 / 10000 (based on requirements)
425
+ - Throughput: Requests per second (RPS)
426
+
427
+ Output:
428
+ - Section 6: Performance Design
429
+ - 6.1: Caching Strategy (what, TTL, invalidation)
430
+ - 6.2: Database Optimization (indexes, pooling, replicas)
431
+ - 6.3: Scalability (horizontal scaling, load balancing)
432
+ - 6.4: Performance Targets (response time, throughput, concurrency)
433
+
434
+ Validation:
435
+ - Caching strategy defined for frequently accessed data
436
+ - Database indexes defined
437
+ - Scalability approach appropriate for expected load
438
+ - Performance targets measurable and realistic
439
+ ```
440
+
441
+ ### Step 9: Execute Phase -1 Constitutional Gates
442
+
443
+ ```yaml
444
+ Purpose: Validate design against Constitution Articles VII, VIII, IX + ANTI-TECH-CREEP BEFORE implementation
445
+
446
+ Actions:
447
+ 0. **Baseline Deviation Check (ANTI-TECH-CREEP)**:
448
+ Check:
449
+ - [ ] All baseline technologies from CLAUDE.md are reused (no replacements)
450
+ - [ ] All new technologies explicitly justified with PRD requirements
451
+ - [ ] No unnecessary refactoring (keep existing patterns)
452
+ - [ ] No unfamiliar third-party libraries without strong reason
453
+
454
+ Validation:
455
+ - Compare Section 2 (Technology Stack) with BASELINE_TECH_STACK from Step 1
456
+ - Identify all deviations (new tech, replaced tech, removed tech)
457
+ - For each deviation:
458
+ * Verify it's listed in "Deviation from Baseline" subsection in Section 2
459
+ * Verify PRD requirement that necessitates it
460
+ * Verify justification is concrete (not "might be useful" or "best practice")
461
+ * Example valid: "Adding Redis because PRD requires <500ms API response"
462
+ * Example invalid: "Replacing Express with NestJS for better architecture"
463
+
464
+ If violations found:
465
+ - Document in Complexity Tracking table
466
+ - Format: `| Baseline Deviation | ${tech_change} | ${justification} | ${approved} |`
467
+ - Example: `| Redis Cache | PRD requires <500ms response | Caching layer needed | YES |`
468
+ - Require explicit approval for all deviations
469
+
470
+ 1. Simplicity Gate (Article VII):
471
+ Check:
472
+ - [ ] ≤3 projects/modules (count frontend, backend, database as separate if truly separate)
473
+ - [ ] No future-proofing (no "we might need X later" features)
474
+ - [ ] Minimal dependencies (only essential packages)
475
+
476
+ If violated:
477
+ - Document in Complexity Tracking table
478
+ - Provide justification
479
+ - Require explicit approval
480
+
481
+ 2. Anti-Abstraction Gate (Article VIII):
482
+ Check:
483
+ - [ ] Direct framework usage (no custom wrappers around Express/React/etc.)
484
+ - [ ] Single data model (Prisma schema / TypeORM entities as single source)
485
+ - [ ] No unnecessary interfaces (no BaseController, BaseService unless justified)
486
+
487
+ If violated:
488
+ - Document in Complexity Tracking table
489
+ - Provide justification
490
+ - Require explicit approval
491
+
492
+ 3. Integration-First Gate (Article IX):
493
+ Check:
494
+ - [ ] Contracts defined first (API endpoints in Section 4)
495
+ - [ ] Contract tests planned (will write in TASKS Phase 2)
496
+ - [ ] Real environment testing (Docker for Postgres + Redis, not mocks)
497
+
498
+ If violated:
499
+ - Document in Complexity Tracking table
500
+ - Provide justification
501
+ - Require explicit approval
502
+
503
+ Output:
504
+ - Section 7: Constitution Check (Phase -1 Gates)
505
+ - **7.0: Baseline Deviation Check (ANTI-TECH-CREEP)**
506
+ - 7.1: Simplicity Gate checklist
507
+ - 7.2: Anti-Abstraction Gate checklist
508
+ - 7.3: Integration-First Gate checklist
509
+ - 7.4: Complexity Tracking table (if any violations)
510
+
511
+ Validation:
512
+ - All gates checked
513
+ - All violations documented and justified
514
+ - No violations OR all violations explicitly approved
515
+ ```
516
+
517
+ ### Step 10: Validate Completeness and Generate Output
518
+
519
+ ```yaml
520
+ Purpose: Final validation before outputting TECH_DESIGN.md
521
+
522
+ Validation Checklist:
523
+ - [ ] Section 1: System Architecture (Overview, Modules, Data Flow) - Complete
524
+ - [ ] Section 2: Technology Stack (Frontend, Backend, Database, Infrastructure) - Complete with versions and justifications
525
+ - [ ] Section 3: Data Model Design (Schema, Relationships, Indexes) - Complete
526
+ - [ ] Section 4: API Design (Endpoints, Request/Response, Errors) - Complete
527
+ - [ ] Section 5: Security Design (Auth, Authz, Secret Mgmt, Validation) - Complete
528
+ - [ ] Section 6: Performance Design (Caching, Optimization, Scalability) - Complete
529
+ - [ ] Section 7: Constitution Check (Phase -1 Gates) - Complete
530
+ - [ ] Section 8: Validation Checklist - Complete
531
+ - [ ] No {{PLACEHOLDER}} patterns remaining
532
+ - [ ] All technologies are specific with versions
533
+ - [ ] All tables have primary keys and relationships defined
534
+ - [ ] All API endpoints have schemas
535
+ - [ ] ✅ NO HARDCODED SECRETS
536
+ - [ ] Constitution gates passed or violations justified
537
+
538
+ Actions:
539
+ 1. If validation fails:
540
+ - DO NOT output TECH_DESIGN.md
541
+ - Report which checklist items failed
542
+ - Provide guidance on what needs to be added/fixed
543
+ - Example: "ERROR: Section 3 incomplete - missing user_roles table referenced in Section 5.2"
544
+
545
+ 2. If validation passes:
546
+ - Generate complete TECH_DESIGN.md using the template structure below
547
+ - Write to: devflow/requirements/${REQ_ID}/TECH_DESIGN.md
548
+ - Update: orchestration_status.json (status = "tech_design_complete")
549
+ - Log: log_event "${REQ_ID}" "Technical design completed"
550
+ - Append to EXECUTION_LOG.md
551
+
552
+ Output:
553
+ - Complete TECH_DESIGN.md file
554
+ - Status update in orchestration_status.json
555
+ - Log entry in EXECUTION_LOG.md
556
+ ```
557
+
558
+ ---
559
+
560
+ ## Output Template Structure
561
+
562
+ ```markdown
563
+ # Technical Design: ${REQ_ID} - ${TITLE}
564
+
565
+ **Status**: Draft
566
+ **Created**: ${ISO_8601_UTC_TIMESTAMP}
567
+ **Updated**: ${ISO_8601_UTC_TIMESTAMP}
568
+ **Type**: Technical Design
569
+
570
+ ---
571
+
572
+ ## 1. System Architecture
573
+
574
+ ### 1.1 Architecture Overview
575
+
576
+ [Text-based architecture diagram showing all layers and components]
577
+
578
+ Example:
579
+ \`\`\`
580
+ [Frontend (React)] <--HTTPS--> [API Gateway (Express)] <---> [Auth Service]
581
+ | |
582
+ v v
583
+ [User Service] [Database (PostgreSQL)]
584
+ |
585
+ v
586
+ [Cache (Redis)]
587
+ \`\`\`
588
+
589
+ ### 1.2 Module Breakdown
590
+
591
+ - **Module A**: [Responsibility and purpose]
592
+ - **Module B**: [Responsibility and purpose]
593
+ - **Module C**: [Responsibility and purpose]
594
+
595
+ ### 1.3 Data Flow
596
+
597
+ [Describe request → response flow with authentication, processing, and error handling]
598
+
599
+ Example:
600
+ 1. User Request → Frontend
601
+ 2. Frontend → API Gateway (with JWT token)
602
+ 3. API Gateway → Auth Middleware (verify token)
603
+ 4. Auth Middleware → Service (if authorized)
604
+ 5. Service → Database (query/mutation)
605
+ 6. Service → Cache (read/write)
606
+ 7. Service → API Gateway (response)
607
+ 8. API Gateway → Frontend (JSON response)
608
+
609
+ ### 1.4 Existing Codebase Integration
610
+
611
+ [Describe how this design integrates with existing codebase patterns]
612
+
613
+ - Reuses: [List reusable components, middleware, utilities]
614
+ - Follows: [Existing naming conventions, file structure, code style]
615
+ - Extends: [Existing data models, API patterns, authentication]
616
+
617
+ ---
618
+
619
+ ## 2. Technology Stack
620
+
621
+ ### 2.1 Frontend (if applicable)
622
+
623
+ - **Framework**: [e.g., React 18.2 with TypeScript 5.0]
624
+ - **Justification**: [1-2 sentences on why this choice]
625
+ - **State Management**: [e.g., Redux Toolkit 2.0]
626
+ - **Justification**: [1-2 sentences on why this choice]
627
+ - **UI Library**: [e.g., Material-UI 5.14]
628
+ - **Justification**: [1-2 sentences on why this choice]
629
+ - **Build Tool**: [e.g., Vite 5.0]
630
+ - **Justification**: [1-2 sentences on why this choice]
631
+
632
+ ### 2.2 Backend
633
+
634
+ - **Framework**: [e.g., Express 4.18 with TypeScript 5.0]
635
+ - **Justification**: [1-2 sentences on why this choice]
636
+ - **ORM**: [e.g., Prisma 5.0]
637
+ - **Justification**: [1-2 sentences on why this choice]
638
+ - **Validation**: [e.g., Zod 3.22]
639
+ - **Justification**: [1-2 sentences on why this choice]
640
+ - **Authentication**: [e.g., jsonwebtoken 9.0]
641
+ - **Justification**: [1-2 sentences on why this choice]
642
+
643
+ ### 2.3 Database
644
+
645
+ - **Primary DB**: [e.g., PostgreSQL 15]
646
+ - **Justification**: [1-2 sentences on why this choice]
647
+ - **Cache**: [e.g., Redis 7.0]
648
+ - **Justification**: [1-2 sentences on why this choice]
649
+
650
+ ### 2.4 Infrastructure
651
+
652
+ - **Deployment**: [e.g., Docker + Docker Compose]
653
+ - **Justification**: [1-2 sentences on why this choice]
654
+ - **CI/CD**: [e.g., GitHub Actions]
655
+ - **Justification**: [1-2 sentences on why this choice]
656
+ - **Hosting**: [e.g., AWS EC2 / Vercel / Self-hosted]
657
+ - **Justification**: [1-2 sentences on why this choice]
658
+
659
+ ---
660
+
661
+ ## 3. Data Model Design
662
+
663
+ ### 3.1 Database Schema
664
+
665
+ [For each table, use this format:]
666
+
667
+ #### Table: ${table_name}
668
+
669
+ | Column | Type | Constraints | Description |
670
+ |--------|------|-------------|-------------|
671
+ | id | UUID | PRIMARY KEY | [Description] |
672
+ | ${column_name} | ${data_type} | ${constraints} | [Description] |
673
+ | created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | Creation timestamp |
674
+ | updated_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | Update timestamp |
675
+
676
+ [Repeat for all tables]
677
+
678
+ ### 3.2 Entity Relationships
679
+
680
+ [Visual text representation of relationships]
681
+
682
+ Example:
683
+ - User 1:N Orders (one user can have multiple orders)
684
+ - Order N:M Products (many-to-many through order_items junction table)
685
+ - User 1:1 UserProfile (one-to-one relationship)
686
+
687
+ [ERD-style text diagram if helpful:]
688
+ \`\`\`
689
+ users (1) ----< (N) orders
690
+ orders (N) >----< (M) products (through order_items)
691
+ users (1) ----| (1) user_profiles
692
+ \`\`\`
693
+
694
+ ### 3.3 Indexes and Constraints
695
+
696
+ **Indexes**:
697
+ - ${table_name}(${column_name}) - [Purpose, e.g., "for login lookup"]
698
+ - ${table_name}(${col1}, ${col2}) - [Purpose, e.g., "composite index for user order history"]
699
+
700
+ **Constraints**:
701
+ - Foreign Keys:
702
+ - orders.user_id → users.id ON DELETE CASCADE
703
+ - order_items.order_id → orders.id ON DELETE CASCADE
704
+ - Unique Constraints:
705
+ - users.email UNIQUE
706
+ - Check Constraints:
707
+ - orders.total_amount > 0
708
+
709
+ ---
710
+
711
+ ## 4. API Design
712
+
713
+ ### 4.1 API Endpoints
714
+
715
+ [Group endpoints by resource. For each endpoint:]
716
+
717
+ #### ${HTTP_METHOD} ${endpoint_path}
718
+
719
+ **Purpose**: [1 sentence description]
720
+
721
+ **Authentication**: [Required: Yes/No] [Role: admin/user/guest]
722
+
723
+ **Request**:
724
+ \`\`\`json
725
+ {
726
+ "${field_name}": "${value_type}",
727
+ ...
728
+ }
729
+ \`\`\`
730
+
731
+ **Validation**:
732
+ - ${field_name}: [validation rules, e.g., "valid email format, max 255 chars"]
733
+ - ${field_name}: [validation rules, e.g., "min 8 chars, must include uppercase, lowercase, number, special char"]
734
+
735
+ **Response** (${success_code}):
736
+ \`\`\`json
737
+ {
738
+ "${field_name}": "${value}",
739
+ ...
740
+ }
741
+ \`\`\`
742
+
743
+ **Errors**:
744
+ - 400: [Description, e.g., "Invalid input (email format, password strength)"]
745
+ - 401: [Description, e.g., "Unauthorized - invalid or missing token"]
746
+ - 403: [Description, e.g., "Forbidden - insufficient permissions"]
747
+ - 404: [Description, e.g., "Resource not found"]
748
+ - 409: [Description, e.g., "Conflict - email already exists"]
749
+ - 500: [Description, e.g., "Internal server error"]
750
+
751
+ [Repeat for all endpoints, grouped by resource]
752
+
753
+ ### 4.2 Error Response Format
754
+
755
+ Standard error response schema:
756
+ \`\`\`json
757
+ {
758
+ "error": {
759
+ "code": "ERROR_CODE",
760
+ "message": "Human-readable error message",
761
+ "details": [
762
+ {
763
+ "field": "field_name",
764
+ "issue": "Specific issue description"
765
+ }
766
+ ]
767
+ }
768
+ }
769
+ \`\`\`
770
+
771
+ ---
772
+
773
+ ## 5. Security Design
774
+
775
+ ### 5.1 Authentication
776
+
777
+ - **Strategy**: [e.g., JWT with access and refresh tokens]
778
+ - **Token Expiry**: Access [e.g., 15 minutes], Refresh [e.g., 7 days]
779
+ - **Token Storage**: [e.g., Access tokens in httpOnly cookies, Refresh tokens in database]
780
+ - **Token Refresh Mechanism**: [Describe refresh flow]
781
+
782
+ ### 5.2 Authorization
783
+
784
+ - **Model**: [e.g., RBAC (Role-Based Access Control)]
785
+ - **Roles**:
786
+ - admin: [Permissions, e.g., "Full access to all resources"]
787
+ - user: [Permissions, e.g., "Access to own resources"]
788
+ - guest: [Permissions, e.g., "Read-only access to public resources"]
789
+ - **Implementation**: [e.g., "Middleware checks JWT claims for role, blocks unauthorized requests"]
790
+
791
+ ### 5.3 Secret Management
792
+
793
+ - ✅ **NO HARDCODED SECRETS** (Constitution Article III)
794
+ - **Strategy**: Environment variables stored in .env file (not committed to Git)
795
+ - **Required Secrets**:
796
+ - JWT_SECRET: [Purpose, e.g., "For signing JWT access tokens"]
797
+ - DATABASE_URL: [Purpose, e.g., "Database connection string"]
798
+ - REDIS_URL: [Purpose, e.g., "Redis connection string"]
799
+ - [Additional API keys for third-party services]
800
+ - **Secret Rotation**: [e.g., "Every 90 days or per security policy"]
801
+ - **Secret Storage**:
802
+ - Development: .env file (gitignored)
803
+ - Production: CI/CD secrets (GitHub Secrets, AWS Secrets Manager, etc.)
804
+
805
+ ### 5.4 Input Validation
806
+
807
+ - **Tool**: [e.g., Zod schemas for all API inputs]
808
+ - **Validation Points**: All API endpoints validate request body, query params, path params
809
+ - **SQL Injection Prevention**: Use ORM (Prisma/TypeORM) with parameterized queries
810
+ - **XSS Prevention**:
811
+ - React escapes by default
812
+ - CSP (Content Security Policy) headers
813
+ - Sanitize user-generated content
814
+ - **CSRF Prevention**:
815
+ - SameSite cookies
816
+ - CSRF tokens for state-changing operations (POST/PUT/DELETE)
817
+
818
+ ### 5.5 Rate Limiting
819
+
820
+ - **Login Attempts**: [e.g., "Max 5 attempts per IP per 15 minutes"]
821
+ - **API Requests**: [e.g., "Max 100 requests per user per minute"]
822
+ - **Tool**: [e.g., "express-rate-limit middleware"]
823
+ - **Implementation**: [Describe rate limiting strategy]
824
+
825
+ ### 5.6 Security Headers
826
+
827
+ - **Tool**: [e.g., "Helmet.js for Express"]
828
+ - **Headers**:
829
+ - CSP (Content Security Policy): [Configuration]
830
+ - HSTS (HTTP Strict Transport Security): [Configuration]
831
+ - X-Frame-Options: DENY
832
+ - X-Content-Type-Options: nosniff
833
+ - Referrer-Policy: no-referrer
834
+
835
+ ---
836
+
837
+ ## 6. Performance Design
838
+
839
+ ### 6.1 Caching Strategy
840
+
841
+ - **Cache Layer**: [e.g., Redis 7.0]
842
+ - **What to Cache**:
843
+ - User sessions: TTL [e.g., 15 minutes]
844
+ - User profiles: TTL [e.g., 5 minutes], invalidate on update
845
+ - [Other cached data]: TTL [e.g., 10 minutes]
846
+ - **Cache Key Patterns**:
847
+ - `user:{userId}:session`
848
+ - `user:{userId}:profile`
849
+ - [Additional patterns]
850
+ - **Cache Invalidation**:
851
+ - Write-through: Update cache on data write
852
+ - TTL-based: Expire after TTL
853
+ - Manual: Invalidate on specific events
854
+
855
+ ### 6.2 Database Optimization
856
+
857
+ - **Indexes**: [List all indexes from Section 3.3]
858
+ - **Query Optimization**:
859
+ - Use ORM's select to fetch only needed fields
860
+ - Avoid N+1 query problems with eager loading
861
+ - **Connection Pooling**: Max [e.g., 20] connections
862
+ - **Read Replicas**: [If applicable, describe read replica strategy]
863
+
864
+ ### 6.3 Scalability
865
+
866
+ - **Horizontal Scaling**: Stateless API servers behind load balancer
867
+ - **Load Balancer**: [e.g., "Nginx or cloud provider load balancer"]
868
+ - **Database**:
869
+ - Read replicas for read-heavy operations
870
+ - Sharding [if needed]: [Describe sharding strategy]
871
+ - **Cache**: Redis cluster for high availability
872
+ - **CDN**: [If applicable] For static assets (images, CSS, JS)
873
+
874
+ ### 6.4 Performance Targets
875
+
876
+ | Metric | Target | Measurement |
877
+ |--------|--------|-------------|
878
+ | API Response Time (p95) | < 200ms | Application Performance Monitoring (APM) |
879
+ | Database Query Time (p95) | < 50ms | Database query logs |
880
+ | Concurrent Users | [e.g., 1000+] | Load testing |
881
+ | Throughput (RPS) | [e.g., 500 requests/sec] | Load testing |
882
+
883
+ ---
884
+
885
+ ## 7. Constitution Check (Phase -1 Gates)
886
+
887
+ ### 7.0 Baseline Deviation Check (ANTI-TECH-CREEP)
888
+
889
+ **Baseline Tech Stack** (from CLAUDE.md):
890
+ - **Frontend**: [e.g., React 18 with TypeScript 5.0]
891
+ - **Backend**: [e.g., Express 4.18 with TypeScript]
892
+ - **Database**: [e.g., PostgreSQL 15]
893
+ - **ORM**: [e.g., Prisma 5.0]
894
+ - **Authentication**: [e.g., JWT with bcrypt]
895
+ - **Validation**: [e.g., Zod 3.22]
896
+ - **Testing**: [e.g., Jest 29 with supertest]
897
+
898
+ **Deviation Analysis**:
899
+ - [x] **All baseline technologies reused**: [Verify all baseline tech in Section 2]
900
+ - [x] **All new technologies justified**: [List all deviations with PRD requirements]
901
+ - [x] **No unnecessary refactoring**: [Verify no replacements of baseline tech]
902
+ - [x] **No unfamiliar third-party libraries**: [Verify all new libraries have clear necessity]
903
+
904
+ **Deviations from Baseline** (if any):
905
+ | New/Changed Technology | PRD Requirement | Justification | Status |
906
+ |------------------------|-----------------|---------------|--------|
907
+ | [e.g., Redis Cache] | [e.g., <500ms API response] | [e.g., High-frequency reads require caching] | ✅ Approved |
908
+ | [If none, write "None"] | N/A | N/A | N/A |
909
+
910
+ **Status**: ✅ Passed (no deviations) / ⚠️ Deviations (see table above)
911
+
912
+ ### 7.1 Simplicity Gate (Article VII)
913
+
914
+ - [ ] **≤3 projects/modules**: [List modules: e.g., "Frontend, Backend, Database = 3 modules"]
915
+ - [ ] **No future-proofing**: [Verify no speculative features like "might need message queue later"]
916
+ - [ ] **Minimal dependencies**: [List essential dependencies only]
917
+
918
+ **Status**: ✅ Passed / ⚠️ Violations (see Complexity Tracking)
919
+
920
+ ### 7.2 Anti-Abstraction Gate (Article VIII)
921
+
922
+ - [ ] **Direct framework usage**: [Verify no custom wrappers, e.g., "Using Express directly, no BaseController"]
923
+ - [ ] **Single data model**: [Verify single source of truth, e.g., "Prisma schema is single source"]
924
+ - [ ] **No unnecessary interfaces**: [Verify no unnecessary abstraction layers]
925
+
926
+ **Status**: ✅ Passed / ⚠️ Violations (see Complexity Tracking)
927
+
928
+ ### 7.3 Integration-First Gate (Article IX)
929
+
930
+ - [ ] **Contracts defined first**: [Verify API contracts in Section 4]
931
+ - [ ] **Contract tests planned**: [Verify tests will be written in TASKS Phase 2]
932
+ - [ ] **Real environment testing**: [Verify Docker for Postgres + Redis, not mocks]
933
+
934
+ **Status**: ✅ Passed / ⚠️ Violations (see Complexity Tracking)
935
+
936
+ ### 7.4 Complexity Tracking
937
+
938
+ [Only if there are violations:]
939
+
940
+ | Violation Type | Potential Violation | Justification | Approved? |
941
+ |----------------|---------------------|---------------|-----------|
942
+ | Baseline Deviation | [Example: "Added Redis Cache"] | [Example: "PRD requires <500ms API response time"] | [YES/NO] |
943
+ | Simplicity | [Example: "4 modules instead of 3"] | [Example: "Frontend/Backend/Database/Cache - cache required for performance"] | [YES/NO] |
944
+ | Anti-Abstraction | [Example: "Custom BaseController"] | [Example: "..."] | [YES/NO] |
945
+ | Integration-First | [Example: "Mock database in tests"] | [Example: "..."] | [YES/NO] |
946
+
947
+ **Note**: If no violations, this table can be omitted or replaced with:
948
+ | [e.g., "Using 4 modules instead of 3"] | [e.g., "Separate admin service required for security isolation"] | [Yes/No/Pending] |
949
+ | [If none, write "None"] | N/A | N/A |
950
+
951
+ ---
952
+
953
+ ## 8. Validation Checklist
954
+
955
+ - [ ] **Section 1**: System Architecture (Overview, Modules, Data Flow) - Complete
956
+ - [ ] **Section 2**: Technology Stack (Frontend, Backend, Database, Infrastructure) - Complete with versions and justifications
957
+ - [ ] **Section 3**: Data Model Design (Schema, Relationships, Indexes) - Complete
958
+ - [ ] **Section 4**: API Design (Endpoints, Request/Response, Errors) - Complete
959
+ - [ ] **Section 5**: Security Design (Auth, Authz, Secret Mgmt, Validation) - Complete
960
+ - [ ] **Section 6**: Performance Design (Caching, Optimization, Scalability) - Complete
961
+ - [ ] **Section 7**: Constitution Check (Phase -1 Gates) - Complete
962
+ - [ ] **No placeholders**: No {{PLACEHOLDER}} patterns remaining
963
+ - [ ] **Specific technologies**: All technologies have versions (e.g., "React 18.2", not "modern framework")
964
+ - [ ] **Complete schema**: All tables have primary keys, foreign keys, indexes
965
+ - [ ] **Complete API**: All endpoints have request/response schemas and error handling
966
+ - [ ] **✅ NO HARDCODED SECRETS**: All secrets in environment variables
967
+ - [ ] **Constitution compliance**: Phase -1 Gates passed or violations justified
968
+
969
+ **Ready for Epic Planning**: ✅ YES / ❌ NO (if NO, explain what needs to be fixed)
970
+
971
+ ---
972
+
973
+ **Generated by**: tech-architect agent (research-type)
974
+ **Template Version**: 1.0.0
975
+ **Constitution Version**: v2.0.0
976
+ ```
977
+
978
+ ---
979
+
980
+ ## Template Usage Notes
981
+
982
+ ### For tech-architect Agent
983
+
984
+ 1. **Load this template** at the start of technical design process
985
+ 2. **Follow Execution Flow** step-by-step (Steps 1-10)
986
+ 3. **Fill all sections** of the Output Template Structure
987
+ 4. **Validate completeness** using Step 10 checklist
988
+ 5. **Output complete TECH_DESIGN.md** with no {{PLACEHOLDER}} remaining
989
+
990
+ ### For planner Agent
991
+
992
+ After TECH_DESIGN.md is generated:
993
+
994
+ 1. **Read TECH_DESIGN.md** as input to Epic and Tasks generation
995
+ 2. **Use Section 3 (Data Model)** to generate database migration tasks
996
+ 3. **Use Section 4 (API Design)** to generate API implementation tasks
997
+ 4. **Use Section 5 (Security)** to generate security implementation tasks
998
+ 5. **Use Section 6 (Performance)** to generate optimization tasks
999
+ 6. **Ensure TASKS.md covers ALL layers** defined in TECH_DESIGN.md
1000
+
1001
+ This ensures comprehensive task breakdown with no missing technical details.
1002
+
1003
+ ---
1004
+
1005
+ ## Quality Criteria Summary
1006
+
1007
+ A complete TECH_DESIGN.md must have:
1008
+
1009
+ ✅ **All 8 sections filled** with concrete technical details
1010
+ ✅ **No {{PLACEHOLDER}}** patterns remaining
1011
+ ✅ **Specific technologies** with versions and justifications
1012
+ ✅ **Complete database schema** with tables, columns, relationships, indexes
1013
+ ✅ **Complete API contracts** with all endpoints, request/response schemas, errors
1014
+ ✅ **Complete security plan** with NO HARDCODED SECRETS
1015
+ ✅ **Complete performance plan** with caching, optimization, scalability
1016
+ ✅ **Constitution compliance** with Phase -1 Gates passed or violations justified
1017
+ ✅ **Validation checklist** fully checked
1018
+
1019
+ Only then is it ready for Epic planning and task breakdown.