@polymorphism-tech/morph-spec 7.0.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +368 -368
  2. package/claude-plugin.json +14 -14
  3. package/docs/CHEATSHEET.md +199 -199
  4. package/docs/QUICKSTART.md +200 -200
  5. package/framework/CLAUDE.md +1 -1
  6. package/framework/MORPH.md +4 -1
  7. package/framework/agents.json +132 -127
  8. package/framework/rubrics/backend.json +41 -36
  9. package/framework/rules/ai-agents-standards.md +45 -15
  10. package/framework/rules/neon-standards.md +25 -26
  11. package/framework/skills/core/morph-brainstorming/SKILL.md +1 -1
  12. package/framework/skills/core/morph-plan/SKILL.md +3 -1
  13. package/framework/skills/core/morph-stack-scan/SKILL.md +3 -3
  14. package/framework/standards/STANDARDS.json +1729 -1133
  15. package/framework/standards/ai-agents/agent-session.md +160 -0
  16. package/framework/standards/ai-agents/batching.md +193 -0
  17. package/framework/standards/ai-agents/context-providers.md +188 -0
  18. package/framework/standards/ai-agents/mcp-server.md +250 -0
  19. package/framework/standards/ai-agents/mcp-tools.md +197 -0
  20. package/framework/standards/ai-agents/middleware-patterns.md +207 -0
  21. package/framework/standards/ai-agents/modalities-image-gen.md +173 -0
  22. package/framework/standards/ai-agents/modalities-speech-to-text.md +171 -0
  23. package/framework/standards/ai-agents/modalities-text-to-speech.md +181 -0
  24. package/framework/standards/ai-agents/modalities-vision.md +201 -0
  25. package/framework/standards/ai-agents/multi-agent-patterns.md +155 -0
  26. package/framework/standards/ai-agents/production.md +114 -258
  27. package/framework/standards/ai-agents/prompts-in-db.md +214 -0
  28. package/framework/standards/ai-agents/providers/model-registry.md +158 -0
  29. package/framework/standards/ai-agents/rag-custom-pgvector.md +243 -0
  30. package/framework/standards/ai-agents/service-tier-flex.md +135 -0
  31. package/framework/standards/ai-agents/setup.md +142 -316
  32. package/framework/standards/ai-agents/structured-output.md +249 -0
  33. package/framework/standards/ai-agents/sweet-spot.md +109 -0
  34. package/framework/standards/ai-agents/workflows.md +114 -284
  35. package/framework/standards/architecture/vertical-slice/vertical-slice.md +439 -429
  36. package/framework/standards/backend/api/validation.md +92 -88
  37. package/framework/standards/backend/database/postgresql/database.md +336 -332
  38. package/framework/standards/backend/database/vector-search-rag.md +599 -541
  39. package/framework/standards/backend/dotnet/fluent-validation-vsa.md +4 -0
  40. package/framework/standards/backend/dotnet/result-pattern.md +4 -0
  41. package/framework/standards/backend/dotnet/scalar-ui.md +176 -172
  42. package/framework/standards/backend/dotnet/scrutor.md +4 -0
  43. package/framework/standards/backend/dotnet/vsa-handler-patterns.md +310 -274
  44. package/framework/standards/backend/integrations/asaas/asaas-api.md +260 -216
  45. package/framework/standards/backend/integrations/hangfire/hangfire-jobs.md +354 -350
  46. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +30 -19
  47. package/framework/standards/backend/integrations/resend/resend-email.md +400 -385
  48. package/framework/standards/data/nosql/cache/redis.md +106 -97
  49. package/framework/standards/data/nosql/cosmos-db.md +127 -118
  50. package/framework/standards/data/vector-search/rag-chunking.md +113 -104
  51. package/framework/standards/frontend/design-system/ai-image-generation.md +4 -0
  52. package/framework/standards/frontend/design-system/animations.md +164 -160
  53. package/framework/standards/frontend/design-system/naming.md +68 -64
  54. package/framework/standards/frontend/gsap/gsap-core.md +14 -8
  55. package/framework/standards/frontend/gsap/gsap-plugins.md +26 -21
  56. package/framework/standards/frontend/gsap/gsap-scrolltrigger.md +9 -7
  57. package/framework/standards/frontend/nextjs/app-router.md +127 -123
  58. package/framework/standards/frontend/nextjs/components.md +136 -132
  59. package/framework/standards/frontend/nextjs/data-fetching.md +130 -126
  60. package/framework/standards/frontend/nextjs/forms.md +134 -128
  61. package/framework/standards/frontend/nextjs/motion-patterns.md +328 -322
  62. package/framework/standards/frontend/nextjs/naming-conventions.md +71 -67
  63. package/framework/standards/frontend/nextjs/nextjs-patterns.md +229 -225
  64. package/framework/standards/frontend/nextjs/project-structure.md +106 -102
  65. package/framework/standards/frontend/nextjs/state-management.md +76 -72
  66. package/framework/standards/frontend/nextjs/testing.md +115 -111
  67. package/framework/standards/infrastructure/docker/easypanel-deploy.md +196 -192
  68. package/framework/standards/infrastructure/neon/neon-pgrag.md +6 -2
  69. package/framework/standards/infrastructure/neon/neon-pgvector.md +4 -0
  70. package/framework/standards/infrastructure/neon/neon-setup.md +5 -1
  71. package/framework/standards/integration/mcp/mcp-tools.md +471 -462
  72. package/framework/templates/CLAUDE.md.core.template +1 -1
  73. package/framework/templates/REGISTRY.json +1745 -1239
  74. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +39 -0
  75. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +68 -0
  76. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +117 -0
  77. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +95 -0
  78. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +61 -0
  79. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +107 -0
  80. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +58 -0
  81. package/framework/templates/code/dotnet/backend/repository.cs +3 -10
  82. package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +58 -0
  83. package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +91 -0
  84. package/package.json +89 -83
  85. package/src/core/templates/template-registry.js +289 -256
  86. package/src/lib/generators/context-generator.js +516 -518
  87. package/src/lib/generators/scaffold-generator.js +23 -26
  88. package/framework/standards/infrastructure/neon/neon-semantic-kernel.md +0 -310
  89. package/framework/templates/integrations/semantic-kernel-neon.cs +0 -125
