@polymorphism-tech/morph-spec 4.12.0 → 4.13.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 (314) hide show
  1. package/README.md +21 -29
  2. package/bin/morph-spec.js +41 -24
  3. package/bin/task-manager.js +962 -1341
  4. package/bin/validate.js +1 -1
  5. package/claude-plugin.json +1 -1
  6. package/docs/CHEATSHEET.md +10 -11
  7. package/docs/QUICKSTART.md +15 -15
  8. package/framework/CLAUDE.md +5 -2
  9. package/framework/agents/README.md +3 -4
  10. package/framework/agents/ai-agents/ai-system-architect.md +6 -10
  11. package/framework/agents/architecture/seo-growth-hacker.md +166 -326
  12. package/framework/agents/architecture/standards-architect.md +21 -31
  13. package/framework/agents/backend/dotnet-senior.md +160 -86
  14. package/framework/agents/backend/ef-modeler.md +2 -6
  15. package/framework/agents/backend/hangfire-orchestrator.md +8 -9
  16. package/framework/agents/backend/ms-agent-expert.md +1 -1
  17. package/framework/agents/frontend/nextjs-expert.md +198 -133
  18. package/framework/agents/frontend/ui-ux-designer.md +226 -267
  19. package/framework/agents/infrastructure/infra-architect.md +191 -27
  20. package/framework/agents/integrations/clerk-auth.md +19 -26
  21. package/framework/agents/integrations/hangfire-integration.md +1 -4
  22. package/framework/agents.json +215 -1453
  23. package/framework/commands/morph-apply.md +4 -4
  24. package/framework/commands/morph-preflight.md +4 -26
  25. package/framework/commands/morph-proposal.md +19 -19
  26. package/framework/commands/morph-status.md +2 -2
  27. package/framework/commands/morph-troubleshoot.md +6 -13
  28. package/framework/hooks/README.md +1 -6
  29. package/framework/hooks/claude-code/post-tool-use/validator-feedback.js +4 -6
  30. package/framework/hooks/claude-code/pre-compact/save-morph-context.js +12 -7
  31. package/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +2 -2
  32. package/framework/hooks/claude-code/pre-tool-use/protect-spec-files.js +2 -2
  33. package/framework/hooks/claude-code/pre-tool-use/task-tracking-guard.js +5 -10
  34. package/framework/hooks/claude-code/session-start/inject-morph-context.js +63 -30
  35. package/framework/hooks/claude-code/session-start/resume-context.js +77 -0
  36. package/framework/hooks/claude-code/statusline.py +4 -5
  37. package/framework/hooks/claude-code/stop/validate-completion.js +4 -4
  38. package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +8 -8
  39. package/framework/hooks/shared/compact-restore.js +28 -5
  40. package/framework/hooks/shared/phase-utils.js +4 -8
  41. package/framework/hooks/shared/state-reader.js +34 -3
  42. package/framework/phases.json +7 -45
  43. package/framework/rules/ai-agents-standards.md +15 -0
  44. package/framework/rules/asaas-standards.md +13 -0
  45. package/framework/rules/clerk-standards.md +13 -0
  46. package/framework/rules/csharp-standards.md +8 -4
  47. package/framework/rules/data-standards.md +18 -0
  48. package/framework/rules/dotnet-templates.md +87 -0
  49. package/framework/rules/frontend-standards.md +13 -13
  50. package/framework/rules/hangfire-standards.md +13 -0
  51. package/framework/rules/infrastructure-standards.md +27 -16
  52. package/framework/rules/morph-workflow.md +73 -13
  53. package/framework/rules/nextjs-standards.md +1 -0
  54. package/framework/rules/nextjs-templates.md +40 -0
  55. package/framework/rules/resend-standards.md +12 -0
  56. package/framework/rules/supabase-standards.md +29 -0
  57. package/framework/skills/README.md +6 -8
  58. package/framework/skills/level-0-meta/mcp-registry.json +21 -99
  59. package/framework/{standards/ai-agents/team-orchestration.md → skills/level-0-meta/morph-agent-teams/SKILL.md} +472 -479
  60. package/framework/skills/level-0-meta/morph-brainstorming/SKILL.md +28 -1
  61. package/framework/skills/level-0-meta/morph-checklist/SKILL.md +2 -2
  62. package/framework/skills/level-0-meta/morph-code-review/SKILL.md +1 -5
  63. package/framework/skills/level-0-meta/morph-code-review/scripts/scan-csharp.mjs +1 -1
  64. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +23 -41
  65. package/framework/skills/level-0-meta/morph-init/SKILL.md +18 -14
  66. package/framework/skills/level-0-meta/morph-parallel-dispatch/SKILL.md +225 -0
  67. package/framework/skills/level-0-meta/morph-post-implementation/SKILL.md +20 -0
  68. package/framework/skills/level-0-meta/morph-tool-usage-guide/SKILL.md +4 -8
  69. package/framework/skills/level-0-meta/morph-tool-usage-guide/references/tools-per-phase.md +15 -59
  70. package/framework/skills/level-0-meta/morph-verification-before-completion/SKILL.md +7 -19
  71. package/framework/skills/level-0-meta/morph-verification-before-completion/scripts/check-phase-outputs.mjs +8 -8
  72. package/framework/skills/level-1-workflows/README.md +1 -1
  73. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +49 -50
  74. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +58 -124
  75. package/framework/skills/level-1-workflows/morph-phase-design/references/architecture-analysis-guide.md +5 -50
  76. package/framework/skills/level-1-workflows/morph-phase-design/references/spec-example.md +1 -1
  77. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +127 -159
  78. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/implementer-prompt.md +4 -3
  79. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/spec-reviewer-prompt.md +2 -2
  80. package/framework/skills/level-1-workflows/morph-phase-implement/references/recap-example.md +1 -1
  81. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +17 -13
  82. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +22 -40
  83. package/framework/skills/level-1-workflows/morph-phase-tasks/references/task-planning-patterns.md +0 -2
  84. package/framework/skills/level-1-workflows/morph-phase-tasks/references/tasks-example.md +5 -5
  85. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +57 -77
  86. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +1 -1
  87. package/framework/squad-templates/backend-only.json +6 -6
  88. package/framework/squad-templates/frontend-only.json +17 -8
  89. package/framework/squad-templates/full-stack.json +29 -24
  90. package/framework/standards/STANDARDS.json +1021 -2369
  91. package/framework/standards/backend/dotnet/fluent-validation-vsa.md +200 -0
  92. package/framework/standards/backend/dotnet/result-pattern.md +213 -0
  93. package/framework/standards/backend/dotnet/scalar-ui.md +172 -0
  94. package/framework/standards/backend/dotnet/scrutor.md +158 -0
  95. package/framework/standards/backend/dotnet/vsa-handler-patterns.md +274 -0
  96. package/framework/standards/frontend/nextjs/motion-patterns.md +1 -1
  97. package/framework/standards/infrastructure/supabase/mcp-setup.md +83 -193
  98. package/framework/standards/integration/mcp/mcp-tools.md +91 -77
  99. package/framework/templates/IDE-SNIPPETS.md +2 -6
  100. package/framework/templates/README.md +709 -814
  101. package/framework/templates/REGISTRY.json +223 -762
  102. package/framework/templates/code/dotnet/abstractions/api-endpoint.cs +7 -0
  103. package/framework/templates/code/dotnet/abstractions/error.cs +60 -0
  104. package/framework/templates/code/dotnet/abstractions/handler.cs +12 -0
  105. package/framework/templates/code/dotnet/abstractions/result.cs +74 -0
  106. package/framework/templates/code/dotnet/backend/repository.cs +148 -141
  107. package/framework/templates/code/dotnet/constants/api-tags.cs +6 -0
  108. package/framework/templates/code/dotnet/exceptions/exception-handler.cs +32 -0
  109. package/framework/templates/code/dotnet/extensions/database-extensions.cs +20 -0
  110. package/framework/templates/code/dotnet/extensions/handler-registration.cs +38 -0
  111. package/framework/templates/code/dotnet/extensions/health-checks.cs +24 -0
  112. package/framework/templates/code/dotnet/extensions/map-endpoints.cs +35 -0
  113. package/framework/templates/code/dotnet/extensions/result-extensions.cs +29 -0
  114. package/framework/templates/code/dotnet/feature/endpoint.cs.hbs +21 -0
  115. package/framework/templates/code/dotnet/feature/entity.cs.hbs +8 -0
  116. package/framework/templates/code/dotnet/feature/errors.cs.hbs +8 -0
  117. package/framework/templates/code/dotnet/feature/handler.cs.hbs +24 -0
  118. package/framework/templates/code/dotnet/feature/request.cs.hbs +4 -0
  119. package/framework/templates/code/dotnet/feature/response.cs.hbs +4 -0
  120. package/framework/templates/code/dotnet/feature/validator.cs.hbs +15 -0
  121. package/framework/templates/code/dotnet/jobs/job.cs +21 -17
  122. package/framework/templates/code/dotnet/pipelines/logging-decorator.cs +31 -0
  123. package/framework/templates/code/dotnet/pipelines/validation-decorator.cs +97 -0
  124. package/framework/templates/code/dotnet/test.cs +192 -106
  125. package/framework/templates/context/ARCHITECTURE.md +89 -0
  126. package/framework/templates/context/CONTEXT-FEATURE.md +2 -2
  127. package/framework/templates/context/CONTEXT.md +180 -181
  128. package/framework/templates/context/design-system.md +1 -5
  129. package/framework/templates/docs/onboarding.md +2 -3
  130. package/framework/templates/docs/proposal.md +171 -182
  131. package/framework/templates/docs/spec.md +1 -3
  132. package/framework/templates/docs/ui-components.md +0 -72
  133. package/framework/templates/examples/design-system-examples.md +4 -4
  134. package/framework/templates/feature/decisions.md +0 -66
  135. package/framework/templates/feature/recap.md +1 -2
  136. package/framework/templates/infrastructure/github/README.md +56 -593
  137. package/framework/templates/integrations/clerk-config.cs +0 -41
  138. package/framework/templates/meta-prompts/parallel-workers/parallel-worker.md +2 -2
  139. package/framework/templates/meta-prompts/squad-leaders/backend-squad.md +1 -2
  140. package/framework/templates/meta-prompts/squad-leaders/frontend-squad.md +83 -126
  141. package/framework/templates/meta-prompts/validators/pre-commit-validator.md +2 -2
  142. package/framework/templates/project/validate.js +2 -4
  143. package/framework/templates/ui/design-system.css +1 -1
  144. package/framework/workflows/README.md +8 -8
  145. package/framework/workflows/configs/fast-track.json +51 -0
  146. package/framework/workflows/configs/full.json +68 -0
  147. package/framework/workflows/configs/standard.json +7 -3
  148. package/framework/workflows/docs/STORY-DRIVEN-DEVELOPMENT.md +1 -1
  149. package/framework/workflows/docs/enforcement-pipeline.md +18 -19
  150. package/framework/workflows/docs/full-morph.md +69 -76
  151. package/framework/workflows/docs/standard.md +49 -44
  152. package/framework/workflows/docs/ui-refresh.md +1 -1
  153. package/package.json +3 -3
  154. package/src/commands/agents/dispatch-agents.js +55 -116
  155. package/src/commands/context/context-refresh.js +79 -0
  156. package/src/commands/phase/phase-reset.js +1 -1
  157. package/src/commands/project/doctor.js +10 -32
  158. package/src/commands/project/init.js +12 -0
  159. package/src/commands/project/status.js +6 -12
  160. package/src/commands/scaffold/scaffold.js +131 -0
  161. package/src/commands/scope/escalate.js +1 -1
  162. package/src/commands/state/advance-phase.js +15 -29
  163. package/src/commands/state/state.js +20 -5
  164. package/src/commands/tasks/task.js +0 -30
  165. package/src/commands/validation/validate-feature.js +3 -10
  166. package/src/core/paths/output-schema.js +12 -13
  167. package/src/core/state/phase-state-machine.js +211 -217
  168. package/src/core/state/state-manager.js +9 -9
  169. package/src/lib/agents/agents-manager.js +2 -2
  170. package/src/lib/agents/output-collector.js +1 -2
  171. package/src/lib/detectors/design-system-detector.js +4 -4
  172. package/src/lib/detectors/index.js +1 -11
  173. package/src/lib/generators/architecture-scanner.js +640 -0
  174. package/src/lib/generators/context-generator.js +3 -3
  175. package/src/lib/generators/design-system-generator.js +508 -587
  176. package/src/lib/generators/index.js +12 -10
  177. package/src/lib/generators/metadata-extractor.js +386 -387
  178. package/src/lib/generators/recap-generator.js +4 -4
  179. package/src/lib/generators/scaffold-generator.js +317 -0
  180. package/src/lib/generators/settings-generator.js +0 -1
  181. package/src/lib/phase-chain/phase-validator.js +64 -42
  182. package/src/lib/stack/stack-profile.js +2 -2
  183. package/src/lib/standards/digest-builder.js +72 -285
  184. package/src/lib/tasks/task-parser.js +11 -5
  185. package/src/lib/validators/architecture/architecture-validator.js +259 -387
  186. package/src/lib/validators/content/content-validator.js +287 -287
  187. package/src/lib/validators/css/css-validator.js +340 -352
  188. package/src/lib/validators/packages/package-validator.js +347 -360
  189. package/src/lib/validators/shared/issue-counter.js +14 -18
  190. package/src/lib/validators/validation-runner.js +3 -19
  191. package/src/scripts/setup-infra.js +1 -1
  192. package/src/utils/agents-installer.js +24 -3
  193. package/src/utils/file-copier.js +1 -0
  194. package/src/utils/hooks-installer.js +11 -19
  195. package/src/utils/skills-installer.js +178 -178
  196. package/framework/agents/architecture/prompt-engineer.md +0 -195
  197. package/framework/agents/backend/api-designer.md +0 -106
  198. package/framework/agents/frontend/blazor-builder.md +0 -229
  199. package/framework/agents/frontend/nextjs-ui-specialist.md +0 -218
  200. package/framework/agents/infrastructure/azure-architect.md +0 -150
  201. package/framework/agents/infrastructure/azure-deploy-specialist.md +0 -707
  202. package/framework/agents/infrastructure/bicep-architect.md +0 -132
  203. package/framework/agents/infrastructure/container-specialist.md +0 -137
  204. package/framework/agents/infrastructure/devops-engineer.md +0 -126
  205. package/framework/agents/integrations/azure-identity.md +0 -148
  206. package/framework/agents/quality/code-analyzer.md +0 -239
  207. package/framework/agents/quality/testing-specialist.md +0 -130
  208. package/framework/hooks/claude-code/notification/approval-reminder.js +0 -57
  209. package/framework/hooks/claude-code/post-tool-use/context-refresh.js +0 -109
  210. package/framework/hooks/claude-code/post-tool-use/skill-reminder.js +0 -78
  211. package/framework/index/troubleshooting-index.json +0 -184
  212. package/framework/rules/testing-standards.md +0 -14
  213. package/framework/skills/level-0-meta/morph-replicate/SKILL.md +0 -230
  214. package/framework/skills/level-0-meta/morph-replicate/references/blazor-html-mapping.md +0 -70
  215. package/framework/skills/level-1-workflows/morph-phase-clarify/SKILL.md +0 -256
  216. package/framework/skills/level-1-workflows/morph-phase-clarify/references/clarifications-example.md +0 -117
  217. package/framework/skills/level-1-workflows/morph-phase-setup/SKILL.md +0 -269
  218. package/framework/standards/ai-agents/blazor-ui.md +0 -364
  219. package/framework/standards/architecture/ddd/aggregates.md +0 -120
  220. package/framework/standards/architecture/ddd/bounded-contexts.md +0 -105
  221. package/framework/standards/architecture/ddd/complexity-levels.md +0 -108
  222. package/framework/standards/architecture/ddd/entities.md +0 -99
  223. package/framework/standards/architecture/ddd/ubiquitous-language.md +0 -58
  224. package/framework/standards/architecture/ddd/value-objects.md +0 -124
  225. package/framework/standards/backend/api/minimal-api.md +0 -494
  226. package/framework/standards/backend/api/rest.md +0 -492
  227. package/framework/standards/backend/authentication/passkeys.md +0 -428
  228. package/framework/standards/backend/database/ef-core.md +0 -199
  229. package/framework/standards/backend/database/migrations.md +0 -393
  230. package/framework/standards/backend/database/repository-patterns.md +0 -528
  231. package/framework/standards/backend/dotnet/async.md +0 -366
  232. package/framework/standards/backend/dotnet/core.md +0 -117
  233. package/framework/standards/backend/dotnet/di.md +0 -439
  234. package/framework/standards/backend/dotnet/program-cs-checklist.md +0 -92
  235. package/framework/standards/context/analytics.md +0 -96
  236. package/framework/standards/context/bundles.md +0 -110
  237. package/framework/standards/context/priming.md +0 -78
  238. package/framework/standards/core/architecture.md +0 -185
  239. package/framework/standards/core/coding.md +0 -214
  240. package/framework/standards/core/git-branching-strategy.md +0 -403
  241. package/framework/standards/core/git.md +0 -185
  242. package/framework/standards/core/testing.md +0 -295
  243. package/framework/standards/data/nosql/blob-storage.md +0 -102
  244. package/framework/standards/data/vector-search/azure-ai-search.md +0 -121
  245. package/framework/standards/frontend/blazor/design-checklist.md +0 -222
  246. package/framework/standards/frontend/blazor/fluent-ui-setup.md +0 -595
  247. package/framework/standards/frontend/blazor/fluent-ui.md +0 -137
  248. package/framework/standards/frontend/blazor/html-conversion.md +0 -184
  249. package/framework/standards/frontend/blazor/lifecycle.md +0 -195
  250. package/framework/standards/frontend/blazor/pitfalls.md +0 -198
  251. package/framework/standards/frontend/blazor/state.md +0 -191
  252. package/framework/standards/frontend/design-system/aesthetic-direction.md +0 -266
  253. package/framework/standards/frontend/design-system/design-trends.md +0 -171
  254. package/framework/standards/infrastructure/azure/azure.md +0 -624
  255. package/framework/standards/infrastructure/azure/bicep/bicep-patterns.md +0 -422
  256. package/framework/standards/infrastructure/azure/devops/azure-devops-setup.md +0 -516
  257. package/framework/standards/infrastructure/azure/devops/local-development.md +0 -520
  258. package/framework/standards/infrastructure/azure/services/functions.md +0 -486
  259. package/framework/standards/infrastructure/azure/services/service-bus.md +0 -459
  260. package/framework/standards/infrastructure/azure/services/storage.md +0 -407
  261. package/framework/standards/infrastructure/vercel/vercel-database.md +0 -106
  262. package/framework/standards/integration/api/graphql.md +0 -91
  263. package/framework/standards/integration/api/grpc.md +0 -114
  264. package/framework/standards/integration/api/rest-design.md +0 -95
  265. package/framework/standards/integration/event-driven/cqrs.md +0 -101
  266. package/framework/standards/integration/event-driven/event-sourcing.md +0 -124
  267. package/framework/standards/integration/event-driven/service-bus.md +0 -95
  268. package/framework/standards/observability/logging.md +0 -131
  269. package/framework/standards/observability/metrics.md +0 -121
  270. package/framework/standards/observability/monitoring.md +0 -114
  271. package/framework/standards/observability/tracing.md +0 -132
  272. package/framework/standards/workflows/parallel-execution.md +0 -112
  273. package/framework/standards/workflows/thread-management.md +0 -113
  274. package/framework/templates/code/dotnet/backend/service.cs +0 -139
  275. package/framework/templates/code/dotnet/contracts/Commands.cs +0 -74
  276. package/framework/templates/code/dotnet/contracts/Entities.cs +0 -25
  277. package/framework/templates/code/dotnet/contracts/Queries.cs +0 -74
  278. package/framework/templates/code/dotnet/contracts/api-contracts.cs +0 -173
  279. package/framework/templates/code/dotnet/contracts/contracts-level1.cs +0 -69
  280. package/framework/templates/code/dotnet/contracts/contracts-level2.cs +0 -86
  281. package/framework/templates/code/dotnet/contracts/contracts-level3.cs +0 -41
  282. package/framework/templates/code/dotnet/frontend/component.razor +0 -239
  283. package/framework/templates/infrastructure/azure/Dockerfile.example +0 -82
  284. package/framework/templates/infrastructure/azure/README.md +0 -286
  285. package/framework/templates/infrastructure/azure/app-insights.bicep +0 -63
  286. package/framework/templates/infrastructure/azure/app-service.bicep +0 -164
  287. package/framework/templates/infrastructure/azure/container-app-env.bicep +0 -49
  288. package/framework/templates/infrastructure/azure/container-app.bicep +0 -156
  289. package/framework/templates/infrastructure/azure/deploy-checklist.md +0 -426
  290. package/framework/templates/infrastructure/azure/deploy.ps1 +0 -229
  291. package/framework/templates/infrastructure/azure/deploy.sh +0 -208
  292. package/framework/templates/infrastructure/azure/key-vault.bicep +0 -91
  293. package/framework/templates/infrastructure/azure/main.bicep +0 -189
  294. package/framework/templates/infrastructure/azure/parameters.dev.json +0 -29
  295. package/framework/templates/infrastructure/azure/parameters.prod.json +0 -29
  296. package/framework/templates/infrastructure/azure/parameters.staging.json +0 -29
  297. package/framework/templates/infrastructure/azure/sql-database.bicep +0 -103
  298. package/framework/templates/infrastructure/azure/storage.bicep +0 -106
  299. package/framework/templates/infrastructure/github/actions/azure-auth/action.yml.hbs +0 -22
  300. package/framework/templates/infrastructure/github/workflows/deploy-azure-app-service.yml.hbs +0 -61
  301. package/framework/templates/integrations/azure-identity-config.cs +0 -288
  302. package/framework/templates/project-structure/dotnet-ddd.md +0 -70
  303. package/framework/templates/saas/subscription.cs +0 -347
  304. package/framework/templates/saas/tenant.cs +0 -338
  305. package/framework/templates/ui/FluentDesignTheme.cs +0 -149
  306. package/framework/templates/ui/MudTheme.cs +0 -281
  307. package/framework/workflows/configs/nodejs-cli.json +0 -40
  308. package/src/commands/standards/context-budget.js +0 -89
  309. package/src/lib/standards/index.js +0 -7
  310. package/src/lib/standards/standards-context-injector.js +0 -302
  311. package/src/lib/validators/blazor/blazor-concurrency-analyzer.js +0 -316
  312. package/src/lib/validators/blazor/blazor-state-validator.js +0 -279
  313. package/src/lib/validators/blazor/blazor-validator.js +0 -369
  314. package/src/lib/validators/blazor/index.js +0 -9
