@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.
- package/.morph/.morphversion +5 -0
- package/.morph/analytics/threads-log.jsonl +5 -0
- package/.morph/config/config.json +8 -0
- package/.morph/framework/agents.json +1815 -0
- package/.morph/framework/hooks/README.md +205 -0
- package/.morph/framework/hooks/claude-code/notification/approval-reminder.js +54 -0
- package/.morph/framework/hooks/claude-code/post-tool-use/dispatch.js +83 -0
- package/.morph/framework/hooks/claude-code/post-tool-use/handle-tool-failure.js +42 -0
- package/.morph/framework/hooks/claude-code/pre-compact/save-morph-context.js +61 -0
- package/.morph/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +71 -0
- package/.morph/framework/hooks/claude-code/pre-tool-use/protect-readonly-files.js +58 -0
- package/.morph/framework/hooks/claude-code/pre-tool-use/protect-spec-files.js +64 -0
- package/.morph/framework/hooks/claude-code/session-start/inject-morph-context.js +94 -0
- package/.morph/framework/hooks/claude-code/statusline.py +538 -0
- package/.morph/framework/hooks/claude-code/statusline.sh +7 -0
- package/.morph/framework/hooks/claude-code/stop/validate-completion.js +88 -0
- package/.morph/framework/hooks/claude-code/user-prompt/enrich-prompt.js +91 -0
- package/.morph/framework/hooks/git/commit-msg/conventional-commits.sh +33 -0
- package/.morph/framework/hooks/git/pre-commit/agents.sh +25 -0
- package/.morph/framework/hooks/git/pre-commit/orchestrator.sh +64 -0
- package/.morph/framework/hooks/git/pre-commit/specs.sh +50 -0
- package/.morph/framework/hooks/git/pre-push/run-tests.sh +44 -0
- package/.morph/framework/hooks/shared/hook-response.js +45 -0
- package/.morph/framework/hooks/shared/phase-utils.js +129 -0
- package/.morph/framework/hooks/shared/state-reader.js +138 -0
- package/.morph/framework/hooks/shared/stdin-reader.js +26 -0
- package/.morph/framework/standards/STANDARDS.json +933 -0
- package/.morph/framework/standards/ai-agents/blazor-ui.md +364 -0
- package/.morph/framework/standards/ai-agents/production.md +415 -0
- package/.morph/framework/standards/ai-agents/setup.md +418 -0
- package/.morph/framework/standards/ai-agents/team-orchestration.md +479 -0
- package/.morph/framework/standards/ai-agents/workflows.md +354 -0
- package/.morph/framework/standards/architecture/ddd/aggregates.md +120 -0
- package/.morph/framework/standards/architecture/ddd/bounded-contexts.md +105 -0
- package/.morph/framework/standards/architecture/ddd/complexity-levels.md +108 -0
- package/.morph/framework/standards/architecture/ddd/entities.md +99 -0
- package/.morph/framework/standards/architecture/ddd/ubiquitous-language.md +58 -0
- package/.morph/framework/standards/architecture/ddd/value-objects.md +124 -0
- package/.morph/framework/standards/backend/api/minimal-api.md +494 -0
- package/.morph/framework/standards/backend/api/rest.md +492 -0
- package/.morph/framework/standards/backend/api/validation.md +88 -0
- package/.morph/framework/standards/backend/authentication/passkeys.md +428 -0
- package/.morph/framework/standards/backend/database/ef-core.md +199 -0
- package/.morph/framework/standards/backend/database/migrations.md +393 -0
- package/.morph/framework/standards/backend/database/postgresql/database.md +352 -0
- package/.morph/framework/standards/backend/database/repository-patterns.md +528 -0
- package/.morph/framework/standards/backend/database/vector-search-rag.md +541 -0
- package/.morph/framework/standards/backend/dotnet/async.md +366 -0
- package/.morph/framework/standards/backend/dotnet/core.md +117 -0
- package/.morph/framework/standards/backend/dotnet/di.md +439 -0
- package/.morph/framework/standards/backend/dotnet/program-cs-checklist.md +92 -0
- package/.morph/framework/standards/backend/integrations/asaas/asaas-api.md +216 -0
- package/.morph/framework/standards/backend/integrations/clerk/clerk-auth.md +290 -0
- package/.morph/framework/standards/backend/integrations/hangfire/hangfire-jobs.md +350 -0
- package/.morph/framework/standards/backend/integrations/resend/resend-email.md +385 -0
- package/.morph/framework/standards/context/analytics.md +96 -0
- package/.morph/framework/standards/context/bundles.md +110 -0
- package/.morph/framework/standards/context/priming.md +78 -0
- package/.morph/framework/standards/core/architecture.md +185 -0
- package/.morph/framework/standards/core/coding.md +214 -0
- package/.morph/framework/standards/core/git-branching-strategy.md +403 -0
- package/.morph/framework/standards/core/git.md +185 -0
- package/.morph/framework/standards/core/testing.md +295 -0
- package/.morph/framework/standards/data/nosql/blob-storage.md +102 -0
- package/.morph/framework/standards/data/nosql/cache/redis.md +97 -0
- package/.morph/framework/standards/data/nosql/cosmos-db.md +118 -0
- package/.morph/framework/standards/data/vector-search/azure-ai-search.md +121 -0
- package/.morph/framework/standards/data/vector-search/rag-chunking.md +104 -0
- package/.morph/framework/standards/frontend/blazor/design-checklist.md +222 -0
- package/.morph/framework/standards/frontend/blazor/fluent-ui-setup.md +595 -0
- package/.morph/framework/standards/frontend/blazor/fluent-ui.md +137 -0
- package/.morph/framework/standards/frontend/blazor/html-conversion.md +184 -0
- package/.morph/framework/standards/frontend/blazor/lifecycle.md +195 -0
- package/.morph/framework/standards/frontend/blazor/pitfalls.md +198 -0
- package/.morph/framework/standards/frontend/blazor/state.md +191 -0
- package/.morph/framework/standards/frontend/design-system/animations.md +151 -0
- package/.morph/framework/standards/frontend/design-system/naming.md +64 -0
- package/.morph/framework/standards/frontend/nextjs/app-router.md +123 -0
- package/.morph/framework/standards/frontend/nextjs/components.md +132 -0
- package/.morph/framework/standards/frontend/nextjs/data-fetching.md +126 -0
- package/.morph/framework/standards/frontend/nextjs/forms.md +128 -0
- package/.morph/framework/standards/frontend/nextjs/naming-conventions.md +67 -0
- package/.morph/framework/standards/frontend/nextjs/nextjs-patterns.md +215 -0
- package/.morph/framework/standards/frontend/nextjs/project-structure.md +102 -0
- package/.morph/framework/standards/frontend/nextjs/state-management.md +72 -0
- package/.morph/framework/standards/frontend/nextjs/testing.md +111 -0
- package/.morph/framework/standards/infrastructure/azure/azure.md +624 -0
- package/.morph/framework/standards/infrastructure/azure/bicep/bicep-patterns.md +422 -0
- package/.morph/framework/standards/infrastructure/azure/devops/azure-devops-setup.md +516 -0
- package/.morph/framework/standards/infrastructure/azure/devops/local-development.md +520 -0
- package/.morph/framework/standards/infrastructure/azure/services/functions.md +486 -0
- package/.morph/framework/standards/infrastructure/azure/services/service-bus.md +459 -0
- package/.morph/framework/standards/infrastructure/azure/services/storage.md +407 -0
- package/.morph/framework/standards/infrastructure/docker/easypanel-deploy.md +196 -0
- package/.morph/framework/standards/infrastructure/supabase/mcp-setup.md +252 -0
- package/.morph/framework/standards/infrastructure/supabase/supabase-auth.md +176 -0
- package/.morph/framework/standards/infrastructure/supabase/supabase-pgvector.md +169 -0
- package/.morph/framework/standards/infrastructure/supabase/supabase-rls.md +184 -0
- package/.morph/framework/standards/infrastructure/supabase/supabase-storage.md +153 -0
- package/.morph/framework/standards/integration/api/graphql.md +91 -0
- package/.morph/framework/standards/integration/api/grpc.md +114 -0
- package/.morph/framework/standards/integration/api/rest-design.md +95 -0
- package/.morph/framework/standards/integration/event-driven/cqrs.md +101 -0
- package/.morph/framework/standards/integration/event-driven/event-sourcing.md +124 -0
- package/.morph/framework/standards/integration/event-driven/service-bus.md +95 -0
- package/.morph/framework/standards/integration/mcp/mcp-tools.md +384 -0
- package/.morph/framework/standards/observability/logging.md +131 -0
- package/.morph/framework/standards/observability/metrics.md +121 -0
- package/.morph/framework/standards/observability/monitoring.md +114 -0
- package/.morph/framework/standards/observability/tracing.md +132 -0
- package/.morph/framework/standards/workflows/parallel-execution.md +112 -0
- package/.morph/framework/standards/workflows/thread-management.md +113 -0
- package/.morph/framework/templates/.idea/morph-templates.xml +92 -0
- package/.morph/framework/templates/.vscode/morph-templates.code-snippets +186 -0
- package/.morph/framework/templates/IDE-SNIPPETS.md +266 -0
- package/.morph/framework/templates/README.md +814 -0
- package/.morph/framework/templates/REGISTRY.json +1888 -0
- package/.morph/framework/templates/code/dotnet/backend/repository.cs +141 -0
- package/.morph/framework/templates/code/dotnet/backend/service.cs +139 -0
- package/.morph/framework/templates/code/dotnet/contracts/Commands.cs +74 -0
- package/.morph/framework/templates/code/dotnet/contracts/Entities.cs +25 -0
- package/.morph/framework/templates/code/dotnet/contracts/Queries.cs +74 -0
- package/.morph/framework/templates/code/dotnet/contracts/README.md +74 -0
- package/.morph/framework/templates/code/dotnet/contracts/api-contracts.cs +173 -0
- package/.morph/framework/templates/code/dotnet/contracts/contracts-level1.cs +69 -0
- package/.morph/framework/templates/code/dotnet/contracts/contracts-level2.cs +86 -0
- package/.morph/framework/templates/code/dotnet/contracts/contracts-level3.cs +41 -0
- package/.morph/framework/templates/code/dotnet/database/migration.cs +83 -0
- package/.morph/framework/templates/code/dotnet/frontend/component.razor +239 -0
- package/.morph/framework/templates/code/dotnet/jobs/agent.cs +163 -0
- package/.morph/framework/templates/code/dotnet/jobs/job.cs +171 -0
- package/.morph/framework/templates/code/dotnet/test.cs +239 -0
- package/.morph/framework/templates/code/sql/rls-policy.sql +57 -0
- package/.morph/framework/templates/code/sql/supabase-migration.sql +100 -0
- package/.morph/framework/templates/code/sql/supabase-migration.template.sql +113 -0
- package/.morph/framework/templates/code/typescript/contracts.ts +168 -0
- package/.morph/framework/templates/context/CONTEXT-FEATURE.md +276 -0
- package/.morph/framework/templates/context/CONTEXT.md +181 -0
- package/.morph/framework/templates/docs/clarifications.md +253 -0
- package/.morph/framework/templates/docs/onboarding.md +123 -0
- package/.morph/framework/templates/docs/proposal.md +182 -0
- package/.morph/framework/templates/docs/schema-analysis.md +119 -0
- package/.morph/framework/templates/docs/spec.md +198 -0
- package/.morph/framework/templates/docs/ui-components.md +124 -0
- package/.morph/framework/templates/docs/ui-design-system.md +76 -0
- package/.morph/framework/templates/docs/ui-flows.md +167 -0
- package/.morph/framework/templates/docs/ui-mockups.md +98 -0
- package/.morph/framework/templates/docs/user-stories.md +34 -0
- package/.morph/framework/templates/examples/design-system-examples.md +357 -0
- package/.morph/framework/templates/examples/spec-examples.md +90 -0
- package/.morph/framework/templates/feature/decisions.md +187 -0
- package/.morph/framework/templates/feature/recap.md +146 -0
- package/.morph/framework/templates/feature/tasks.md +199 -0
- package/.morph/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +43 -0
- package/.morph/framework/templates/frontend/nextjs/client-component.tsx.hbs +26 -0
- package/.morph/framework/templates/frontend/nextjs/env.mjs.hbs +32 -0
- package/.morph/framework/templates/frontend/nextjs/feature-form.tsx.hbs +56 -0
- package/.morph/framework/templates/frontend/nextjs/page.tsx.hbs +22 -0
- package/.morph/framework/templates/frontend/nextjs/tsconfig.json.hbs +26 -0
- package/.morph/framework/templates/frontend/nextjs/use-feature.ts.hbs +54 -0
- package/.morph/framework/templates/infrastructure/azure/Dockerfile.example +82 -0
- package/.morph/framework/templates/infrastructure/azure/README.md +286 -0
- package/.morph/framework/templates/infrastructure/azure/app-insights.bicep +63 -0
- package/.morph/framework/templates/infrastructure/azure/app-service.bicep +164 -0
- package/.morph/framework/templates/infrastructure/azure/container-app-env.bicep +49 -0
- package/.morph/framework/templates/infrastructure/azure/container-app.bicep +156 -0
- package/.morph/framework/templates/infrastructure/azure/deploy-checklist.md +426 -0
- package/.morph/framework/templates/infrastructure/azure/deploy.ps1 +229 -0
- package/.morph/framework/templates/infrastructure/azure/deploy.sh +208 -0
- package/.morph/framework/templates/infrastructure/azure/key-vault.bicep +91 -0
- package/.morph/framework/templates/infrastructure/azure/main.bicep +189 -0
- package/.morph/framework/templates/infrastructure/azure/parameters.dev.json +29 -0
- package/.morph/framework/templates/infrastructure/azure/parameters.prod.json +29 -0
- package/.morph/framework/templates/infrastructure/azure/parameters.staging.json +29 -0
- package/.morph/framework/templates/infrastructure/azure/sql-database.bicep +103 -0
- package/.morph/framework/templates/infrastructure/azure/storage.bicep +106 -0
- package/.morph/framework/templates/infrastructure/docker/Dockerfile.template +58 -0
- package/.morph/framework/templates/infrastructure/docker/docker-compose.template.yml +67 -0
- package/.morph/framework/templates/infrastructure/docker/dockerfile-api.dockerfile +38 -0
- package/.morph/framework/templates/infrastructure/docker/dockerfile-web.dockerfile +48 -0
- package/.morph/framework/templates/infrastructure/docker/easypanel.template.json +54 -0
- package/.morph/framework/templates/infrastructure/github/README.md +593 -0
- package/.morph/framework/templates/infrastructure/github/actions/azure-auth/action.yml.hbs +22 -0
- package/.morph/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +45 -0
- package/.morph/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +27 -0
- package/.morph/framework/templates/infrastructure/github/workflows/deploy-azure-app-service.yml.hbs +61 -0
- package/.morph/framework/templates/infrastructure/github/workflows/deploy-easypanel.yml.hbs +31 -0
- package/.morph/framework/templates/infrastructure/github/workflows/docker-build-push.yml.hbs +59 -0
- package/.morph/framework/templates/infrastructure/github/workflows/dotnet-build.yml.hbs +39 -0
- package/.morph/framework/templates/integrations/asaas-client.cs +387 -0
- package/.morph/framework/templates/integrations/asaas-webhook.cs +351 -0
- package/.morph/framework/templates/integrations/azure-identity-config.cs +288 -0
- package/.morph/framework/templates/integrations/clerk-config.cs +258 -0
- package/.morph/framework/templates/meta-prompts/fusion/fusion-agent.md +76 -0
- package/.morph/framework/templates/meta-prompts/fusion/fusion-aggregator.md +100 -0
- package/.morph/framework/templates/meta-prompts/hops/hop-retry.md +78 -0
- package/.morph/framework/templates/meta-prompts/hops/hop-validation.md +97 -0
- package/.morph/framework/templates/meta-prompts/hops/hop-wrapper.md +36 -0
- package/.morph/framework/templates/meta-prompts/parallel-workers/parallel-coordinator.md +113 -0
- package/.morph/framework/templates/meta-prompts/parallel-workers/parallel-worker.md +80 -0
- package/.morph/framework/templates/meta-prompts/squad-leaders/backend-squad.md +90 -0
- package/.morph/framework/templates/meta-prompts/squad-leaders/frontend-squad.md +126 -0
- package/.morph/framework/templates/meta-prompts/squad-leaders/squad-leader.md +43 -0
- package/.morph/framework/templates/meta-prompts/validators/checkpoint-validator.md +107 -0
- package/.morph/framework/templates/meta-prompts/validators/pre-commit-validator.md +95 -0
- package/.morph/framework/templates/project-structure/dotnet-ddd.md +70 -0
- package/.morph/framework/templates/saas/subscription.cs +347 -0
- package/.morph/framework/templates/saas/tenant.cs +338 -0
- package/.morph/framework/templates/state.template.json +17 -0
- package/.morph/framework/templates/ui/FluentDesignTheme.cs +149 -0
- package/.morph/framework/templates/ui/MudTheme.cs +281 -0
- package/.morph/framework/templates/ui/design-system.css +226 -0
- package/.morph/logs/tool-failures.log +17 -0
- package/.morph/memory/pre-compact-2026-02-24T17-43-30-049Z.json +16 -0
- package/.morph/plans/eager-watching-bunny.md +105 -0
- package/.morph/plans/temporal-seeking-nebula.md +45 -0
- package/.morph/state.json +48 -0
- package/CLAUDE.md +1 -1
- package/README.md +2 -2
- package/bin/morph-spec.js +0 -9
- package/framework/CLAUDE.md +1 -1
- package/framework/hooks/README.md +10 -6
- package/framework/hooks/claude-code/notification/approval-reminder.js +2 -0
- package/framework/hooks/claude-code/post-tool-use/dispatch.js +1 -1
- package/framework/hooks/claude-code/stop/validate-completion.js +1 -1
- package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +1 -1
- package/package.json +1 -1
- package/src/commands/project/init.js +15 -42
- package/src/commands/project/update.js +22 -37
- package/src/lib/installers/mcp-installer.js +18 -3
- package/src/utils/hooks-installer.js +5 -15
- 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*
|