@@ -1,64 +1,68 @@
1
- # CSS Naming Convention
2
-
3
- > **Scope:** universal
4
- > **Layer:** 0 (always load)
5
- > **Keywords:** css, bem, naming, class names, conventions
6
- > **Load When:** always
7
-
8
- ## Principles
9
-
10
- 1. **Page prefix** — Prevents conflicts
11
- 2. **BEM for components** — Clear hierarchy
12
- 3. **Namespaced variables** — No library collisions
13
- 4. **State suffixes** — Consistent modifiers
14
-
15
- ---
16
-
17
- ## Page Prefixes
18
-
19
- | Page | Example |
20
- |------|---------|
21
- | Home | `.home-hero`, `.home-features` |
22
- | Checkout | `.checkout-form`, `.checkout-summary` |
23
- | Dashboard | `.dashboard-stats`, `.dashboard-chart` |
24
- | Auth | `.auth-form`, `.auth-social-buttons` |
25
-
26
- ## BEM for Reusable Components
27
-
28
- ```css
29
- .card { } /* Block */
30
- .card__header { } /* Element */
31
- .card__body { }
32
- .card--featured { } /* Modifier */
33
- ```
34
-
35
- **Rule:** BEM for reusable components. Page prefix for page-specific elements.
36
-
37
- ## CSS Variables with Namespace
38
-
39
- ```css
40
- :root {
41
- --app-primary: #007bff;
42
- --app-spacing-md: 1rem;
43
- --app-font-heading: 'Segoe UI', sans-serif;
44
- }
45
- ```
46
-
47
- ## State Suffixes
48
-
49
- | State | Suffix |
50
- |-------|--------|
51
- | Active | `--active` |
52
- | Disabled | `--disabled` |
53
- | Loading | `--loading` |
54
- | Error | `--error` |
55
-
56
- ```css
57
- .button { }
58
- .button--active { }
59
- .button--disabled { }
60
- ```
61
-
62
- ---
63
-
64
- *MORPH-SPEC by Polymorphism Tech*
1
+ # CSS Naming Convention
2
+
3
+ > **Scope:** universal
4
+ > **Layer:** 0 (always load)
5
+ > **Keywords:** css, bem, naming, class names, conventions
6
+ > **Load When:** always
7
+
8
+ **Verified against:** CSS (BEM + custom properties — language-level, no framework). Last-verified: 2026-05-20.
9
+
10
+ ---
11
+
12
+ ## Principles
13
+
14
+ 1. **Page prefix** — Prevents conflicts
15
+ 2. **BEM for components** — Clear hierarchy
16
+ 3. **Namespaced variables** — No library collisions
17
+ 4. **State suffixes** — Consistent modifiers
18
+
19
+ ---
20
+
21
+ ## Page Prefixes
22
+
23
+ | Page | Example |
24
+ |------|---------|
25
+ | Home | `.home-hero`, `.home-features` |
26
+ | Checkout | `.checkout-form`, `.checkout-summary` |
27
+ | Dashboard | `.dashboard-stats`, `.dashboard-chart` |
28
+ | Auth | `.auth-form`, `.auth-social-buttons` |
29
+
30
+ ## BEM for Reusable Components
31
+
32
+ ```css
33
+ .card { } /* Block */
34
+ .card__header { } /* Element */
35
+ .card__body { }
36
+ .card--featured { } /* Modifier */
37
+ ```
38
+
39
+ **Rule:** BEM for reusable components. Page prefix for page-specific elements.
40
+
41
+ ## CSS Variables with Namespace
42
+
43
+ ```css
44
+ :root {
45
+ --app-primary: #007bff;
46
+ --app-spacing-md: 1rem;
47
+ --app-font-heading: 'Segoe UI', sans-serif;
48
+ }
49
+ ```
50
+
51
+ ## State Suffixes
52
+
53
+ | State | Suffix |
54
+ |-------|--------|
55
+ | Active | `--active` |
56
+ | Disabled | `--disabled` |
57
+ | Loading | `--loading` |
58
+ | Error | `--error` |
59
+
60
+ ```css
61
+ .button { }
62
+ .button--active { }
63
+ .button--disabled { }
64
+ ```
65
+
66
+ ---
67
+
68
+ *MORPH-SPEC by Polymorphism Tech*
@@ -1,12 +1,14 @@
1
- ---
2
- scope: frontend-nextjs-ui
3
- layer: 3
4
- keywords: gsap, animation, timeline, tween, useGSAP, greensock, transform
5
- load_when: gsap-animator active
6
- ---
7
-
8
1
  # GSAP Core & React Integration