@@ -1,814 +1,709 @@
1
- # MORPH-SPEC Template System
2
-
3
- > **Technology-Based Organization for Multi-Stack Reusability**
4
-
5
- ## Overview
6
-
7
- The MORPH-SPEC template system provides **57 production-ready templates** organized by **technology** (not by stack) to enable maximum reusability across current and future stacks.
8
-
9
- **Key Principle:** Templates are grouped by the **technology they use** (dotnet, typescript, sql, azure, docker), allowing new stacks like `vue-firebase` or `angular-mongodb` to reuse existing templates for .NET, TypeScript, SQL, etc.
10
-
11
- ---
12
-
13
- ## 📁 Directory Structure
14
-
15
- ```
16
- framework/templates/
17
- ├── docs/ # Universal documentation templates
18
- │ ├── proposal.md # Feature proposal (required)
19
- │ └── spec.md # Technical specification (required)
20
- │
21
- ├── feature/ # Feature management
22
- │ ├── tasks.md # Implementation tasks (required)
23
- │ ├── decisions.md # Architecture Decision Records (required)
24
- │ └── recap.md # Post-implementation summary (required)
25
- │
26
- ├── context/ # Context generation
27
- │ ├── CONTEXT.md # Project-level context
28
- │ └── CONTEXT-FEATURE.md # Feature-level context
29
- │
30
- ├── code/ # Code templates organized by technology
31
- │ ├── dotnet/
32
- │ │ ├── backend/
33
- │ │ │ ├── service.cs # Service layer
34
- │ │ │ ├── repository.cs # Data access layer
35
- │ │ │ └── test.cs # Unit tests
36
- │ │ ├── frontend/
37
- │ │ │ └── component.razor # Blazor components
38
- │ │ ├── database/
39
- │ │ │ └── migration.cs # EF Core migrations
40
- │ │ ├── jobs/
41
- │ │ │ ├── job.cs # Hangfire background jobs
42
- │ │ │ └── agent.cs # MS Agent Framework agents
43
- │ │ └── contracts/
44
- │ │ ├── contracts.cs # Base contracts
45
- │ │ ├── Commands.cs # CQRS commands
46
- │ │ ├── Queries.cs # CQRS queries
47
- │ │ ├── Entities.cs # Domain entities
48
- │ │ ├── api-contracts.cs # API contracts
49
- │ │ └── README.md # Contracts documentation
50
- │ │
51
- │ ├── typescript/
52
- │ │ └── contracts.ts # TypeScript type definitions
53
- │ │
54
- │ └── sql/
55
- │ ├── supabase-migration.sql # Basic migration
56
- │ ├── supabase-migration.template.sql # Enhanced migration
57
- │ └── rls-policy.sql # Row-level security
58
- │
59
- ├── infrastructure/
60
- │ ├── azure/ # Azure Bicep templates
61
- │ │ ├── main.bicep # Main orchestration (required)
62
- │ │ ├── container-app.bicep # Container Apps
63
- │ │ ├── container-app-env.bicep # Container environment
64
- │ │ ├── app-service.bicep # App Service
65
- │ │ ├── sql-database.bicep # Azure SQL
66
- │ │ ├── storage.bicep # Storage Account
67
- │ │ ├── key-vault.bicep # Key Vault
68
- │ │ ├── app-insights.bicep # Application Insights
69
- │ │ ├── parameters.dev.json # Dev parameters
70
- │ │ ├── parameters.staging.json # Staging parameters
71
- │ │ ├── parameters.prod.json # Prod parameters
72
- │ │ ├── deploy.ps1 # PowerShell deploy
73
- │ │ ├── deploy.sh # Bash deploy
74
- │ │ ├── deploy-checklist.md # Pre-deploy checklist
75
- │ │ ├── azure-pipelines-deploy.yml # Azure DevOps
76
- │ │ ├── Dockerfile.example # Dockerfile example
77
- │ │ └── README.md # Infrastructure docs
78
- │ │
79
- │ ├── docker/ # Docker & EasyPanel
80
- │ │ ├── dockerfile-api.dockerfile # .NET API
81
- │ │ ├── dockerfile-web.dockerfile # Next.js web
82
- │ │ ├── Dockerfile.template # Generic
83
- │ │ ├── docker-compose.template.yml # Compose
84
- │ │ └── easypanel.template.json # EasyPanel config
85
- │ │
86
- │ └── github/ # GitHub Actions CI/CD
87
- │ ├── workflows/ # Reusable workflow templates
88
- │ │ ├── dotnet-build.yml.hbs # .NET restore, build, test
89
- │ │ ├── docker-build-push.yml.hbs # Docker build & push
90
- │ │ ├── deploy-azure-app-service.yml.hbs # Azure App Service deployment
91
- │ │ └── deploy-easypanel.yml.hbs # EasyPanel deployment
92
- │ │
93
- │ ├── actions/ # Composite action templates
94
- │ │ ├── docker-build-push/action.yml.hbs
95
- │ │ ├── health-check/action.yml.hbs
96
- │ │ └── azure-auth/action.yml.hbs
97
- │ │
98
- │ └── README.md # GitHub Actions docs
99
- │
100
- ├── integrations/ # Platform-agnostic integrations
101
- │ ├── asaas-client.cs # Asaas financial API
102
- │ ├── asaas-webhook.cs # Asaas webhooks
103
- │ ├── azure-identity-config.cs # Azure AD/Entra
104
- │ └── clerk-config.cs # Clerk auth
105
- │
106
- ├── ui/ # Design systems
107
- │ ├── design-system.css # CSS tokens
108
- │ ├── FluentDesignTheme.cs # Fluent UI theme
109
- │ └── MudTheme.cs # MudBlazor theme
110
- │
111
- ├── saas/ # Multi-tenant patterns
112
- │ ├── subscription.cs # Subscription model
113
- │ └── tenant.cs # Tenant model
114
- │
115
- ├── examples/ # Reference implementations
116
- │ ├── spec-examples.md # Example specs
117
- │ └── design-system-examples.md # Design system examples
118
- │
119
- └── REGISTRY.json # Template metadata registry
120
- ```
121
-
122
- ---
123
-
124
- ## 🏗️ Technology-Based Architecture
125
-
126
- **Why organize by technology instead of by stack?**
127
-
128
- | Organization | Pros | Cons | Best For |
129
- |--------------|------|------|----------|
130
- | **By Stack** (old v1) | Stack-specific optimizations | Duplicate templates, hard to reuse | Single-stack projects |
131
- | **By Technology** (new v2) | Reusable, DRY, future-proof | Requires stack override mechanism | Multi-stack frameworks |
132
-
133
- **Example:** A `.NET service.cs` template works for both `blazor-azure` and `nextjs-supabase` stacks (both use .NET backend). No need to duplicate!
134
-
135
- **Future-proof:** When we create `vue-firebase` stack, we can reuse:
136
- - `code/typescript/` templates
137
- - `infrastructure/docker/` templates
138
- - `integrations/` templates (Clerk, etc.)
139
-
140
- **Only create NEW templates for Vue-specific code.**
141
-
142
- ---
143
-
144
- ## ⚙️ Template Engine: Handlebars
145
-
146
- All templates use **Handlebars** with **20+ custom helpers**.
147
-
148
- ### Basic Syntax
149
-
150
- ```handlebars
151
- # Feature: {{titleCase FEATURE_NAME}}
152
-
153
- Namespace: {{pascalCase FEATURE_NAME}}
154
-
155
- Created: {{DATE}}
156
- ```
157
-
158
- ### Available Helpers
159
-
160
- | Helper | Input | Output | Usage |
161
- |--------|-------|--------|-------|
162
- | `{{pascalCase str}}` | `user-profile` | `UserProfile` | Class names |
163
- | `{{camelCase str}}` | `user-profile` | `userProfile` | Variable names |
164
- | `{{snakeCase str}}` | `user-profile` | `user_profile` | SQL tables |
165
- | `{{upperSnakeCase str}}` | `user-profile` | `USER_PROFILE` | Constants |
166
- | `{{titleCase str}}` | `user-profile` | `User Profile` | Titles |
167
- | `{{kebabCase str}}` | `User Profile` | `user-profile` | URLs |
168
- | `{{pluralize str}}` | `user` | `users` | Collections |
169
- | `{{singularize str}}` | `users` | `user` | Entities |
170
- | `{{eq a b}}` | `"blazor" "blazor"` | `true` | Conditionals |
171
- | `{{or a b}}` | `false true` | `true` | Logical OR |
172
- | `{{and a b}}` | `true false` | `false` | Logical AND |
173
- | `{{default val fallback}}` | `null "default"` | `"default"` | Defaults |
174
-
175
- ### Conditional Logic
176
-
177
- ```handlebars
178
- {{#if (eq STACK "blazor-azure")}}
179
- // Azure-specific code
180
- {{else if (eq STACK "nextjs-supabase")}}
181
- // Supabase-specific code
182
- {{else}}
183
- // Generic code
184
- {{/if}}
185
- ```
186
-
187
- ### Deprecated: Pre-computed Variables
188
-
189
- **❌ Old (v1):**
190
- ```handlebars
191
- {{pascalCase FEATURE_NAME}} <!-- Pre-computed in bin/render-template.js -->
192
- ```
193
-
194
- **✅ New (v2):**
195
- ```handlebars
196
- {{pascalCase FEATURE_NAME}} <!-- Computed via Handlebars helper -->
197
- ```
198
-
199
- ---
200
-
201
- ## 🛠️ CLI Commands
202
-
203
- ### List All Templates
204
-
205
- ```bash
206
- # List all templates
207
- morph-spec template list
208
-
209
- # Filter by category
210
- morph-spec template list --category code
211
- morph-spec template list --category infrastructure
212
-
213
- # Filter by phase
214
- morph-spec template list --phase implement
215
-
216
- # Filter by stack applicability
217
- morph-spec template list --stack blazor-azure
218
-
219
- # Show only required templates
220
- morph-spec template list --required
221
- ```
222
-
223
- **Output:**
224
- ```
225
- 📦 Universal Templates (9)
226
- proposal Feature Proposal [REQUIRED] [UNIVERSAL] [HBS]
227
- spec Technical Specification [REQUIRED] [UNIVERSAL] [HBS]
228
- tasks Implementation Tasks [REQUIRED] [UNIVERSAL] [HBS]
229
- ...
230
-
231
- 📦 Technology-Based Templates (48)
232
- dotnet-backend-service .NET Service Class [UNIVERSAL] [HBS] (dotnet)
233
- typescript-contracts TypeScript Contracts [UNIVERSAL] [HBS] (typescript)
234
- azure-bicep-main Main Bicep Orchestration [REQUIRED] [UNIVERSAL] [HBS] (bicep)
235
- ...
236
- ```
237
-
238
- ### Show Template Details
239
-
240
- ```bash
241
- # Show metadata
242
- morph-spec template show dotnet-backend-service
243
-
244
- # Show with file preview
245
- morph-spec template show dotnet-backend-service --preview
246
-
247
- # Show with resolved path
248
- morph-spec template show dotnet-backend-service --show-path
249
- ```
250
-
251
- **Output:**
252
- ```
253
- Template: dotnet-backend-service
254
-
255
- 📋 Metadata
256
- ID: dotnet-backend-service
257
- Name: .NET Service Class
258
- Path: code/dotnet/backend/service.cs
259
- Location: framework
260
- Category: code
261
- Phase: implement
262
- Required: No
263
- Technology: dotnet
264
- Applicable Stacks: blazor-azure, nextjs-supabase
265
-
266
- 📝 Description
267
- C# service class template with dependency injection and interface pattern
268
-
269
- 🔑 Variables
270
- {{FEATURE_NAME}}
271
- {{NAMESPACE}}
272
-
273
- 📄 Output Name
274
- {FeatureName}Service.cs
275
-
276
- 💡 Usage Hint
277
- morph-spec template render dotnet-backend-service output.cs '{"FEATURE_NAME":"user-auth","NAMESPACE":"MyApp"}'
278
- ```
279
-
280
- ### Render Template
281
-
282
- ```bash
283
- # Render to file
284
- morph-spec template render dotnet-backend-service UserAuthService.cs '{
285
- "FEATURE_NAME": "user-auth",
286
- "NAMESPACE": "MyApp.Services"
287
- }'
288
-
289
- # Dry run (preview only)
290
- morph-spec template render dotnet-backend-service output.cs '{"FEATURE_NAME":"test"}' --dry-run
291
-
292
- # Auto-resolve path (searches framework → stack override)
293
- morph-spec template render proposal proposal.md '{"FEATURE_NAME":"auth"}' --resolve-path
294
- ```
295
-
296
- **Default Variables (auto-injected):**
297
- - `DATE`: `2026-02-17`
298
- - `YEAR`: `2026`
299
- - `TIMESTAMP`: `2026-02-17T19:38:00.000Z`
300
-
301
- ### Customize Template (Stack Override)
302
-
303
- ```bash
304
- # Copy to stack-specific directory (override framework version)
305
- morph-spec template customize dotnet-backend-service --stack blazor-azure
306
-
307
- # Copy to project-local (cross-stack override)
308
- morph-spec template customize dotnet-backend-service --local
309
-
310
- # Force overwrite if exists
311
- morph-spec template customize dotnet-backend-service --stack blazor-azure --force
312
- ```
313
-
314
- **Output:**
315
- ```
316
- Source: framework/templates/code/dotnet/backend/service.cs
317
- Destination: stacks/blazor-azure/.morph/framework/templates/code/dotnet/backend/service.cs
318
-
319
- ✅ Template copied for customization
320
-
321
- 📝 Next Steps
322
- 1. Edit the template file:
323
- stacks/blazor-azure/.morph/framework/templates/code/dotnet/backend/service.cs
324
-
325
- 2. Template will now be used instead of framework version
326
- (Stack-specific templates take precedence)
327
-
328
- 3. Test rendering:
329
- morph-spec template render dotnet-backend-service output.cs '{"FEATURE_NAME":"test"}'
330
-
331
- ⚠️ Customized templates won't receive framework updates
332
- To get updates: delete customized version and re-run this command
333
- ```
334
-
335
- ---
336
-
337
- ## 🔄 GitHub Actions Templates
338
-
339
- The framework provides reusable GitHub Actions workflows and composite actions for CI/CD automation.
340
-
341
- ### Structure
342
-
343
- ```
344
- infrastructure/github/
345
- ├── workflows/ # Reusable workflow templates
346
- │ ├── dotnet-build.yml.hbs # .NET restore, build, test
347
- │ ├── docker-build-push.yml.hbs # Docker build & push
348
- │ ├── deploy-azure-app-service.yml.hbs # Azure App Service deployment
349
- │ └── deploy-easypanel.yml.hbs # EasyPanel deployment
350
- │
351
- └── actions/ # Composite action templates
352
- ├── docker-build-push/action.yml.hbs
353
- ├── health-check/action.yml.hbs
354
- └── azure-auth/action.yml.hbs
355
- ```
356
-
357
- ### Reusable Workflows vs Composite Actions
358
-
359
- | Type | Purpose | Location | Usage |
360
- |------|---------|----------|-------|
361
- | **Reusable Workflows** | Complete CI/CD pipelines (multi-job) | `workflows/*.yml.hbs` | Called via `uses:` from stack workflows |
362
- | **Composite Actions** | Reusable step logic (single responsibility) | `actions/*/action.yml.hbs` | Called via `uses:` in workflow steps |
363
-
364
- ### Deployment Strategy Difference
365
-
366
- **Blazor-Azure:** Direct .NET publish to Azure App Service (no Docker)
367
- - `dotnet publish` → `azure/webapps-deploy@v2`
368
- - Bicep deploys App Service Plan + App Service
369
- - Authentication: OIDC (Federated Identity)
370
-
371
- **NextJS-Supabase:** Docker containers to EasyPanel
372
- - `docker build` → `docker push` → EasyPanel webhook
373
- - Multi-service deployment (API + Web)
374
- - Registry: GitHub Container Registry (ghcr.io)
375
-
376
- ### Template Rendering
377
-
378
- **GitHub Actions Constraint:**
379
- - ❌ GitHub Actions CANNOT reference parent directories (`../../../../framework/`)
380
- - ✅ Solution: Framework templates are **rendered** into each stack's `.github/` directory
381
- - Rendered `.yml` files are **committed** to repos (not `.yml.hbs` templates)
382
-
383
- **Rendering Process:**
384
- ```bash
385
- # Render all GitHub Actions templates for a stack (manual for now)
386
- # Future: morph-spec template render github-workflows --stack blazor-azure
387
- ```
388
-
389
- ### Handlebars Variables
390
-
391
- - `{{APP_NAME}}` - Application name from config.json
392
- - `{{DOTNET_VERSION}}` - .NET SDK version
393
- - `{{GITHUB_OWNER}}` - GitHub organization/user
394
- - `{{kebabCase APP_NAME}}` - Docker image name format
395
- - `${{{{ inputs.* }}}}` - GitHub Actions runtime syntax (escaped with `{{{{raw}}}}`)
396
-
397
- ### Authentication & Secrets
398
-
399
- **Azure (Blazor-Azure):**
400
- ```yaml
401
- # OIDC (Federated Identity) - Recommended
402
- - uses: azure/login@v1
403
- with:
404
- client-id: ${{{{ secrets.AZURE_CLIENT_ID }}}}
405
- tenant-id: ${{{{ secrets.AZURE_TENANT_ID }}}}
406
- subscription-id: ${{{{ secrets.AZURE_SUBSCRIPTION_ID }}}}
407
- ```
408
-
409
- **Docker Registry (NextJS-Supabase):**
410
- ```yaml
411
- # GitHub Container Registry (ghcr.io)
412
- - uses: docker/login-action@v3
413
- with:
414
- registry: ghcr.io
415
- username: ${{{{ github.actor }}}}
416
- password: ${{{{ secrets.GITHUB_TOKEN }}}}
417
- ```
418
-
419
- **GitHub Secrets to Configure:**
420
- - Blazor-Azure: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_SUBSCRIPTION_ID`
421
- - NextJS-Supabase: `GITHUB_TOKEN` (auto), `EASYPANEL_API_TOKEN`
422
-
423
- ### Example: Blazor-Azure CI/CD
424
-
425
- **CI Build Workflow** (`stacks/blazor-azure/.morph/framework/templates/infrastructure/github/workflows/ci-build.yml.hbs`):
426
- ```yaml
427
- name: CI Build
428
-
429
- on:
430
- pull_request:
431
- branches: [main, staging]
432
-
433
- jobs:
434
- build:
435
- uses: ./.github/workflows/dotnet-build.yml # Framework template (rendered)
436
- with:
437
- dotnet-version: '{{DOTNET_VERSION}}'
438
- run-tests: true
439
-
440
- security:
441
- runs-on: ubuntu-latest
442
- steps:
443
- - uses: actions/checkout@v4
444
- - name: Check vulnerable packages
445
- run: dotnet list package --vulnerable --include-transitive
446
- ```
447
-
448
- **Production Deployment** (`cd-prod.yml.hbs`):
449
- ```yaml
450
- name: Deploy to Production
451
-
452
- on:
453
- push:
454
- branches: [main]
455
-
456
- jobs:
457
- build:
458
- uses: ./.github/workflows/dotnet-build.yml
459
- with:
460
- dotnet-version: '{{DOTNET_VERSION}}'
461
- secrets: inherit
462
-
463
- deploy:
464
- needs: build
465
- uses: ./.github/workflows/deploy-azure-app-service.yml
466
- with:
467
- environment: 'production'
468
- resource-group: 'rg-{{kebabCase APP_NAME}}-prod'
469
- app-service-name: 'app-{{kebabCase APP_NAME}}-prod'
470
- secrets: inherit
471
- ```
472
-
473
- ### Stack-Specific Overrides
474
-
475
- Stack-specific workflow templates in:
476
- - `stacks/blazor-azure/.morph/framework/templates/infrastructure/github/workflows/`
477
- - `stacks/nextjs-supabase/.morph/framework/templates/infrastructure/github/workflows/`
478
-
479
- **Resolution Order:**
480
- 1. Project-local: `.morph/framework/templates/infrastructure/github/workflows/ci-build.yml.hbs`
481
- 2. Stack default: `stacks/{stack}/.morph/framework/templates/infrastructure/github/workflows/ci-build.yml.hbs`
482
- 3. Framework fallback: `framework/templates/infrastructure/github/workflows/dotnet-build.yml.hbs`
483
-
484
- ---
485
-
486
- ## 🔀 Stack Override Mechanism
487
-
488
- **Resolution Order:**
489
-
490
- 1. **Stack-specific override** (highest priority)
491
- - `stacks/{stack}/.morph/framework/templates/code/dotnet/backend/service.cs`
492
-
493
- 2. **Project-local override** (medium priority)
494
- - `.morph/framework/templates/code/dotnet/backend/service.cs`
495
-
496
- 3. **Framework template** (fallback)
497
- - `framework/templates/code/dotnet/backend/service.cs`
498
-
499
- **Use Cases for Overrides:**
500
-
501
- | Scenario | Override Location | Example |
502
- |----------|-------------------|---------|
503
- | Stack-specific tweak | `stacks/{stack}/.morph/framework/templates/` | Blazor uses different DI pattern |
504
- | Project-wide customization | `.morph/framework/templates/` | Company-specific code style |
505
- | Use framework default | None (no override) | Standard templates work fine |
506
-
507
- **Example:**
508
-
509
- ```bash
510
- # Create stack override for Blazor
511
- morph-spec template customize dotnet-backend-service --stack blazor-azure
512
-
513
- # Edit the override
514
- code stacks/blazor-azure/.morph/framework/templates/code/dotnet/backend/service.cs
515
-
516
- # Now all renders for blazor-azure will use the override
517
- morph-spec template render dotnet-backend-service UserService.cs '...' --stack blazor-azure
518
- ```
519
-
520
- ---
521
-
522
- ## 📊 Template Registry (REGISTRY.json)
523
-
524
- The `REGISTRY.json` file is the **single source of truth** for all template metadata.
525
-
526
- ### Schema
527
-
528
- ```json
529
- {
530
- "version": "2.0.0",
531
- "templates": [
532
- {
533
- "id": "dotnet-backend-service",
534
- "name": ".NET Service Class",
535
- "path": "code/dotnet/backend/service.cs",
536
- "location": "framework",
537
- "category": "code",
538
- "phase": "implement",
539
- "required": false,
540
- "technology": "dotnet",
541
- "applicableStacks": ["blazor-azure", "nextjs-supabase"],
542
- "engine": "handlebars",
543
- "placeholders": ["FEATURE_NAME", "NAMESPACE"],
544
- "outputName": "{FeatureName}Service.cs",
545
- "deprecated": false
546
- }
547
- ]
548
- }
549
- ```
550
-
551
- ### Discovery API
552
-
553
- ```javascript
554
- import {
555
- getAllTemplates,
556
- getTemplateById,
557
- getTemplatesByCategory,
558
- getTemplatesByTechnology,
559
- resolveTemplatePathById
560
- } from '../src/lib/template-registry.js';
561
-
562
- // Get all templates
563
- const all = getAllTemplates();
564
-
565
- // Get specific template
566
- const service = getTemplateById('dotnet-backend-service');
567
-
568
- // Filter by category
569
- const codeTemplates = getTemplatesByCategory('code');
570
-
571
- // Filter by technology
572
- const dotnetTemplates = getTemplatesByTechnology('dotnet');
573
-
574
- // Resolve path with fallback
575
- const path = resolveTemplatePathById('dotnet-backend-service', '/project', 'blazor-azure');
576
- // Returns: framework/templates/code/dotnet/backend/service.cs
577
- // Or: stacks/blazor-azure/.morph/framework/templates/code/dotnet/backend/service.cs (if override exists)
578
- ```
579
-
580
- ---
581
-
582
- ## 🚀 Creating New Templates
583
-
584
- ### 1. Create Template File
585
-
586
- ```bash
587
- # For .NET templates
588
- touch framework/templates/code/dotnet/backend/my-template.cs
589
-
590
- # For infrastructure templates
591
- touch framework/templates/infrastructure/azure/my-resource.bicep
592
- ```
593
-
594
- ### 2. Add Handlebars Placeholders
595
-
596
- ```handlebars
597
- namespace {{pascalCase NAMESPACE}};
598
-
599
- public class {{pascalCase FEATURE_NAME}}Service
600
- {
601
- // TODO: Implement {{titleCase FEATURE_NAME}} logic
602
- }
603
- ```
604
-
605
- ### 3. Register in REGISTRY.json
606
-
607
- ```json
608
- {
609
- "id": "dotnet-backend-my-template",
610
- "name": "My Custom Template",
611
- "path": "code/dotnet/backend/my-template.cs",
612
- "location": "framework",
613
- "category": "code",
614
- "phase": "implement",
615
- "required": false,
616
- "technology": "dotnet",
617
- "applicableStacks": ["blazor-azure"],
618
- "engine": "handlebars",
619
- "placeholders": ["FEATURE_NAME", "NAMESPACE"],
620
- "outputName": "{FeatureName}MyTemplate.cs",
621
- "deprecated": false
622
- }
623
- ```
624
-
625
- ### 4. Test Rendering
626
-
627
- ```bash
628
- morph-spec template render dotnet-backend-my-template output.cs '{
629
- "FEATURE_NAME": "user-auth",
630
- "NAMESPACE": "MyApp.Services"
631
- }'
632
- ```
633
-
634
- ---
635
-
636
- ## 📦 Migration Guide: v1 → v2
637
-
638
- ### What Changed
639
-
640
- | Aspect | v1 (Stack-Based) | v2 (Technology-Based) |
641
- |--------|------------------|----------------------|
642
- | **Location** | `stacks/{stack}/.morph/framework/templates/` | `framework/templates/{technology}/` |
643
- | **Organization** | By stack (blazor-azure, nextjs-supabase) | By technology (dotnet, azure, docker) |
644
- | **Duplication** | High (proposal.md × 2, decisions.md × 2) | Low (shared templates in framework) |
645
- | **Template Engine** | 3 engines (custom, Handlebars, mixed) | 1 engine (Handlebars with helpers) |
646
- | **Pre-computed Variables** | `{{pascalCase FEATURE_NAME}}` | `{{pascalCase FEATURE_NAME}}` (helpers) |
647
- | **Registry** | None (hardcoded paths) | `REGISTRY.json` (centralized metadata) |
648
- | **CLI** | None | `morph-spec template list/show/render/customize` |
649
- | **Future Stacks** | Must copy templates | Reuse existing technology templates |
650
-
651
- ### Breaking Changes
652
-
653
- **1. Template Paths**
654
-
655
- ```diff
656
- - stacks/blazor-azure/.morph/framework/templates/service.cs
657
- + framework/templates/code/dotnet/backend/service.cs
658
-
659
- - stacks/blazor-azure/.morph/framework/templates/infra/main.bicep
660
- + framework/templates/infrastructure/azure/main.bicep
661
-
662
- - stacks/nextjs-supabase/.morph/framework/templates/dockerfile-web.dockerfile
663
- + framework/templates/infrastructure/docker/dockerfile-web.dockerfile
664
- ```
665
-
666
- **2. Pre-computed Variables**
667
-
668
- ```diff
669
- - {{pascalCase FEATURE_NAME}}
670
- + {{pascalCase FEATURE_NAME}}
671
-
672
- - {{camelCase FEATURE_NAME}}
673
- + {{camelCase FEATURE_NAME}}
674
-
675
- - {{snakeCase FEATURE_NAME}}
676
- + {{snakeCase FEATURE_NAME}}
677
- ```
678
-
679
- **3. Template Resolution**
680
-
681
- ```javascript
682
- // Old (v1)
683
- const templatePath = join(resolveTemplatesDir(projectPath), 'service.cs');
684
-
685
- // New (v2)
686
- const templatePath = resolveTemplatePath(projectPath, 'code/dotnet/backend/service.cs', stackId);
687
- // Automatically falls back: stack override → framework
688
- ```
689
-
690
- ### Migration Steps
691
-
692
- **Step 1:** Update code to use `resolveTemplatePath()`
693
-
694
- ```javascript
695
- import { resolveTemplatePath } from '../lib/stack-resolver.js';
696
-
697
- // Before
698
- const path = join(resolveTemplatesDir(process.cwd()), 'service.cs');
699
-
700
- // After
701
- const path = resolveTemplatePath(process.cwd(), 'code/dotnet/backend/service.cs', 'blazor-azure');
702
- ```
703
-
704
- **Step 2:** Update template syntax to Handlebars
705
-
706
- ```handlebars
707
- <!-- Before -->
708
- namespace {{NAMESPACE}};
709
- public class {{pascalCase FEATURE_NAME}}Service { }
710
-
711
- <!-- After -->
712
- namespace {{pascalCase NAMESPACE}};
713
- public class {{pascalCase FEATURE_NAME}}Service { }
714
- ```
715
-
716
- **Step 3:** Use CLI commands instead of hardcoded paths
717
-
718
- ```bash
719
- # Before (hardcoded)
720
- cp framework/templates/proposal.md .morph/features/user-auth/proposal.md
721
-
722
- # After (CLI)
723
- morph-spec template render proposal .morph/features/user-auth/proposal.md '{
724
- "FEATURE_NAME": "user-auth"
725
- }'
726
- ```
727
-
728
- ---
729
-
730
- ## 🎯 Best Practices
731
-
732
- ### 1. **Use Helpers, Not Pre-computed Variables**
733
-
734
- ```handlebars
735
- ✅ GOOD:
736
- {{pascalCase FEATURE_NAME}}Service
737
-
738
- ❌ BAD:
739
- {{pascalCase FEATURE_NAME}}Service // Deprecated, won't work
740
- ```
741
-
742
- ### 2. **Keep Templates Technology-Agnostic**
743
-
744
- ```handlebars
745
- ✅ GOOD: code/dotnet/backend/service.cs
746
- Works for: blazor-azure, nextjs-supabase, future-dotnet-stack
747
-
748
- ❌ BAD: code/blazor/service.cs
749
- Locked to Blazor only
750
- ```
751
-
752
- ### 3. **Use Stack Conditionals for Differences**
753
-
754
- ```handlebars
755
- {{#if (eq STACK "blazor-azure")}}
756
- // Azure-specific implementation
757
- {{else if (eq STACK "nextjs-supabase")}}
758
- // Supabase-specific implementation
759
- {{else}}
760
- // Generic implementation
761
- {{/if}}
762
- ```
763
-
764
- ### 4. **Document Applicability in Registry**
765
-
766
- ```json
767
- {
768
- "technology": "dotnet",
769
- "applicableStacks": ["blazor-azure", "nextjs-supabase"],
770
- "description": "Works with any .NET backend stack"
771
- }
772
- ```
773
-
774
- ### 5. **Override Only When Necessary**
775
-
776
- ```bash
777
- # Only customize if framework template doesn't meet needs
778
- morph-spec template customize dotnet-backend-service --stack blazor-azure
779
-
780
- # Otherwise, use framework version (gets updates automatically)
781
- morph-spec template render dotnet-backend-service output.cs '...'
782
- ```
783
-
784
- ---
785
-
786
- ## 📚 References
787
-
788
- - **Template Registry API:** [`src/lib/template-registry.js`](../../src/lib/template-registry.js)
789
- - **Template Renderer:** [`src/lib/template-renderer.js`](../../src/lib/template-renderer.js)
790
- - **Stack Resolver:** [`src/lib/stack-resolver.js`](../../src/lib/stack-resolver.js)
791
- - **CLI Commands:** [`src/commands/template-*.js`](../../src/commands/)
792
- - **Handlebars Docs:** https://handlebarsjs.com/
793
-
794
- ---
795
-
796
- ## 🤝 Contributing
797
-
798
- ### Adding New Technology
799
-
800
- 1. Create directory: `framework/templates/code/{technology}/`
801
- 2. Add templates with Handlebars syntax
802
- 3. Register in `REGISTRY.json` with `"technology": "{technology}"`
803
- 4. Test with `morph-spec template render`
804
- 5. Document in this README
805
-
806
- ### Deprecating Templates
807
-
808
- 1. Add `"deprecated": true` to `REGISTRY.json`
809
- 2. Add `"deprecationReason": "Reason here"`
810
- 3. Keep file for backward compatibility or remove after major version bump
811
-
812
- ---
813
-
814
- **MORPH-SPEC Template System v2.0** - Technology-Based, Future-Proof, DRY ✨
1
+ # MORPH-SPEC Template System
2
+
3
+ > **Technology-Based Organization for Multi-Stack Reusability**
4
+
5
+ ## Overview
6
+
7
+ The MORPH-SPEC template system provides **57 production-ready templates** organized by **technology** (not by stack) to enable maximum reusability across current and future stacks.
8
+
9
+ **Key Principle:** Templates are grouped by the **technology they use** (dotnet, typescript, sql, docker), allowing new stacks like `vue-firebase` or `angular-mongodb` to reuse existing templates for .NET, TypeScript, SQL, etc.
10
+
11
+ ---
12
+
13
+ ## 📁 Directory Structure
14
+
15
+ ```
16
+ framework/templates/
17
+ ├── docs/ # Universal documentation templates
18
+ │ ├── proposal.md # Feature proposal (required)
19
+ │ └── spec.md # Technical specification (required)
20
+ │
21
+ ├── feature/ # Feature management
22
+ │ ├── tasks.md # Implementation tasks (required)
23
+ │ ├── decisions.md # Architecture Decision Records (required)
24
+ │ └── recap.md # Post-implementation summary (required)
25
+ │
26
+ ├── context/ # Context generation
27
+ │ ├── CONTEXT.md # Project-level context
28
+ │ └── CONTEXT-FEATURE.md # Feature-level context
29
+ │
30
+ ├── code/ # Code templates organized by technology
31
+ │ ├── dotnet/
32
+ │ │ ├── backend/
33
+ │ │ │ ├── service.cs # Service layer
34
+ │ │ │ ├── repository.cs # Data access layer
35
+ │ │ │ └── test.cs # Unit tests
36
+ │ │ ├── database/
37
+ │ │ │ └── migration.cs # EF Core migrations
38
+ │ │ ├── jobs/
39
+ │ │ │ ├── job.cs # Hangfire background jobs
40
+ │ │ │ └── agent.cs # MS Agent Framework agents
41
+ │ │ └── contracts/
42
+ │ │ ├── contracts.cs # Base contracts
43
+ │ │ ├── Commands.cs # CQRS commands
44
+ │ │ ├── Queries.cs # CQRS queries
45
+ │ │ ├── Entities.cs # Domain entities
46
+ │ │ ├── api-contracts.cs # API contracts
47
+ │ │ └── README.md # Contracts documentation
48
+ │ │
49
+ │ ├── typescript/
50
+ │ │ └── contracts.ts # TypeScript type definitions
51
+ │ │
52
+ │ └── sql/
53
+ │ ├── supabase-migration.sql # Basic migration
54
+ │ ├── supabase-migration.template.sql # Enhanced migration
55
+ │ └── rls-policy.sql # Row-level security
56
+ │
57
+ ├── infrastructure/
58
+ │ ├── docker/ # Docker & EasyPanel
59
+ │ │ ├── dockerfile-api.dockerfile # .NET API
60
+ │ │ ├── dockerfile-web.dockerfile # Next.js web
61
+ │ │ ├── Dockerfile.template # Generic
62
+ │ │ ├── docker-compose.template.yml # Compose
63
+ │ │ └── easypanel.template.json # EasyPanel config
64
+ │ │
65
+ │ └── github/ # GitHub Actions CI/CD
66
+ │ ├── workflows/ # Reusable workflow templates
67
+ │ │ ├── dotnet-build.yml.hbs # .NET restore, build, test
68
+ │ │ ├── docker-build-push.yml.hbs # Docker build & push
69
+ │ │ └── deploy-easypanel.yml.hbs # EasyPanel deployment
70
+ │ │
71
+ │ ├── actions/ # Composite action templates
72
+ │ │ ├── docker-build-push/action.yml.hbs
73
+ │ │ └── health-check/action.yml.hbs
74
+ │ │
75
+ │ └── README.md # GitHub Actions docs
76
+ │
77
+ ├── integrations/ # Platform-agnostic integrations
78
+ │ ├── asaas-client.cs # Asaas financial API
79
+ │ ├── asaas-webhook.cs # Asaas webhooks
80
+ │ └── clerk-config.cs # Clerk auth
81
+ │
82
+ ├── ui/ # Design systems
83
+ │ └── design-system.css # CSS tokens
84
+ │
85
+ ├── saas/ # Multi-tenant patterns
86
+ │
87
+ ├── examples/ # Reference implementations
88
+ │ ├── spec-examples.md # Example specs
89
+ │ └── design-system-examples.md # Design system examples
90
+ │
91
+ └── REGISTRY.json # Template metadata registry
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 🏗️ Technology-Based Architecture
97
+
98
+ **Why organize by technology instead of by stack?**
99
+
100
+ | Organization | Pros | Cons | Best For |
101
+ |--------------|------|------|----------|
102
+ | **By Stack** (old v1) | Stack-specific optimizations | Duplicate templates, hard to reuse | Single-stack projects |
103
+ | **By Technology** (new v2) | Reusable, DRY, future-proof | Requires stack override mechanism | Multi-stack frameworks |
104
+
105
+ **Example:** A `.NET service.cs` template works for both `dotnet-nextjs` and `nextjs-supabase` stacks (both use .NET backend). No need to duplicate!
106
+
107
+ **Future-proof:** When we create `vue-firebase` stack, we can reuse:
108
+ - `code/typescript/` templates
109
+ - `infrastructure/docker/` templates
110
+ - `integrations/` templates (Clerk, etc.)
111
+
112
+ **Only create NEW templates for Vue-specific code.**
113
+
114
+ ---
115
+
116
+ ## ⚙️ Template Engine: Handlebars
117
+
118
+ All templates use **Handlebars** with **20+ custom helpers**.
119
+
120
+ ### Basic Syntax
121
+
122
+ ```handlebars
123
+ # Feature: {{titleCase FEATURE_NAME}}
124
+
125
+ Namespace: {{pascalCase FEATURE_NAME}}
126
+
127
+ Created: {{DATE}}
128
+ ```
129
+
130
+ ### Available Helpers
131
+
132
+ | Helper | Input | Output | Usage |
133
+ |--------|-------|--------|-------|
134
+ | `{{pascalCase str}}` | `user-profile` | `UserProfile` | Class names |
135
+ | `{{camelCase str}}` | `user-profile` | `userProfile` | Variable names |
136
+ | `{{snakeCase str}}` | `user-profile` | `user_profile` | SQL tables |
137
+ | `{{upperSnakeCase str}}` | `user-profile` | `USER_PROFILE` | Constants |
138
+ | `{{titleCase str}}` | `user-profile` | `User Profile` | Titles |
139
+ | `{{kebabCase str}}` | `User Profile` | `user-profile` | URLs |
140
+ | `{{pluralize str}}` | `user` | `users` | Collections |
141
+ | `{{singularize str}}` | `users` | `user` | Entities |
142
+ | `{{eq a b}}` | `"nextjs" "nextjs"` | `true` | Conditionals |
143
+ | `{{or a b}}` | `false true` | `true` | Logical OR |
144
+ | `{{and a b}}` | `true false` | `false` | Logical AND |
145
+ | `{{default val fallback}}` | `null "default"` | `"default"` | Defaults |
146
+
147
+ ### Conditional Logic
148
+
149
+ ```handlebars
150
+ {{#if (eq STACK "nextjs-supabase")}}
151
+ // Supabase-specific code
152
+ {{else}}
153
+ // Generic code
154
+ {{/if}}
155
+ ```
156
+
157
+ ### Deprecated: Pre-computed Variables
158
+
159
+ **❌ Old (v1):**
160
+ ```handlebars
161
+ {{pascalCase FEATURE_NAME}} <!-- Pre-computed in bin/render-template.js -->
162
+ ```
163
+
164
+ **✅ New (v2):**
165
+ ```handlebars
166
+ {{pascalCase FEATURE_NAME}} <!-- Computed via Handlebars helper -->
167
+ ```
168
+
169
+ ---
170
+
171
+ ## 🛠️ CLI Commands
172
+
173
+ ### List All Templates
174
+
175
+ ```bash
176
+ # List all templates
177
+ morph-spec template list
178
+
179
+ # Filter by category
180
+ morph-spec template list --category code
181
+ morph-spec template list --category infrastructure
182
+
183
+ # Filter by phase
184
+ morph-spec template list --phase implement
185
+
186
+ # Filter by stack applicability
187
+ morph-spec template list --stack dotnet-nextjs
188
+
189
+ # Show only required templates
190
+ morph-spec template list --required
191
+ ```
192
+
193
+ **Output:**
194
+ ```
195
+ 📦 Universal Templates (9)
196
+ proposal Feature Proposal [REQUIRED] [UNIVERSAL] [HBS]
197
+ spec Technical Specification [REQUIRED] [UNIVERSAL] [HBS]
198
+ tasks Implementation Tasks [REQUIRED] [UNIVERSAL] [HBS]
199
+ ...
200
+
201
+ 📦 Technology-Based Templates (48)
202
+ dotnet-backend-service .NET Service Class [UNIVERSAL] [HBS] (dotnet)
203
+ typescript-contracts TypeScript Contracts [UNIVERSAL] [HBS] (typescript)
204
+ ...
205
+ ```
206
+
207
+ ### Show Template Details
208
+
209
+ ```bash
210
+ # Show metadata
211
+ morph-spec template show dotnet-backend-service
212
+
213
+ # Show with file preview
214
+ morph-spec template show dotnet-backend-service --preview
215
+
216
+ # Show with resolved path
217
+ morph-spec template show dotnet-backend-service --show-path
218
+ ```
219
+
220
+ **Output:**
221
+ ```
222
+ Template: dotnet-backend-service
223
+
224
+ 📋 Metadata
225
+ ID: dotnet-backend-service
226
+ Name: .NET Service Class
227
+ Path: code/dotnet/backend/service.cs
228
+ Location: framework
229
+ Category: code
230
+ Phase: implement
231
+ Required: No
232
+ Technology: dotnet
233
+ Applicable Stacks: dotnet-nextjs, nextjs-supabase
234
+
235
+ 📝 Description
236
+ C# service class template with dependency injection and interface pattern
237
+
238
+ 🔑 Variables
239
+ {{FEATURE_NAME}}
240
+ {{NAMESPACE}}
241
+
242
+ 📄 Output Name
243
+ {FeatureName}Service.cs
244
+
245
+ 💡 Usage Hint
246
+ morph-spec template render dotnet-backend-service output.cs '{"FEATURE_NAME":"user-auth","NAMESPACE":"MyApp"}'
247
+ ```
248
+
249
+ ### Render Template
250
+
251
+ ```bash
252
+ # Render to file
253
+ morph-spec template render dotnet-backend-service UserAuthService.cs '{
254
+ "FEATURE_NAME": "user-auth",
255
+ "NAMESPACE": "MyApp.Services"
256
+ }'
257
+
258
+ # Dry run (preview only)
259
+ morph-spec template render dotnet-backend-service output.cs '{"FEATURE_NAME":"test"}' --dry-run
260
+
261
+ # Auto-resolve path (searches framework → stack override)
262
+ morph-spec template render proposal proposal.md '{"FEATURE_NAME":"auth"}' --resolve-path
263
+ ```
264
+
265
+ **Default Variables (auto-injected):**
266
+ - `DATE`: `2026-02-17`
267
+ - `YEAR`: `2026`
268
+ - `TIMESTAMP`: `2026-02-17T19:38:00.000Z`
269
+
270
+ ### Customize Template (Stack Override)
271
+
272
+ ```bash
273
+ # Copy to stack-specific directory (override framework version)
274
+ morph-spec template customize dotnet-backend-service --stack dotnet-nextjs
275
+
276
+ # Copy to project-local (cross-stack override)
277
+ morph-spec template customize dotnet-backend-service --local
278
+
279
+ # Force overwrite if exists
280
+ morph-spec template customize dotnet-backend-service --stack dotnet-nextjs --force
281
+ ```
282
+
283
+ **Output:**
284
+ ```
285
+ Source: framework/templates/code/dotnet/backend/service.cs
286
+ Destination: stacks/dotnet-nextjs/.morph/framework/templates/code/dotnet/backend/service.cs
287
+
288
+ ✅ Template copied for customization
289
+
290
+ 📝 Next Steps
291
+ 1. Edit the template file:
292
+ stacks/dotnet-nextjs/.morph/framework/templates/code/dotnet/backend/service.cs
293
+
294
+ 2. Template will now be used instead of framework version
295
+ (Stack-specific templates take precedence)
296
+
297
+ 3. Test rendering:
298
+ morph-spec template render dotnet-backend-service output.cs '{"FEATURE_NAME":"test"}'
299
+
300
+ ⚠️ Customized templates won't receive framework updates
301
+ To get updates: delete customized version and re-run this command
302
+ ```
303
+
304
+ ---
305
+
306
+ ## 🔄 GitHub Actions Templates
307
+
308
+ The framework provides reusable GitHub Actions workflows and composite actions for CI/CD automation.
309
+
310
+ ### Structure
311
+
312
+ ```
313
+ infrastructure/github/
314
+ ├── workflows/ # Reusable workflow templates
315
+ │ ├── dotnet-build.yml.hbs # .NET restore, build, test
316
+ │ ├── docker-build-push.yml.hbs # Docker build & push
317
+ │ └── deploy-easypanel.yml.hbs # EasyPanel deployment
318
+ │
319
+ └── actions/ # Composite action templates
320
+ ├── docker-build-push/action.yml.hbs
321
+ └── health-check/action.yml.hbs
322
+ ```
323
+
324
+ ### Reusable Workflows vs Composite Actions
325
+
326
+ | Type | Purpose | Location | Usage |
327
+ |------|---------|----------|-------|
328
+ | **Reusable Workflows** | Complete CI/CD pipelines (multi-job) | `workflows/*.yml.hbs` | Called via `uses:` from stack workflows |
329
+ | **Composite Actions** | Reusable step logic (single responsibility) | `actions/*/action.yml.hbs` | Called via `uses:` in workflow steps |
330
+
331
+ ### Deployment Strategy Difference
332
+
333
+ **NextJS-Supabase:** Docker containers to EasyPanel
334
+ - `docker build` → `docker push` → EasyPanel webhook
335
+ - Multi-service deployment (API + Web)
336
+ - Registry: GitHub Container Registry (ghcr.io)
337
+
338
+ ### Template Rendering
339
+
340
+ **GitHub Actions Constraint:**
341
+ - ❌ GitHub Actions CANNOT reference parent directories (`../../../../framework/`)
342
+ - ✅ Solution: Framework templates are **rendered** into each stack's `.github/` directory
343
+ - Rendered `.yml` files are **committed** to repos (not `.yml.hbs` templates)
344
+
345
+ **Rendering Process:**
346
+ ```bash
347
+ # Render all GitHub Actions templates for a stack (manual for now)
348
+ # Future: morph-spec template render github-workflows --stack dotnet-nextjs
349
+ ```
350
+
351
+ ### Handlebars Variables
352
+
353
+ - `{{APP_NAME}}` - Application name from config.json
354
+ - `{{DOTNET_VERSION}}` - .NET SDK version
355
+ - `{{GITHUB_OWNER}}` - GitHub organization/user
356
+ - `{{kebabCase APP_NAME}}` - Docker image name format
357
+ - `${{{{ inputs.* }}}}` - GitHub Actions runtime syntax (escaped with `{{{{raw}}}}`)
358
+
359
+ ### Authentication & Secrets
360
+
361
+ **Docker Registry (NextJS-Supabase):**
362
+ ```yaml
363
+ # GitHub Container Registry (ghcr.io)
364
+ - uses: docker/login-action@v3
365
+ with:
366
+ registry: ghcr.io
367
+ username: ${{{{ github.actor }}}}
368
+ password: ${{{{ secrets.GITHUB_TOKEN }}}}
369
+ ```
370
+
371
+ **GitHub Secrets to Configure:**
372
+ - NextJS-Supabase: `GITHUB_TOKEN` (auto), `EASYPANEL_API_TOKEN`
373
+
374
+ ### Stack-Specific Overrides
375
+
376
+ Stack-specific workflow templates in:
377
+ - `stacks/nextjs-supabase/.morph/framework/templates/infrastructure/github/workflows/`
378
+
379
+ **Resolution Order:**
380
+ 1. Project-local: `.morph/framework/templates/infrastructure/github/workflows/ci-build.yml.hbs`
381
+ 2. Stack default: `stacks/{stack}/.morph/framework/templates/infrastructure/github/workflows/ci-build.yml.hbs`
382
+ 3. Framework fallback: `framework/templates/infrastructure/github/workflows/dotnet-build.yml.hbs`
383
+
384
+ ---
385
+
386
+ ## 🔀 Stack Override Mechanism
387
+
388
+ **Resolution Order:**
389
+
390
+ 1. **Stack-specific override** (highest priority)
391
+ - `stacks/{stack}/.morph/framework/templates/code/dotnet/backend/service.cs`
392
+
393
+ 2. **Project-local override** (medium priority)
394
+ - `.morph/framework/templates/code/dotnet/backend/service.cs`
395
+
396
+ 3. **Framework template** (fallback)
397
+ - `framework/templates/code/dotnet/backend/service.cs`
398
+
399
+ **Use Cases for Overrides:**
400
+
401
+ | Scenario | Override Location | Example |
402
+ |----------|-------------------|---------|
403
+ | Stack-specific tweak | `stacks/{stack}/.morph/framework/templates/` | Stack uses different DI pattern |
404
+ | Project-wide customization | `.morph/framework/templates/` | Company-specific code style |
405
+ | Use framework default | None (no override) | Standard templates work fine |
406
+
407
+ **Example:**
408
+
409
+ ```bash
410
+ # Create stack override
411
+ morph-spec template customize dotnet-backend-service --stack dotnet-nextjs
412
+
413
+ # Edit the override
414
+ code stacks/dotnet-nextjs/.morph/framework/templates/code/dotnet/backend/service.cs
415
+
416
+ # Now all renders for dotnet-nextjs will use the override
417
+ morph-spec template render dotnet-backend-service UserService.cs '...' --stack dotnet-nextjs
418
+ ```
419
+
420
+ ---
421
+
422
+ ## 📊 Template Registry (REGISTRY.json)
423
+
424
+ The `REGISTRY.json` file is the **single source of truth** for all template metadata.
425
+
426
+ ### Schema
427
+
428
+ ```json
429
+ {
430
+ "version": "2.0.0",
431
+ "templates": [
432
+ {
433
+ "id": "dotnet-backend-service",
434
+ "name": ".NET Service Class",
435
+ "path": "code/dotnet/backend/service.cs",
436
+ "location": "framework",
437
+ "category": "code",
438
+ "phase": "implement",
439
+ "required": false,
440
+ "technology": "dotnet",
441
+ "applicableStacks": ["dotnet-nextjs", "nextjs-supabase"],
442
+ "engine": "handlebars",
443
+ "placeholders": ["FEATURE_NAME", "NAMESPACE"],
444
+ "outputName": "{FeatureName}Service.cs",
445
+ "deprecated": false
446
+ }
447
+ ]
448
+ }
449
+ ```
450
+
451
+ ### Discovery API
452
+
453
+ ```javascript
454
+ import {
455
+ getAllTemplates,
456
+ getTemplateById,
457
+ getTemplatesByCategory,
458
+ getTemplatesByTechnology,
459
+ resolveTemplatePathById
460
+ } from '../src/lib/template-registry.js';
461
+
462
+ // Get all templates
463
+ const all = getAllTemplates();
464
+
465
+ // Get specific template
466
+ const service = getTemplateById('dotnet-backend-service');
467
+
468
+ // Filter by category
469
+ const codeTemplates = getTemplatesByCategory('code');
470
+
471
+ // Filter by technology
472
+ const dotnetTemplates = getTemplatesByTechnology('dotnet');
473
+
474
+ // Resolve path with fallback
475
+ const path = resolveTemplatePathById('dotnet-backend-service', '/project', 'dotnet-nextjs');
476
+ // Returns: framework/templates/code/dotnet/backend/service.cs
477
+ // Or: stacks/dotnet-nextjs/.morph/framework/templates/code/dotnet/backend/service.cs (if override exists)
478
+ ```
479
+
480
+ ---
481
+
482
+ ## 🚀 Creating New Templates
483
+
484
+ ### 1. Create Template File
485
+
486
+ ```bash
487
+ # For .NET templates
488
+ touch framework/templates/code/dotnet/backend/my-template.cs
489
+
490
+ # For infrastructure templates
491
+ touch framework/templates/infrastructure/docker/my-resource.dockerfile
492
+ ```
493
+
494
+ ### 2. Add Handlebars Placeholders
495
+
496
+ ```handlebars
497
+ namespace {{pascalCase NAMESPACE}};
498
+
499
+ public class {{pascalCase FEATURE_NAME}}Service
500
+ {
501
+ // TODO: Implement {{titleCase FEATURE_NAME}} logic
502
+ }
503
+ ```
504
+
505
+ ### 3. Register in REGISTRY.json
506
+
507
+ ```json
508
+ {
509
+ "id": "dotnet-backend-my-template",
510
+ "name": "My Custom Template",
511
+ "path": "code/dotnet/backend/my-template.cs",
512
+ "location": "framework",
513
+ "category": "code",
514
+ "phase": "implement",
515
+ "required": false,
516
+ "technology": "dotnet",
517
+ "applicableStacks": ["dotnet-nextjs"],
518
+ "engine": "handlebars",
519
+ "placeholders": ["FEATURE_NAME", "NAMESPACE"],
520
+ "outputName": "{FeatureName}MyTemplate.cs",
521
+ "deprecated": false
522
+ }
523
+ ```
524
+
525
+ ### 4. Test Rendering
526
+
527
+ ```bash
528
+ morph-spec template render dotnet-backend-my-template output.cs '{
529
+ "FEATURE_NAME": "user-auth",
530
+ "NAMESPACE": "MyApp.Services"
531
+ }'
532
+ ```
533
+
534
+ ---
535
+
536
+ ## 📦 Migration Guide: v1 → v2
537
+
538
+ ### What Changed
539
+
540
+ | Aspect | v1 (Stack-Based) | v2 (Technology-Based) |
541
+ |--------|------------------|----------------------|
542
+ | **Location** | `stacks/{stack}/.morph/framework/templates/` | `framework/templates/{technology}/` |
543
+ | **Organization** | By stack (dotnet-nextjs, nextjs-supabase) | By technology (dotnet, docker) |
544
+ | **Duplication** | High (proposal.md × 2, decisions.md × 2) | Low (shared templates in framework) |
545
+ | **Template Engine** | 3 engines (custom, Handlebars, mixed) | 1 engine (Handlebars with helpers) |
546
+ | **Pre-computed Variables** | `{{pascalCase FEATURE_NAME}}` | `{{pascalCase FEATURE_NAME}}` (helpers) |
547
+ | **Registry** | None (hardcoded paths) | `REGISTRY.json` (centralized metadata) |
548
+ | **CLI** | None | `morph-spec template list/show/render/customize` |
549
+ | **Future Stacks** | Must copy templates | Reuse existing technology templates |
550
+
551
+ ### Breaking Changes
552
+
553
+ **1. Template Paths**
554
+
555
+ ```diff
556
+ - stacks/dotnet-nextjs/.morph/framework/templates/service.cs
557
+ + framework/templates/code/dotnet/backend/service.cs
558
+
559
+ - stacks/nextjs-supabase/.morph/framework/templates/dockerfile-web.dockerfile
560
+ + framework/templates/infrastructure/docker/dockerfile-web.dockerfile
561
+ ```
562
+
563
+ **2. Pre-computed Variables**
564
+
565
+ ```diff
566
+ - {{pascalCase FEATURE_NAME}}
567
+ + {{pascalCase FEATURE_NAME}}
568
+
569
+ - {{camelCase FEATURE_NAME}}
570
+ + {{camelCase FEATURE_NAME}}
571
+
572
+ - {{snakeCase FEATURE_NAME}}
573
+ + {{snakeCase FEATURE_NAME}}
574
+ ```
575
+
576
+ **3. Template Resolution**
577
+
578
+ ```javascript
579
+ // Old (v1)
580
+ const templatePath = join(resolveTemplatesDir(projectPath), 'service.cs');
581
+
582
+ // New (v2)
583
+ const templatePath = resolveTemplatePath(projectPath, 'code/dotnet/backend/service.cs', stackId);
584
+ // Automatically falls back: stack override → framework
585
+ ```
586
+
587
+ ### Migration Steps
588
+
589
+ **Step 1:** Update code to use `resolveTemplatePath()`
590
+
591
+ ```javascript
592
+ import { resolveTemplatePath } from '../lib/stack-resolver.js';
593
+
594
+ // Before
595
+ const path = join(resolveTemplatesDir(process.cwd()), 'service.cs');
596
+
597
+ // After
598
+ const path = resolveTemplatePath(process.cwd(), 'code/dotnet/backend/service.cs', 'dotnet-nextjs');
599
+ ```
600
+
601
+ **Step 2:** Update template syntax to Handlebars
602
+
603
+ ```handlebars
604
+ <!-- Before -->
605
+ namespace {{NAMESPACE}};
606
+ public class {{pascalCase FEATURE_NAME}}Service { }
607
+
608
+ <!-- After -->
609
+ namespace {{pascalCase NAMESPACE}};
610
+ public class {{pascalCase FEATURE_NAME}}Service { }
611
+ ```
612
+
613
+ **Step 3:** Use CLI commands instead of hardcoded paths
614
+
615
+ ```bash
616
+ # Before (hardcoded)
617
+ cp framework/templates/proposal.md .morph/features/user-auth/proposal.md
618
+
619
+ # After (CLI)
620
+ morph-spec template render proposal .morph/features/user-auth/proposal.md '{
621
+ "FEATURE_NAME": "user-auth"
622
+ }'
623
+ ```
624
+
625
+ ---
626
+
627
+ ## 🎯 Best Practices
628
+
629
+ ### 1. **Use Helpers, Not Pre-computed Variables**
630
+
631
+ ```handlebars
632
+ ✅ GOOD:
633
+ {{pascalCase FEATURE_NAME}}Service
634
+
635
+ ❌ BAD:
636
+ {{pascalCase FEATURE_NAME}}Service // Deprecated, won't work
637
+ ```
638
+
639
+ ### 2. **Keep Templates Technology-Agnostic**
640
+
641
+ ```handlebars
642
+ ✅ GOOD: code/dotnet/backend/service.cs
643
+ Works for: dotnet-nextjs, nextjs-supabase, future-dotnet-stack
644
+
645
+ ❌ BAD: code/stack-specific/service.cs
646
+ Locked to one stack only
647
+ ```
648
+
649
+ ### 3. **Use Stack Conditionals for Differences**
650
+
651
+ ```handlebars
652
+ {{#if (eq STACK "nextjs-supabase")}}
653
+ // Supabase-specific implementation
654
+ {{else}}
655
+ // Generic implementation
656
+ {{/if}}
657
+ ```
658
+
659
+ ### 4. **Document Applicability in Registry**
660
+
661
+ ```json
662
+ {
663
+ "technology": "dotnet",
664
+ "applicableStacks": ["dotnet-nextjs", "nextjs-supabase"],
665
+ "description": "Works with any .NET backend stack"
666
+ }
667
+ ```
668
+
669
+ ### 5. **Override Only When Necessary**
670
+
671
+ ```bash
672
+ # Only customize if framework template doesn't meet needs
673
+ morph-spec template customize dotnet-backend-service --stack dotnet-nextjs
674
+
675
+ # Otherwise, use framework version (gets updates automatically)
676
+ morph-spec template render dotnet-backend-service output.cs '...'
677
+ ```
678
+
679
+ ---
680
+
681
+ ## 📚 References
682
+
683
+ - **Template Registry API:** [`src/lib/template-registry.js`](../../src/lib/template-registry.js)
684
+ - **Template Renderer:** [`src/lib/template-renderer.js`](../../src/lib/template-renderer.js)
685
+ - **Stack Resolver:** [`src/lib/stack-resolver.js`](../../src/lib/stack-resolver.js)
686
+ - **CLI Commands:** [`src/commands/template-*.js`](../../src/commands/)
687
+ - **Handlebars Docs:** https://handlebarsjs.com/
688
+
689
+ ---
690
+
691
+ ## 🤝 Contributing
692
+
693
+ ### Adding New Technology
694
+
695
+ 1. Create directory: `framework/templates/code/{technology}/`
696
+ 2. Add templates with Handlebars syntax
697
+ 3. Register in `REGISTRY.json` with `"technology": "{technology}"`
698
+ 4. Test with `morph-spec template render`
699
+ 5. Document in this README
700
+
701
+ ### Deprecating Templates
702
+
703
+ 1. Add `"deprecated": true` to `REGISTRY.json`
704
+ 2. Add `"deprecationReason": "Reason here"`
705
+ 3. Keep file for backward compatibility or remove after major version bump
706
+
707
+ ---
708
+
709
+ **MORPH-SPEC Template System v2.0** - Technology-Based, Future-Proof, DRY ✨