@polymorphism-tech/morph-spec 4.7.1 → 4.7.2

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 (232) hide show
  1. package/.morph/.morphversion +5 -0
  2. package/.morph/analytics/threads-log.jsonl +5 -0
  3. package/.morph/config/config.json +8 -0
  4. package/.morph/framework/agents.json +1815 -0
  5. package/.morph/framework/hooks/README.md +205 -0
  6. package/.morph/framework/hooks/claude-code/notification/approval-reminder.js +54 -0
  7. package/.morph/framework/hooks/claude-code/post-tool-use/dispatch.js +83 -0
  8. package/.morph/framework/hooks/claude-code/post-tool-use/handle-tool-failure.js +42 -0
  9. package/.morph/framework/hooks/claude-code/pre-compact/save-morph-context.js +61 -0
  10. package/.morph/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +71 -0
  11. package/.morph/framework/hooks/claude-code/pre-tool-use/protect-readonly-files.js +58 -0
  12. package/.morph/framework/hooks/claude-code/pre-tool-use/protect-spec-files.js +64 -0
  13. package/.morph/framework/hooks/claude-code/session-start/inject-morph-context.js +94 -0
  14. package/.morph/framework/hooks/claude-code/statusline.py +538 -0
  15. package/.morph/framework/hooks/claude-code/statusline.sh +7 -0
  16. package/.morph/framework/hooks/claude-code/stop/validate-completion.js +88 -0
  17. package/.morph/framework/hooks/claude-code/user-prompt/enrich-prompt.js +91 -0
  18. package/.morph/framework/hooks/git/commit-msg/conventional-commits.sh +33 -0
  19. package/.morph/framework/hooks/git/pre-commit/agents.sh +25 -0
  20. package/.morph/framework/hooks/git/pre-commit/orchestrator.sh +64 -0
  21. package/.morph/framework/hooks/git/pre-commit/specs.sh +50 -0
  22. package/.morph/framework/hooks/git/pre-push/run-tests.sh +44 -0
  23. package/.morph/framework/hooks/shared/hook-response.js +45 -0
  24. package/.morph/framework/hooks/shared/phase-utils.js +129 -0
  25. package/.morph/framework/hooks/shared/state-reader.js +138 -0
  26. package/.morph/framework/hooks/shared/stdin-reader.js +26 -0
  27. package/.morph/framework/standards/STANDARDS.json +933 -0
  28. package/.morph/framework/standards/ai-agents/blazor-ui.md +364 -0
  29. package/.morph/framework/standards/ai-agents/production.md +415 -0
  30. package/.morph/framework/standards/ai-agents/setup.md +418 -0
  31. package/.morph/framework/standards/ai-agents/team-orchestration.md +479 -0
  32. package/.morph/framework/standards/ai-agents/workflows.md +354 -0
  33. package/.morph/framework/standards/architecture/ddd/aggregates.md +120 -0
  34. package/.morph/framework/standards/architecture/ddd/bounded-contexts.md +105 -0
  35. package/.morph/framework/standards/architecture/ddd/complexity-levels.md +108 -0
  36. package/.morph/framework/standards/architecture/ddd/entities.md +99 -0
  37. package/.morph/framework/standards/architecture/ddd/ubiquitous-language.md +58 -0
  38. package/.morph/framework/standards/architecture/ddd/value-objects.md +124 -0
  39. package/.morph/framework/standards/backend/api/minimal-api.md +494 -0
  40. package/.morph/framework/standards/backend/api/rest.md +492 -0
  41. package/.morph/framework/standards/backend/api/validation.md +88 -0
  42. package/.morph/framework/standards/backend/authentication/passkeys.md +428 -0
  43. package/.morph/framework/standards/backend/database/ef-core.md +199 -0
  44. package/.morph/framework/standards/backend/database/migrations.md +393 -0
  45. package/.morph/framework/standards/backend/database/postgresql/database.md +352 -0
  46. package/.morph/framework/standards/backend/database/repository-patterns.md +528 -0
  47. package/.morph/framework/standards/backend/database/vector-search-rag.md +541 -0
  48. package/.morph/framework/standards/backend/dotnet/async.md +366 -0
  49. package/.morph/framework/standards/backend/dotnet/core.md +117 -0
  50. package/.morph/framework/standards/backend/dotnet/di.md +439 -0
  51. package/.morph/framework/standards/backend/dotnet/program-cs-checklist.md +92 -0
  52. package/.morph/framework/standards/backend/integrations/asaas/asaas-api.md +216 -0
  53. package/.morph/framework/standards/backend/integrations/clerk/clerk-auth.md +290 -0
  54. package/.morph/framework/standards/backend/integrations/hangfire/hangfire-jobs.md +350 -0
  55. package/.morph/framework/standards/backend/integrations/resend/resend-email.md +385 -0
  56. package/.morph/framework/standards/context/analytics.md +96 -0
  57. package/.morph/framework/standards/context/bundles.md +110 -0
  58. package/.morph/framework/standards/context/priming.md +78 -0
  59. package/.morph/framework/standards/core/architecture.md +185 -0
  60. package/.morph/framework/standards/core/coding.md +214 -0
  61. package/.morph/framework/standards/core/git-branching-strategy.md +403 -0
  62. package/.morph/framework/standards/core/git.md +185 -0
  63. package/.morph/framework/standards/core/testing.md +295 -0
  64. package/.morph/framework/standards/data/nosql/blob-storage.md +102 -0
  65. package/.morph/framework/standards/data/nosql/cache/redis.md +97 -0
  66. package/.morph/framework/standards/data/nosql/cosmos-db.md +118 -0
  67. package/.morph/framework/standards/data/vector-search/azure-ai-search.md +121 -0
  68. package/.morph/framework/standards/data/vector-search/rag-chunking.md +104 -0
  69. package/.morph/framework/standards/frontend/blazor/design-checklist.md +222 -0
  70. package/.morph/framework/standards/frontend/blazor/fluent-ui-setup.md +595 -0
  71. package/.morph/framework/standards/frontend/blazor/fluent-ui.md +137 -0
  72. package/.morph/framework/standards/frontend/blazor/html-conversion.md +184 -0
  73. package/.morph/framework/standards/frontend/blazor/lifecycle.md +195 -0
  74. package/.morph/framework/standards/frontend/blazor/pitfalls.md +198 -0
  75. package/.morph/framework/standards/frontend/blazor/state.md +191 -0
  76. package/.morph/framework/standards/frontend/design-system/animations.md +151 -0
  77. package/.morph/framework/standards/frontend/design-system/naming.md +64 -0
  78. package/.morph/framework/standards/frontend/nextjs/app-router.md +123 -0
  79. package/.morph/framework/standards/frontend/nextjs/components.md +132 -0
  80. package/.morph/framework/standards/frontend/nextjs/data-fetching.md +126 -0
  81. package/.morph/framework/standards/frontend/nextjs/forms.md +128 -0
  82. package/.morph/framework/standards/frontend/nextjs/naming-conventions.md +67 -0
  83. package/.morph/framework/standards/frontend/nextjs/nextjs-patterns.md +215 -0
  84. package/.morph/framework/standards/frontend/nextjs/project-structure.md +102 -0
  85. package/.morph/framework/standards/frontend/nextjs/state-management.md +72 -0
  86. package/.morph/framework/standards/frontend/nextjs/testing.md +111 -0
  87. package/.morph/framework/standards/infrastructure/azure/azure.md +624 -0
  88. package/.morph/framework/standards/infrastructure/azure/bicep/bicep-patterns.md +422 -0
  89. package/.morph/framework/standards/infrastructure/azure/devops/azure-devops-setup.md +516 -0
  90. package/.morph/framework/standards/infrastructure/azure/devops/local-development.md +520 -0
  91. package/.morph/framework/standards/infrastructure/azure/services/functions.md +486 -0
  92. package/.morph/framework/standards/infrastructure/azure/services/service-bus.md +459 -0
  93. package/.morph/framework/standards/infrastructure/azure/services/storage.md +407 -0
  94. package/.morph/framework/standards/infrastructure/docker/easypanel-deploy.md +196 -0
  95. package/.morph/framework/standards/infrastructure/supabase/mcp-setup.md +252 -0
  96. package/.morph/framework/standards/infrastructure/supabase/supabase-auth.md +176 -0
  97. package/.morph/framework/standards/infrastructure/supabase/supabase-pgvector.md +169 -0
  98. package/.morph/framework/standards/infrastructure/supabase/supabase-rls.md +184 -0
  99. package/.morph/framework/standards/infrastructure/supabase/supabase-storage.md +153 -0
  100. package/.morph/framework/standards/integration/api/graphql.md +91 -0
  101. package/.morph/framework/standards/integration/api/grpc.md +114 -0
  102. package/.morph/framework/standards/integration/api/rest-design.md +95 -0
  103. package/.morph/framework/standards/integration/event-driven/cqrs.md +101 -0
  104. package/.morph/framework/standards/integration/event-driven/event-sourcing.md +124 -0
  105. package/.morph/framework/standards/integration/event-driven/service-bus.md +95 -0
  106. package/.morph/framework/standards/integration/mcp/mcp-tools.md +384 -0
  107. package/.morph/framework/standards/observability/logging.md +131 -0
  108. package/.morph/framework/standards/observability/metrics.md +121 -0
  109. package/.morph/framework/standards/observability/monitoring.md +114 -0
  110. package/.morph/framework/standards/observability/tracing.md +132 -0
  111. package/.morph/framework/standards/workflows/parallel-execution.md +112 -0
  112. package/.morph/framework/standards/workflows/thread-management.md +113 -0
  113. package/.morph/framework/templates/.idea/morph-templates.xml +92 -0
  114. package/.morph/framework/templates/.vscode/morph-templates.code-snippets +186 -0
  115. package/.morph/framework/templates/IDE-SNIPPETS.md +266 -0
  116. package/.morph/framework/templates/README.md +814 -0
  117. package/.morph/framework/templates/REGISTRY.json +1888 -0
  118. package/.morph/framework/templates/code/dotnet/backend/repository.cs +141 -0
  119. package/.morph/framework/templates/code/dotnet/backend/service.cs +139 -0
  120. package/.morph/framework/templates/code/dotnet/contracts/Commands.cs +74 -0
  121. package/.morph/framework/templates/code/dotnet/contracts/Entities.cs +25 -0
  122. package/.morph/framework/templates/code/dotnet/contracts/Queries.cs +74 -0
  123. package/.morph/framework/templates/code/dotnet/contracts/README.md +74 -0
  124. package/.morph/framework/templates/code/dotnet/contracts/api-contracts.cs +173 -0
  125. package/.morph/framework/templates/code/dotnet/contracts/contracts-level1.cs +69 -0
  126. package/.morph/framework/templates/code/dotnet/contracts/contracts-level2.cs +86 -0
  127. package/.morph/framework/templates/code/dotnet/contracts/contracts-level3.cs +41 -0
  128. package/.morph/framework/templates/code/dotnet/database/migration.cs +83 -0
  129. package/.morph/framework/templates/code/dotnet/frontend/component.razor +239 -0
  130. package/.morph/framework/templates/code/dotnet/jobs/agent.cs +163 -0
  131. package/.morph/framework/templates/code/dotnet/jobs/job.cs +171 -0
  132. package/.morph/framework/templates/code/dotnet/test.cs +239 -0
  133. package/.morph/framework/templates/code/sql/rls-policy.sql +57 -0
  134. package/.morph/framework/templates/code/sql/supabase-migration.sql +100 -0
  135. package/.morph/framework/templates/code/sql/supabase-migration.template.sql +113 -0
  136. package/.morph/framework/templates/code/typescript/contracts.ts +168 -0
  137. package/.morph/framework/templates/context/CONTEXT-FEATURE.md +276 -0
  138. package/.morph/framework/templates/context/CONTEXT.md +181 -0
  139. package/.morph/framework/templates/docs/clarifications.md +253 -0
  140. package/.morph/framework/templates/docs/onboarding.md +123 -0
  141. package/.morph/framework/templates/docs/proposal.md +182 -0
  142. package/.morph/framework/templates/docs/schema-analysis.md +119 -0
  143. package/.morph/framework/templates/docs/spec.md +198 -0
  144. package/.morph/framework/templates/docs/ui-components.md +124 -0
  145. package/.morph/framework/templates/docs/ui-design-system.md +76 -0
  146. package/.morph/framework/templates/docs/ui-flows.md +167 -0
  147. package/.morph/framework/templates/docs/ui-mockups.md +98 -0
  148. package/.morph/framework/templates/docs/user-stories.md +34 -0
  149. package/.morph/framework/templates/examples/design-system-examples.md +357 -0
  150. package/.morph/framework/templates/examples/spec-examples.md +90 -0
  151. package/.morph/framework/templates/feature/decisions.md +187 -0
  152. package/.morph/framework/templates/feature/recap.md +146 -0
  153. package/.morph/framework/templates/feature/tasks.md +199 -0
  154. package/.morph/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +43 -0
  155. package/.morph/framework/templates/frontend/nextjs/client-component.tsx.hbs +26 -0
  156. package/.morph/framework/templates/frontend/nextjs/env.mjs.hbs +32 -0
  157. package/.morph/framework/templates/frontend/nextjs/feature-form.tsx.hbs +56 -0
  158. package/.morph/framework/templates/frontend/nextjs/page.tsx.hbs +22 -0
  159. package/.morph/framework/templates/frontend/nextjs/tsconfig.json.hbs +26 -0
  160. package/.morph/framework/templates/frontend/nextjs/use-feature.ts.hbs +54 -0
  161. package/.morph/framework/templates/infrastructure/azure/Dockerfile.example +82 -0
  162. package/.morph/framework/templates/infrastructure/azure/README.md +286 -0
  163. package/.morph/framework/templates/infrastructure/azure/app-insights.bicep +63 -0
  164. package/.morph/framework/templates/infrastructure/azure/app-service.bicep +164 -0
  165. package/.morph/framework/templates/infrastructure/azure/container-app-env.bicep +49 -0
  166. package/.morph/framework/templates/infrastructure/azure/container-app.bicep +156 -0
  167. package/.morph/framework/templates/infrastructure/azure/deploy-checklist.md +426 -0
  168. package/.morph/framework/templates/infrastructure/azure/deploy.ps1 +229 -0
  169. package/.morph/framework/templates/infrastructure/azure/deploy.sh +208 -0
  170. package/.morph/framework/templates/infrastructure/azure/key-vault.bicep +91 -0
  171. package/.morph/framework/templates/infrastructure/azure/main.bicep +189 -0
  172. package/.morph/framework/templates/infrastructure/azure/parameters.dev.json +29 -0
  173. package/.morph/framework/templates/infrastructure/azure/parameters.prod.json +29 -0
  174. package/.morph/framework/templates/infrastructure/azure/parameters.staging.json +29 -0
  175. package/.morph/framework/templates/infrastructure/azure/sql-database.bicep +103 -0
  176. package/.morph/framework/templates/infrastructure/azure/storage.bicep +106 -0
  177. package/.morph/framework/templates/infrastructure/docker/Dockerfile.template +58 -0
  178. package/.morph/framework/templates/infrastructure/docker/docker-compose.template.yml +67 -0
  179. package/.morph/framework/templates/infrastructure/docker/dockerfile-api.dockerfile +38 -0
  180. package/.morph/framework/templates/infrastructure/docker/dockerfile-web.dockerfile +48 -0
  181. package/.morph/framework/templates/infrastructure/docker/easypanel.template.json +54 -0
  182. package/.morph/framework/templates/infrastructure/github/README.md +593 -0
  183. package/.morph/framework/templates/infrastructure/github/actions/azure-auth/action.yml.hbs +22 -0
  184. package/.morph/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +45 -0
  185. package/.morph/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +27 -0
  186. package/.morph/framework/templates/infrastructure/github/workflows/deploy-azure-app-service.yml.hbs +61 -0
  187. package/.morph/framework/templates/infrastructure/github/workflows/deploy-easypanel.yml.hbs +31 -0
  188. package/.morph/framework/templates/infrastructure/github/workflows/docker-build-push.yml.hbs +59 -0
  189. package/.morph/framework/templates/infrastructure/github/workflows/dotnet-build.yml.hbs +39 -0
  190. package/.morph/framework/templates/integrations/asaas-client.cs +387 -0
  191. package/.morph/framework/templates/integrations/asaas-webhook.cs +351 -0
  192. package/.morph/framework/templates/integrations/azure-identity-config.cs +288 -0
  193. package/.morph/framework/templates/integrations/clerk-config.cs +258 -0
  194. package/.morph/framework/templates/meta-prompts/fusion/fusion-agent.md +76 -0
  195. package/.morph/framework/templates/meta-prompts/fusion/fusion-aggregator.md +100 -0
  196. package/.morph/framework/templates/meta-prompts/hops/hop-retry.md +78 -0
  197. package/.morph/framework/templates/meta-prompts/hops/hop-validation.md +97 -0
  198. package/.morph/framework/templates/meta-prompts/hops/hop-wrapper.md +36 -0
  199. package/.morph/framework/templates/meta-prompts/parallel-workers/parallel-coordinator.md +113 -0
  200. package/.morph/framework/templates/meta-prompts/parallel-workers/parallel-worker.md +80 -0
  201. package/.morph/framework/templates/meta-prompts/squad-leaders/backend-squad.md +90 -0
  202. package/.morph/framework/templates/meta-prompts/squad-leaders/frontend-squad.md +126 -0
  203. package/.morph/framework/templates/meta-prompts/squad-leaders/squad-leader.md +43 -0
  204. package/.morph/framework/templates/meta-prompts/validators/checkpoint-validator.md +107 -0
  205. package/.morph/framework/templates/meta-prompts/validators/pre-commit-validator.md +95 -0
  206. package/.morph/framework/templates/project-structure/dotnet-ddd.md +70 -0
  207. package/.morph/framework/templates/saas/subscription.cs +347 -0
  208. package/.morph/framework/templates/saas/tenant.cs +338 -0
  209. package/.morph/framework/templates/state.template.json +17 -0
  210. package/.morph/framework/templates/ui/FluentDesignTheme.cs +149 -0
  211. package/.morph/framework/templates/ui/MudTheme.cs +281 -0
  212. package/.morph/framework/templates/ui/design-system.css +226 -0
  213. package/.morph/logs/tool-failures.log +17 -0
  214. package/.morph/memory/pre-compact-2026-02-24T17-43-30-049Z.json +16 -0
  215. package/.morph/plans/eager-watching-bunny.md +105 -0
  216. package/.morph/plans/temporal-seeking-nebula.md +45 -0
  217. package/.morph/state.json +48 -0
  218. package/CLAUDE.md +1 -1
  219. package/README.md +2 -2
  220. package/bin/morph-spec.js +0 -9
  221. package/framework/CLAUDE.md +1 -1
  222. package/framework/hooks/README.md +10 -6
  223. package/framework/hooks/claude-code/notification/approval-reminder.js +2 -0
  224. package/framework/hooks/claude-code/post-tool-use/dispatch.js +1 -1
  225. package/framework/hooks/claude-code/stop/validate-completion.js +1 -1
  226. package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +1 -1
  227. package/package.json +1 -1
  228. package/src/commands/project/init.js +15 -42
  229. package/src/commands/project/update.js +22 -37
  230. package/src/lib/installers/mcp-installer.js +18 -3
  231. package/src/utils/hooks-installer.js +5 -15
  232. package/src/commands/project/detect.js +0 -114