9
2
 
3
+ > **Scope:** frontend-nextjs-ui
4
+ > **Layer:** 3
5
+ > **Keywords:** gsap, animation, timeline, tween, useGSAP, greensock, transform
6
+ > **Load When:** gsap-animator active
7
+
8
+ **Verified against:** GSAP 3.13 + @gsap/react. Last-verified: 2026-05-20.
9
+
10
+ ---
11
+
10
12
  Reference guide for implementing animations in Next.js projects using GSAP and the official @gsap/react bindings. Covers core APIs, React integration via useGSAP, timeline sequencing, utility functions, performance, accessibility, and the decision boundary with Framer Motion.
11
13
 
12
14
  ---
@@ -33,7 +35,11 @@ Reference guide for implementing animations in Next.js projects using GSAP and t
33
35
  npm install gsap @gsap/react
34
36
  ```
35
37
 
36
- GSAP 3.12+ includes Flip, Observer, and ScrollToPlugin for free. Premium plugins (SplitText, MorphSVG, DrawSVG, MotionPath, Draggable, InertiaPlugin) require a Club GreenSock license — install via `gsap@npm:@gsap/shockingly`.
38
+ Since the Webflow acquisition, **GSAP and every plugin are free for commercial
39
+ use**. The public `gsap` package includes Flip, Observer, ScrollToPlugin, and the
40
+ formerly-premium plugins (SplitText, MorphSVG, DrawSVG, MotionPath, Draggable,
41
+ InertiaPlugin) — no Club GreenSock membership or private registry needed. See
42
+ `gsap-plugins.md` for the per-plugin API.
37
43
 
38
44
  ### Plugin Registration
39
45
 
@@ -1,28 +1,33 @@
1
- ---
2
- scope: frontend-nextjs-gsap
3
- layer: 3
4
- keywords: flip, splittext, morphsvg, drawsvg, motionpath, draggable, observer, scrollto, gsap-plugins
5
- load_when: gsap-animator active
6
- ---
7
-
8
1
  # GSAP Plugins
9
2
 
10
- Reference guide for GSAP's plugin ecosystem in Next.js. Covers free plugins (Flip, Observer, ScrollToPlugin) and Club GreenSock premium plugins (SplitText, MorphSVG, DrawSVG, MotionPath, Draggable, InertiaPlugin).
3
+ > **Scope:** frontend-nextjs-gsap
4
+ > **Layer:** 3
5
+ > **Keywords:** flip, splittext, morphsvg, drawsvg, motionpath, draggable, observer, scrollto, gsap-plugins
6
+ > **Load When:** gsap-animator active
11
7
 
12
- ## Plugin Registration & Licensing
8
+ **Verified against:** GSAP 3.13 + @gsap/react. Last-verified: 2026-05-20.
9
+
10
+ ---
13
11
 
14
- Free plugins (included in gsap 3.12+): Flip, Observer, ScrollToPlugin
12
+ Reference guide for GSAP's plugin ecosystem in Next.js. Covers the full plugin set — Flip, Observer, ScrollToPlugin, SplitText, MorphSVG, DrawSVG, MotionPath, Draggable, InertiaPlugin.
15
13
 
16
- Premium (Club GreenSock): SplitText, MorphSVG, DrawSVG, MotionPath, Draggable, InertiaPlugin, ScrambleText, CustomEase, CustomWiggle, CustomBounce, Physics2D, PhysicsProps
14
+ ## Plugin Registration & Licensing
17
15
 
18
- ```bash
19
- # Free plugins — included with gsap
20
- npm install gsap
16
+ Since the Webflow acquisition, **GSAP and every plugin are free for commercial
17
+ use** — no Club GreenSock membership, no license key, no auth token, no private
18
+ registry. The formerly-premium plugins (SplitText, MorphSVG, DrawSVG, MotionPath,
19
+ Draggable, InertiaPlugin, ScrambleText, CustomEase, CustomWiggle, CustomBounce,
20
+ Physics2D, PhysicsProps) now ship in the public `gsap` package alongside Flip,
21
+ Observer, and ScrollToPlugin.
21
22
 
22
- # Premium plugins — requires Club GreenSock license
23
- npm install gsap@npm:@gsap/shockingly
23
+ ```bash
24
+ # Everything — core + all plugins — installs from the public package
25
+ npm install gsap @gsap/react
24
26
  ```
25
27
 
28
+ > Disregard any older instruction to install `gsap@npm:@gsap/shockingly` or
29
+ > configure a private npm registry — that path is obsolete.
30
+
26
31
  Registration pattern (do ONCE at app init):
27
32
 
28
33
  ```typescript
@@ -70,7 +75,7 @@ function FilterableGrid({ items, filter }: { items: Item[]; filter: string }) {
70
75
 
71
76
  Use cases: filterable grids, list reordering, expanding cards, shared element transitions.
72
77
 
73
- ## SplitText (Premium)
78
+ ## SplitText
74
79
 
75
80
  Split text into chars, words, or lines for staggered reveals:
76
81
 
@@ -101,7 +106,7 @@ Key points:
101
106
  - The split creates `<div>` wrappers -- this affects layout. Test carefully.
102
107
  - useGSAP automatically reverts the split on unmount
103
108
 
104
- ## MorphSVG (Premium)
109
+ ## MorphSVG
105
110
 
106
111
  Morph between SVG shapes:
107
112
 
@@ -125,7 +130,7 @@ Rules:
125
130
  - Match point counts for smoother morphs
126
131
  - `type: "rotational"` is smoother for most shapes
127
132
 
128
- ## DrawSVG (Premium)
133
+ ## DrawSVG
129
134
 
130
135
  Animate SVG stroke drawing:
131
136
 
@@ -151,7 +156,7 @@ gsap.from(paths, {
151
156
 
152
157
  Requires SVG elements with visible `stroke` and `stroke-width`. Does not work on `fill`.
153
158
 
154
- ## MotionPath (Premium)
159
+ ## MotionPath
155
160
 
156
161
  Animate elements along SVG paths:
157
162
 
@@ -192,7 +197,7 @@ gsap.to(window, {
192
197
  });
193
198
  ```