@@ -0,0 +1,215 @@
1
+ # Next.js 15 Patterns Standard
2
+
3
+ > **Scope:** nextjs-supabase
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** nextjs, react, app router, server component, client component
6
+ > **Load When:** nextjs keywords detected
7
+
8
+ Stack: Next.js 15 + Supabase + .NET Backend
9
+
10
+ ## Core Rules
11
+
12
+ - ALWAYS use App Router (not Pages Router)
13
+ - Default to Server Components -- add `'use client'` only when needed
14
+ - ALWAYS colocate loading.tsx and error.tsx with page.tsx
15
+ - NEVER call Supabase directly from client -- use Route Handlers as BFF
16
+ - ALWAYS validate inputs with Zod on both client and server
17
+ - Use TypeScript strict mode (`"strict": true`)
18
+
19
+ ## Server vs Client Components
20
+
21
+ | Aspect | Server Component (default) | Client Component (`'use client'`) |
22
+ |--------|---------------------------|-----------------------------------|
23
+ | Renders | Server only | Server SSR + Client hydration |
24
+ | Access to | DB, env vars, fs, async/await | Browser APIs, useState, useEffect, events |
25
+ | Bundle | Not included | Included in JS bundle |
26
+ | Use when | Data fetching, static content | Interactivity, forms, real-time |
27
+
28
+ Decision: Need useState/useEffect/onClick/browser APIs? Client Component. Otherwise Server Component.
29
+
30
+ ## File-Based Routing
31
+
32
+ ```
33
+ app/
34
+ layout.tsx # Root layout
35
+ page.tsx # / (home)
36
+ loading.tsx / error.tsx # Loading UI / Error boundary
37
+ not-found.tsx # 404
38
+ dashboard/
39
+ layout.tsx # Nested layout
40
+ page.tsx # /dashboard
41
+ loading.tsx
42
+ api/documents/
43
+ route.ts # GET/POST /api/documents
44
+ [id]/route.ts # GET/PUT/DELETE /api/documents/:id
45
+ ```
46
+
47
+ ## Layout and Error Boundaries
48
+
49
+ ```tsx
50
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
51
+ return <html lang="en"><body><Providers>{children}</Providers></body></html>;
52
+ }
53
+
54
+ // loading.tsx
55
+ export default function Loading() { return <div className="animate-pulse">Loading...</div>; }
56
+
57
+ // error.tsx — MUST be 'use client'
58
+ 'use client';
59
+ export default function Error({ error, reset }: { error: Error; reset: () => void }) {
60
+ return <div><h2>Something went wrong</h2><button onClick={reset}>Try again</button></div>;
61
+ }
62
+ ```
63
+
64
+ ## Route Handlers (BFF Pattern)
65
+
66
+ ```ts
67
+ // app/api/documents/route.ts
68
+ import { createClient } from "@/lib/supabase/server";
69
+ import { NextResponse } from "next/server";
70
+ import { z } from "zod";
71
+
72
+ const CreateSchema = z.object({
73
+ title: z.string().min(1).max(200),
74
+ content: z.string().min(1),
75
+ });
76
+
77
+ export async function GET() {
78
+ const supabase = await createClient();
79
+ const { data: { user } } = await supabase.auth.getUser();
80
+ if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
81
+ const { data, error } = await supabase.from("documents").select("*");
82
+ if (error) return NextResponse.json({ error: error.message }, { status: 500 });
83
+ return NextResponse.json(data);
84
+ }
85
+
86
+ export async function POST(request: Request) {
87
+ const supabase = await createClient();
88
+ const { data: { user } } = await supabase.auth.getUser();
89
+ if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
90
+ const parsed = CreateSchema.safeParse(await request.json());
91
+ if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
92
+ const { data, error } = await supabase
93
+ .from("documents").insert({ ...parsed.data, user_id: user.id }).select().single();
94
+ if (error) return NextResponse.json({ error: error.message }, { status: 500 });
95
+ return NextResponse.json(data, { status: 201 });
96
+ }
97
+ ```
98
+
99
+ ## React Query + Supabase
100
+
101
+ ```tsx
102
+ // providers/query-provider.tsx
103
+ 'use client';
104
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
105
+ import { useState } from "react";
106
+
107
+ export function QueryProvider({ children }: { children: React.ReactNode }) {
108
+ const [client] = useState(() => new QueryClient({
109
+ defaultOptions: { queries: { staleTime: 60_000, retry: 1 } },
110
+ }));
111
+ return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
112
+ }
113
+ ```
114
+
115
+ ```tsx
116
+ // hooks/use-documents.ts
117
+ export function useDocuments() {
118
+ return useQuery({
119
+ queryKey: ["documents"],
120
+ queryFn: async () => {
121
+ const res = await fetch("/api/documents");
122
+ if (!res.ok) throw new Error("Failed to fetch");
123
+ return res.json();
124
+ },
125
+ });
126
+ }
127
+
128
+ export function useCreateDocument() {
129
+ const qc = useQueryClient();
130
+ return useMutation({
131
+ mutationFn: async (data: { title: string; content: string }) => {
132
+ const res = await fetch("/api/documents", {
133
+ method: "POST", headers: { "Content-Type": "application/json" },
134
+ body: JSON.stringify(data),
135
+ });
136
+ if (!res.ok) throw new Error("Failed to create");
137
+ return res.json();
138
+ },
139
+ onSuccess: () => qc.invalidateQueries({ queryKey: ["documents"] }),
140
+ });
141
+ }
142
+ ```
143
+
144
+ ## Form Handling (react-hook-form + Zod)
145
+
146
+ ```tsx
147
+ 'use client';
148
+ import { useForm } from "react-hook-form";
149
+ import { zodResolver } from "@hookform/resolvers/zod";
150
+ import { z } from "zod";
151
+
152
+ const schema = z.object({
153
+ title: z.string().min(1, "Required").max(200),
154
+ content: z.string().min(1, "Required"),
155
+ });
156
+
157
+ export function DocumentForm() {
158
+ const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<z.infer<typeof schema>>({
159
+ resolver: zodResolver(schema),
160
+ });
161
+ const create = useCreateDocument();
162
+ return (
163
+ <form onSubmit={handleSubmit((data) => create.mutateAsync(data))}>
164
+ <input {...register("title")} />
165
+ {errors.title && <span>{errors.title.message}</span>}
166
+ <textarea {...register("content")} />
167
+ {errors.content && <span>{errors.content.message}</span>}
168
+ <button type="submit" disabled={isSubmitting}>Save</button>
169
+ </form>
170
+ );
171
+ }
172
+ ```
173
+
174
+ ## shadcn/ui
175
+
176
+ Install: `npx shadcn@latest init` then `npx shadcn@latest add button input card dialog form`.
177
+ Components are copied to `components/ui/` -- NOT an npm dependency, your code to customize.
178
+
179
+ ## TypeScript Strict Patterns
180
+
181
+ | Pattern | Approach |
182
+ |---------|----------|
183
+ | API responses | Zod schema + `z.infer<typeof schema>` |
184
+ | Props | Explicit interface, no `any` |
185
+ | Event handlers | `React.ChangeEvent<HTMLInputElement>` |
186
+ | Null safety | `?.` over type assertions, `if (!data) return null` |
187
+
188
+ ## Common Mistakes
189
+
190
+ | Wrong | Right | Why |
191
+ |-------|-------|-----|
192
+ | `'use client'` on every component | Default to Server Components | Unnecessary JS bundle size |
193
+ | Direct Supabase from client | Route Handler `/api/*` as BFF | Exposes queries, harder to secure |
194
+ | `any` for API responses | Zod schema + infer | No runtime safety |
195
+ | Missing loading.tsx | Colocate with page.tsx | Blank page during load |
196
+ | `useEffect` for data fetching | React Query `useQuery` | No caching, race conditions |
197
+ | Form validation on submit only | Zod resolver + react-hook-form | Delayed error feedback |
198
+ | shadcn as npm package | `npx shadcn@latest add` | Copy-paste system, not a dependency |
199
+
200
+ ## TypeScript Strict Mode (Required)
201
+
202
+ Always enable `"strict": true` in `tsconfig.json`. This is non-negotiable for
203
+ agent-assisted development because agents rely on compiler errors to self-correct.
204
+ Without strict mode, type/null errors only surface at runtime where agents cannot observe them.
205
+
206
+ ```json
207
+ {
208
+ "compilerOptions": {
209
+ "strict": true,
210
+ "noUncheckedIndexedAccess": true
211
+ }
212
+ }
213
+ ```
214
+
215
+ Strict mode enables: `strictNullChecks`, `noImplicitAny`, `strictFunctionTypes`, `strictPropertyInitialization`.
@@ -0,0 +1,102 @@
1
+ # Next.js Project Structure Standard
2
+
3
+ > **Scope:** frontend/nextjs/project-structure
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** project structure, folder structure, feature folder, src layout
6
+ > **Load When:** creating new files or features
7
+
8
+ Feature-based architecture with a shared core. Features are self-contained; shared code is explicit.
9
+
10
+ ## Core Rules
11
+
12
+ - ALWAYS use feature-based folders: `features/{feature-name}/`
13
+ - ALWAYS keep `app/` for routing only — import from `features/`, not the other way
14
+ - NEVER import from one feature into another — extract to `components/` or `lib/` if shared
15
+ - ALWAYS use `src/` directory (configured in `tsconfig.json` with `@/` alias)
16
+ - NEVER put business logic in `components/` — it is presentation only
17
+
18
+ ## Canonical Folder Tree
19
+
20
+ ```
21
+ src/
22
+ ├── app/ # Next.js App Router — routes only
23
+ │ ├── layout.tsx # Root layout + providers
24
+ │ ├── page.tsx # Home page
25
+ │ └── (dashboard)/
26
+ │ ├── layout.tsx
27
+ │ ├── users/
28
+ │ │ ├── page.tsx
29
+ │ │ ├── loading.tsx
30
+ │ │ └── error.tsx
31
+ │ └── billing/
32
+ │ └── page.tsx
33
+
34
+ ├── features/ # Domain features
35
+ │ └── {feature-name}/
36
+ │ ├── components/ # Feature-specific UI components
37
+ │ │ ├── user-list.tsx
38
+ │ │ └── user-card.tsx
39
+ │ ├── hooks/ # TanStack Query hooks for this feature
40
+ │ │ ├── use-users.ts
41
+ │ │ └── use-create-user.ts
42
+ │ ├── types/
43
+ │ │ ├── user.types.ts # TypeScript types
44
+ │ │ └── user.schemas.ts # Zod schemas + z.infer<> types
45
+ │ └── index.ts # Public API — only export what's needed
46
+
47
+ ├── components/ # Shared UI — no business logic
48
+ │ ├── ui/ # shadcn/ui — never edit directly
49
+ │ │ ├── button.tsx
50
+ │ │ └── card.tsx
51
+ │ ├── data-table.tsx
52
+ │ ├── page-header.tsx
53
+ │ └── empty-state.tsx
54
+
55
+ ├── hooks/ # Shared utility hooks — no API calls
56
+ │ ├── use-debounce.ts
57
+ │ └── use-media-query.ts
58
+
59
+ ├── lib/
60
+ │ ├── api-client.ts # Typed fetch wrapper for .NET API
61
+ │ └── query-client.tsx # TanStack Query client + provider
62
+
63
+ ├── types/
64
+ │ ├── api.ts # Shared API shapes: PaginatedResponse<T>, ApiError
65
+ │ └── env.d.ts
66
+
67
+ └── env.mjs # Zod-validated env vars
68
+ ```
69
+
70
+ ## Feature Index Pattern
71
+
72
+ ```ts
73
+ // features/users/index.ts — explicit public API
74
+ export { UserList } from './components/user-list';
75
+ export { UserCard } from './components/user-card';
76
+ export { useUsers } from './hooks/use-users';
77
+ export { useCreateUser } from './hooks/use-create-user';
78
+ export type { User, CreateUserInput } from './types/user.types';
79
+ ```
80
+
81
+ Import from the index, not deep paths:
82
+ ```ts
83
+ // GOOD
84
+ import { UserList, useUsers } from '@/features/users';
85
+
86
+ // BAD
87
+ import { UserList } from '@/features/users/components/user-list';
88
+ ```
89
+
90
+ ## Feature Boundary Rule
91
+
92
+ ```
93
+ app/ → imports from features/ ✓
94
+ features/users/ → imports from components/ and lib/ ✓
95
+ features/users/ → imports from features/billing/ ✗ (extract shared instead)
96
+ components/ → imports from components/ui/ ✓
97
+ components/ → imports from features/ ✗
98
+ ```
99
+
100
+ ---
101
+
102
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,72 @@
1
+ # Next.js State Management Standard
2
+
3
+ > **Scope:** frontend/nextjs/state-management
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** state, zustand, context, redux, client state, server state, useState
6
+ > **Load When:** deciding how to manage state in Next.js
7
+
8
+ Server state (API data) lives in TanStack Query. UI state lives in React. No global state library unless genuinely needed.
9
+
10
+ ## Core Rules
11
+
12
+ - ALWAYS use TanStack Query for anything that comes from the .NET API
13
+ - ALWAYS use `useState` for local UI state (modal open, selected tab, form step)
14
+ - NEVER install Zustand or Redux without first exhausting Server Components + TanStack Query
15
+ - NEVER use React Context for server state — Context does not cache or deduplicate
16
+ - ALWAYS derive state from server data rather than syncing it to local state
17
+
18
+ ## State Decision Tree
19
+
20
+ ```
21
+ Is this data from the .NET API?
22
+ YES → TanStack Query (useQuery / useMutation)
23
+
24
+ Is this local UI state (open/closed, selected, current step)?
25
+ YES → useState in the component that needs it
26
+
27
+ Does multiple components need this UI state?
28
+ YES — is it parent-child? → prop drilling (2-3 levels is fine)
29
+ YES — is it truly global? → React Context (theme, auth user, locale)
30
+ YES — complex with many actions? → Consider Zustand (last resort)
31
+ ```
32
+
33
+ ## Server State (TanStack Query)
34
+
35
+ ```ts
36
+ // GOOD — server state in TanStack Query
37
+ const { data: users } = useUsers(); // cached, deduplicated, background-refetched
38
+
39
+ // BAD — copying server state to useState
40
+ const [users, setUsers] = useState([]);
41
+ useEffect(() => { fetchUsers().then(setUsers); }, []);
42
+ ```
43
+
44
+ ## Local UI State (useState)
45
+
46
+ ```tsx
47
+ function UserList() {
48
+ const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
49
+ const [selectedUserId, setSelectedUserId] = useState<string | null>(null);
50
+ }
51
+ ```
52
+
53
+ ## When Zustand Is Justified
54
+
55
+ Only add Zustand if ALL of these are true:
56
+ 1. State is needed in 5+ unrelated components
57
+ 2. State has complex update logic (not just toggle/set)
58
+ 3. Context causes measurable re-render performance issues
59
+ 4. State is not from the server
60
+
61
+ ## Common Mistakes
62
+
63
+ | Wrong | Right | Why |
64
+ |-------|-------|-----|
65
+ | `useEffect` + `useState` for API data | TanStack Query | Stale data, no cache, double-render |
66
+ | Global store for user list | `useUsers()` | TanStack Query handles sync/cache |
67
+ | Context for everything | useState + prop drilling first | Context causes all consumers to re-render |
68
+ | Zustand by default | Start with useState | YAGNI — most state is local |
69
+
70
+ ---
71
+
72
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,111 @@
1
+ # Next.js Testing Standard
2
+
3
+ > **Scope:** frontend/nextjs/testing
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** testing, jest, vitest, testing-library, msw, component test, unit test
6
+ > **Load When:** writing tests for Next.js components or hooks
7
+
8
+ Jest + React Testing Library for component tests. MSW for API mocking. Co-locate tests with the code they test.
9
+
10
+ ## Core Rules
11
+
12
+ - ALWAYS co-locate test files: `user-card.test.tsx` next to `user-card.tsx`
13
+ - ALWAYS use `@testing-library/user-event` for interactions — not `fireEvent`
14
+ - ALWAYS mock the API layer with MSW — never mock `fetch` directly
15
+ - NEVER test implementation details — test what the user sees
16
+ - ALWAYS test the happy path + one error path per component
17
+
18
+ ## Test File Co-location
19
+
20
+ ```
21
+ features/users/
22
+ ├── components/
23
+ │ ├── user-card.tsx
24
+ │ ├── user-card.test.tsx ← co-located
25
+ │ ├── user-list.tsx
26
+ │ └── user-list.test.tsx
27
+ ├── hooks/
28
+ │ ├── use-users.ts
29
+ │ └── use-users.test.ts ← co-located
30
+ ```
31
+
32
+ ## Component Test Pattern
33
+
34
+ ```tsx
35
+ // features/users/components/user-card.test.tsx
36
+ import { render, screen } from '@testing-library/react';
37
+ import userEvent from '@testing-library/user-event';
38
+ import { UserCard } from './user-card';
39
+
40
+ const mockUser = { id: '1', name: 'João Silva', email: 'joao@example.com', role: 'user' as const };
41
+
42
+ describe('UserCard', () => {
43
+ it('renders user name and email', () => {
44
+ render(<UserCard user={mockUser} />);
45
+ expect(screen.getByText('João Silva')).toBeInTheDocument();
46
+ expect(screen.getByText('joao@example.com')).toBeInTheDocument();
47
+ });
48
+
49
+ it('calls onEdit with user id when edit button clicked', async () => {
50
+ const onEdit = vi.fn();
51
+ render(<UserCard user={mockUser} onEdit={onEdit} />);
52
+ await userEvent.click(screen.getByRole('button', { name: /edit/i }));
53
+ expect(onEdit).toHaveBeenCalledWith('1');
54
+ });
55
+ });
56
+ ```
57
+
58
+ ## Hook Test with MSW
59
+
60
+ ```ts
61
+ // features/users/hooks/use-users.test.ts
62
+ import { renderHook, waitFor } from '@testing-library/react';
63
+ import { http, HttpResponse } from 'msw';
64
+ import { server } from '@/test/msw-server';
65
+ import { QueryClientWrapper } from '@/test/helpers';
66
+ import { useUsers } from './use-users';
67
+
68
+ describe('useUsers', () => {
69
+ it('returns users from API', async () => {
70
+ server.use(
71
+ http.get('/api/proxy/users', () =>
72
+ HttpResponse.json([{ id: '1', name: 'João', email: 'j@ex.com' }])
73
+ )
74
+ );
75
+ const { result } = renderHook(() => useUsers(), { wrapper: QueryClientWrapper });
76
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
77
+ expect(result.current.data).toHaveLength(1);
78
+ });
79
+
80
+ it('returns error state when API fails', async () => {
81
+ server.use(http.get('/api/proxy/users', () => new HttpResponse(null, { status: 500 })));
82
+ const { result } = renderHook(() => useUsers(), { wrapper: QueryClientWrapper });
83
+ await waitFor(() => expect(result.current.isError).toBe(true));
84
+ });
85
+ });
86
+ ```
87
+
88
+ ## Test Helper Setup
89
+
90
+ ```tsx
91
+ // test/helpers.tsx
92
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
93
+
94
+ export function QueryClientWrapper({ children }: { children: React.ReactNode }) {
95
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
96
+ return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
97
+ }
98
+ ```
99
+
100
+ ## Common Mistakes
101
+
102
+ | Wrong | Right | Why |
103
+ |-------|-------|-----|
104
+ | `fireEvent.click(button)` | `await userEvent.click(button)` | userEvent simulates real browser events |
105
+ | Mock `global.fetch` | Mock with MSW | MSW intercepts at network level |
106
+ | `expect(component).toMatchSnapshot()` | `expect(screen.getByText(...))` | Snapshots break on any change |
107
+ | Test file in `__tests__/` folder | Co-locate with source | Easier to find, deleted with the component |
108
+
109
+ ---
110
+
111
+ *MORPH-SPEC by Polymorphism Tech*