194
199
 
195
- ## Draggable (Premium)
200
+ ## Draggable
196
201
 
197
202
  Make elements draggable with optional physics:
198
203
 
@@ -1,12 +1,14 @@
1
- ---
2
- scope: frontend-nextjs-gsap
3
- layer: 3
4
- keywords: scrolltrigger, scroll-animation, pinning, scrubbing, parallax, scroll-driven, gsap
5
- load_when: gsap-animator active
6
- ---
7
-
8
1
  # GSAP ScrollTrigger — Next.js
9
2
 
3
+ > **Scope:** frontend-nextjs-gsap
4
+ > **Layer:** 3
5
+ > **Keywords:** scrolltrigger, scroll-animation, pinning, scrubbing, parallax, scroll-driven, gsap
6
+ > **Load When:** gsap-animator active
7
+
8
+ **Verified against:** GSAP 3.13 ScrollTrigger + @gsap/react. Last-verified: 2026-05-20.
9
+
10
+ ---
11
+
10
12
  Reference guide for implementing scroll-driven animations in Next.js projects using GSAP ScrollTrigger. Covers plugin setup, scrubbing, pinning, batch processing, responsive breakpoints, SSR considerations, and mandatory cleanup patterns.
11
13
 
12
14
  ---
@@ -1,123 +1,127 @@
1
- # Next.js App Router Standard
2
-
3
- > **Scope:** frontend/nextjs/app-router
4
- > **Layer:** 2 (on keyword)
5
- > **Keywords:** next.js, app router, server component, client component, page, layout, route
6
- > **Load When:** editing files in `app/` or `features/` directories
7
-
8
- Next.js App Router with TypeScript strict mode. Server Components by default, Client Components only when interactivity is required.
9
-
10
- ## Core Rules
11
-
12
- - ALWAYS default to Server Components — add `'use client'` only when needed
13
- - ALWAYS keep `app/` directory for routing only — no business logic in page files
14
- - NEVER put data fetching in Client Components when a Server Component can do it
15
- - NEVER use `useEffect` to fetch data — use Server Components or TanStack Query
16
- - ALWAYS co-locate loading/error UI: `loading.tsx`, `error.tsx` next to `page.tsx`
17
- - ALWAYS use TypeScript — no `.js` or `.jsx` files in the project
18
-
19
- ## Server vs Client Components
20
-
21
- | Use Server Component | Use Client Component |
22
- |---------------------|---------------------|
23
- | Fetching from .NET API on load | onClick, onChange, form submit |
24
- | Rendering static or user-specific data | useState, useEffect, useRef |
25
- | Accessing backend environment variables | Browser APIs (localStorage, geolocation) |
26
- | SEO-critical content | TanStack Query hooks |
27
- | No interactivity needed | shadcn/ui interactive components |
28
-
29
- ## Decision Tree
30
-
31
- ```
32
- Does this component need user interaction (click, input, hover state)?
33
- YES → 'use client'
34
- NO → Does it fetch data?
35
- YES → Server Component (fetch directly)
36
- NO → Server Component (static)
37
- ```
38
-
39
- ## App Directory Structure
40
-
41
- ```
42
- src/app/
43
- ├── (auth)/
44
- │ ├── login/
45
- │ │ └── page.tsx # Server Component — renders login form
46
- │ └── register/
47
- │ └── page.tsx
48
- ├── (dashboard)/
49
- │ ├── layout.tsx # Shared layout for dashboard routes
50
- │ ├── page.tsx # Dashboard home
51
- │ └── users/
52
- │ ├── page.tsx # User list (Server Component)
53
- │ ├── [id]/
54
- │ │ └── page.tsx # User detail
55
- │ ├── loading.tsx # Suspense fallback
56
- │ └── error.tsx # Error boundary
57
- └── layout.tsx # Root layout — providers, fonts, metadata
58
- ```
59
-
60
- ## File Conventions
61
-
62
- | File | Purpose | Type |
63
- |------|---------|------|
64
- | `page.tsx` | Route segment UI | Server Component (default) |
65
- | `layout.tsx` | Shared UI wrapper | Server Component |
66
- | `loading.tsx` | Suspense fallback | Server Component |
67
- | `error.tsx` | Error boundary | **Must be Client Component** |
68
- | `not-found.tsx` | 404 page | Server Component |
69
- | `route.ts` | API route (avoid — use .NET API) | — |
70
-
71
- ## Server Component Data Fetch Pattern
72
-
73
- ```tsx
74
- // app/(dashboard)/users/page.tsx
75
- import { UserList } from '@/features/users/components/user-list';
76
-
77
- async function getUsers(): Promise<User[]> {
78
- const res = await fetch(`${process.env.API_URL}/api/users`, {
79
- next: { revalidate: 60 },
80
- });
81
- if (!res.ok) throw new Error('Failed to fetch users');
82
- return res.json();
83
- }
84
-
85
- export default async function UsersPage() {
86
- const users = await getUsers();
87
- return <UserList initialUsers={users} />;
88
- }
89
- ```
90
-
91
- ## Root Layout — Required Providers
92
-
93
- ```tsx
94
- // app/layout.tsx
95
- import { QueryProvider } from '@/lib/query-client';
96
- import { Toaster } from '@/components/ui/sonner';
97
-
98
- export default function RootLayout({ children }: { children: React.ReactNode }) {
99
- return (
100
- <html lang="pt-BR">
101
- <body>
102
- <QueryProvider>
103
- {children}
104
- <Toaster />
105
- </QueryProvider>
106
- </body>
107
- </html>
108
- );
109
- }
110
- ```
111
-
112
- ## Common Mistakes
113
-
114
- | Wrong | Right | Why |
115
- |-------|-------|-----|
116
- | `'use client'` on every component | Only add when needed | Kills SSR benefits, bloats JS bundle |
117
- | `useEffect(() => { fetch(...) }, [])` | Server Component fetch or TanStack Query | Two renders, no caching, no SSR |
118
- | Business logic in `page.tsx` | Move to `features/` | pages are routes, not controllers |
119
- | `fetch` without error handling | Always check `res.ok` | Silent failures in production |
120
-
121
- ---
122
-
123
- *MORPH-SPEC by Polymorphism Tech*
1
+ # Next.js App Router Standard
2
+
3
+ > **Scope:** frontend/nextjs/app-router
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** next.js, app router, server component, client component, page, layout, route
6
+ > **Load When:** editing files in `app/` or `features/` directories
7
+
8
+ **Verified against:** Next.js 15. Last-verified: 2026-05-20.
9
+
10
+ ---
11
+
12
+ Next.js App Router with TypeScript strict mode. Server Components by default, Client Components only when interactivity is required.
13
+
14
+ ## Core Rules
15
+
16
+ - ALWAYS default to Server Components — add `'use client'` only when needed
17
+ - ALWAYS keep `app/` directory for routing only — no business logic in page files
18
+ - NEVER put data fetching in Client Components when a Server Component can do it
19
+ - NEVER use `useEffect` to fetch data — use Server Components or TanStack Query
20
+ - ALWAYS co-locate loading/error UI: `loading.tsx`, `error.tsx` next to `page.tsx`
21
+ - ALWAYS use TypeScript — no `.js` or `.jsx` files in the project
22
+
23
+ ## Server vs Client Components
24
+
25
+ | Use Server Component | Use Client Component |
26
+ |---------------------|---------------------|
27
+ | Fetching from .NET API on load | onClick, onChange, form submit |
28
+ | Rendering static or user-specific data | useState, useEffect, useRef |
29
+ | Accessing backend environment variables | Browser APIs (localStorage, geolocation) |
30
+ | SEO-critical content | TanStack Query hooks |
31
+ | No interactivity needed | shadcn/ui interactive components |
32
+
33
+ ## Decision Tree
34
+
35
+ ```
36
+ Does this component need user interaction (click, input, hover state)?
37
+ YES → 'use client'
38
+ NO → Does it fetch data?
39
+ YES → Server Component (fetch directly)
40
+ NO → Server Component (static)
41
+ ```
42
+
43
+ ## App Directory Structure
44
+
45
+ ```
46
+ src/app/
47
+ ├── (auth)/
48
+ │ ├── login/
49
+ │ │ └── page.tsx # Server Component — renders login form
50
+ │ └── register/
51
+ │ └── page.tsx
52
+ ├── (dashboard)/
53
+ │ ├── layout.tsx # Shared layout for dashboard routes
54
+ │ ├── page.tsx # Dashboard home
55
+ │ └── users/
56
+ │ ├── page.tsx # User list (Server Component)
57
+ │ ├── [id]/
58
+ │ │ └── page.tsx # User detail
59
+ │ ├── loading.tsx # Suspense fallback
60
+ │ └── error.tsx # Error boundary
61
+ └── layout.tsx # Root layout — providers, fonts, metadata
62
+ ```
63
+
64
+ ## File Conventions
65
+
66
+ | File | Purpose | Type |
67
+ |------|---------|------|
68
+ | `page.tsx` | Route segment UI | Server Component (default) |
69
+ | `layout.tsx` | Shared UI wrapper | Server Component |
70
+ | `loading.tsx` | Suspense fallback | Server Component |
71
+ | `error.tsx` | Error boundary | **Must be Client Component** |
72
+ | `not-found.tsx` | 404 page | Server Component |
73
+ | `route.ts` | API route (avoid — use .NET API) | — |
74
+
75
+ ## Server Component Data Fetch Pattern
76
+
77
+ ```tsx
78
+ // app/(dashboard)/users/page.tsx
79
+ import { UserList } from '@/features/users/components/user-list';
80
+
81
+ async function getUsers(): Promise<User[]> {
82
+ const res = await fetch(`${process.env.API_URL}/api/users`, {
83
+ next: { revalidate: 60 },
84
+ });
85
+ if (!res.ok) throw new Error('Failed to fetch users');
86
+ return res.json();
87
+ }
88
+
89
+ export default async function UsersPage() {
90
+ const users = await getUsers();
91
+ return <UserList initialUsers={users} />;
92
+ }
93
+ ```
94
+
95
+ ## Root Layout — Required Providers
96
+
97
+ ```tsx
98
+ // app/layout.tsx
99
+ import { QueryProvider } from '@/lib/query-client';
100
+ import { Toaster } from '@/components/ui/sonner';
101
+
102
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
103
+ return (
104
+ <html lang="pt-BR">
105
+ <body>
106
+ <QueryProvider>
107
+ {children}
108
+ <Toaster />
109
+ </QueryProvider>
110
+ </body>
111
+ </html>
112
+ );
113
+ }
114
+ ```
115
+
116
+ ## Common Mistakes
117
+
118
+ | Wrong | Right | Why |
119
+ |-------|-------|-----|
120
+ | `'use client'` on every component | Only add when needed | Kills SSR benefits, bloats JS bundle |
121
+ | `useEffect(() => { fetch(...) }, [])` | Server Component fetch or TanStack Query | Two renders, no caching, no SSR |
122
+ | Business logic in `page.tsx` | Move to `features/` | pages are routes, not controllers |
123
+ | `fetch` without error handling | Always check `res.ok` | Silent failures in production |
124
+
125
+ ---
126
+
127
+ *MORPH-SPEC by Polymorphism Tech*