@zimezone/z-command 1.1.0 → 1.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 (182) hide show
  1. package/package.json +4 -1
  2. package/templates/agents/api-documenter.agent.md +161 -0
  3. package/templates/agents/architect-review.agent.md +146 -0
  4. package/templates/agents/arm-cortex-expert.agent.md +288 -0
  5. package/templates/agents/backend-architect.agent.md +309 -0
  6. package/templates/agents/backend-security-coder.agent.md +152 -0
  7. package/templates/agents/bash-pro.agent.md +285 -0
  8. package/templates/agents/c-pro.agent.md +35 -0
  9. package/templates/agents/c4-code.agent.md +320 -0
  10. package/templates/agents/c4-component.agent.md +227 -0
  11. package/templates/agents/c4-container.agent.md +248 -0
  12. package/templates/agents/c4-context.agent.md +235 -0
  13. package/templates/agents/conductor-validator.agent.md +245 -0
  14. package/templates/agents/csharp-pro.agent.md +38 -0
  15. package/templates/agents/customer-support.agent.md +148 -0
  16. package/templates/agents/database-admin.agent.md +142 -0
  17. package/templates/agents/database-architect.agent.md +238 -0
  18. package/templates/agents/database-optimizer.agent.md +144 -0
  19. package/templates/agents/debugger.agent.md +30 -0
  20. package/templates/agents/deployment-engineer.agent.md +0 -0
  21. package/templates/agents/devops-troubleshooter.agent.md +138 -0
  22. package/templates/agents/django-pro.agent.md +159 -0
  23. package/templates/agents/docs-architect.agent.md +77 -0
  24. package/templates/agents/dotnet-architect.agent.md +175 -0
  25. package/templates/agents/dx-optimizer.agent.md +63 -0
  26. package/templates/agents/elixir-pro.agent.md +38 -0
  27. package/templates/agents/error-detective.agent.md +32 -0
  28. package/templates/agents/event-sourcing-architect.agent.md +42 -0
  29. package/templates/agents/fastapi-pro.agent.md +171 -0
  30. package/templates/agents/firmware-analyst.agent.md +330 -0
  31. package/templates/agents/frontend-security-coder.agent.md +149 -0
  32. package/templates/agents/haskell-pro.agent.md +37 -0
  33. package/templates/agents/hr-pro.agent.md +105 -0
  34. package/templates/agents/incident-responder.agent.md +190 -0
  35. package/templates/agents/ios-developer.agent.md +198 -0
  36. package/templates/agents/java-pro.agent.md +156 -0
  37. package/templates/agents/javascript-pro.agent.md +35 -0
  38. package/templates/agents/julia-pro.agent.md +187 -0
  39. package/templates/agents/legal-advisor.agent.md +49 -0
  40. package/templates/agents/malware-analyst.agent.md +272 -0
  41. package/templates/agents/mermaid-expert.agent.md +39 -0
  42. package/templates/agents/minecraft-bukkit-pro.agent.md +104 -0
  43. package/templates/agents/mobile-security-coder.agent.md +163 -0
  44. package/templates/agents/monorepo-architect.agent.md +44 -0
  45. package/templates/agents/observability-engineer.agent.md +228 -0
  46. package/templates/agents/performance-engineer.agent.md +167 -0
  47. package/templates/agents/php-pro.agent.md +43 -0
  48. package/templates/agents/posix-shell-pro.agent.md +284 -0
  49. package/templates/agents/quant-analyst.agent.md +32 -0
  50. package/templates/agents/reference-builder.agent.md +167 -0
  51. package/templates/agents/reverse-engineer.agent.md +202 -0
  52. package/templates/agents/risk-manager.agent.md +41 -0
  53. package/templates/agents/ruby-pro.agent.md +35 -0
  54. package/templates/agents/rust-pro.agent.md +156 -0
  55. package/templates/agents/sales-automator.agent.md +35 -0
  56. package/templates/agents/scala-pro.agent.md +60 -0
  57. package/templates/agents/search-specialist.agent.md +59 -0
  58. package/templates/agents/security-auditor.agent.md +138 -0
  59. package/templates/agents/seo-authority-builder.agent.md +116 -0
  60. package/templates/agents/seo-cannibalization-detector.agent.md +103 -0
  61. package/templates/agents/seo-content-auditor.agent.md +63 -0
  62. package/templates/agents/seo-content-planner.agent.md +88 -0
  63. package/templates/agents/seo-content-refresher.agent.md +98 -0
  64. package/templates/agents/seo-content-writer.agent.md +76 -0
  65. package/templates/agents/seo-keyword-strategist.agent.md +75 -0
  66. package/templates/agents/seo-meta-optimizer.agent.md +72 -0
  67. package/templates/agents/seo-snippet-hunter.agent.md +94 -0
  68. package/templates/agents/seo-structure-architect.agent.md +88 -0
  69. package/templates/agents/service-mesh-expert.agent.md +41 -0
  70. package/templates/agents/sql-pro.agent.md +146 -0
  71. package/templates/agents/tdd-orchestrator.agent.md +183 -0
  72. package/templates/agents/temporal-python-pro.agent.md +349 -0
  73. package/templates/agents/terraform-specialist.agent.md +137 -0
  74. package/templates/agents/test-automator.agent.md +203 -0
  75. package/templates/agents/threat-modeling-expert.agent.md +44 -0
  76. package/templates/agents/tutorial-engineer.agent.md +118 -0
  77. package/templates/agents/ui-ux-designer.agent.md +188 -0
  78. package/templates/agents/ui-visual-validator.agent.md +192 -0
  79. package/templates/agents/vector-database-engineer.agent.md +43 -0
  80. package/templates/skills/angular-migration/SKILL.md +410 -0
  81. package/templates/skills/api-design-principles/SKILL.md +528 -0
  82. package/templates/skills/api-design-principles/assets/api-design-checklist.md +155 -0
  83. package/templates/skills/api-design-principles/assets/rest-api-template.py +182 -0
  84. package/templates/skills/api-design-principles/references/graphql-schema-design.md +583 -0
  85. package/templates/skills/api-design-principles/references/rest-best-practices.md +408 -0
  86. package/templates/skills/architecture-decision-records/SKILL.md +428 -0
  87. package/templates/skills/architecture-patterns/SKILL.md +494 -0
  88. package/templates/skills/async-python-patterns/SKILL.md +694 -0
  89. package/templates/skills/auth-implementation-patterns/SKILL.md +634 -0
  90. package/templates/skills/changelog-automation/SKILL.md +552 -0
  91. package/templates/skills/code-review-excellence/SKILL.md +520 -0
  92. package/templates/skills/competitive-landscape/SKILL.md +479 -0
  93. package/templates/skills/context-driven-development/SKILL.md +385 -0
  94. package/templates/skills/cost-optimization/SKILL.md +274 -0
  95. package/templates/skills/cqrs-implementation/SKILL.md +554 -0
  96. package/templates/skills/data-quality-frameworks/SKILL.md +587 -0
  97. package/templates/skills/data-storytelling/SKILL.md +453 -0
  98. package/templates/skills/database-migration/SKILL.md +424 -0
  99. package/templates/skills/dbt-transformation-patterns/SKILL.md +561 -0
  100. package/templates/skills/debugging-strategies/SKILL.md +527 -0
  101. package/templates/skills/defi-protocol-templates/SKILL.md +454 -0
  102. package/templates/skills/dependency-upgrade/SKILL.md +409 -0
  103. package/templates/skills/deployment-pipeline-design/SKILL.md +359 -0
  104. package/templates/skills/distributed-tracing/SKILL.md +438 -0
  105. package/templates/skills/dotnet-backend-patterns/SKILL.md +815 -0
  106. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
  107. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
  108. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
  109. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
  110. package/templates/skills/e2e-testing-patterns/SKILL.md +547 -0
  111. package/templates/skills/employment-contract-templates/SKILL.md +507 -0
  112. package/templates/skills/error-handling-patterns/SKILL.md +636 -0
  113. package/templates/skills/event-store-design/SKILL.md +437 -0
  114. package/templates/skills/fastapi-templates/SKILL.md +567 -0
  115. package/templates/skills/git-advanced-workflows/SKILL.md +400 -0
  116. package/templates/skills/github-actions-templates/SKILL.md +333 -0
  117. package/templates/skills/go-concurrency-patterns/SKILL.md +655 -0
  118. package/templates/skills/grafana-dashboards/SKILL.md +369 -0
  119. package/templates/skills/helm-chart-scaffolding/SKILL.md +544 -0
  120. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  121. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  122. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  123. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  124. package/templates/skills/javascript-testing-patterns/SKILL.md +1025 -0
  125. package/templates/skills/langchain-architecture/SKILL.md +338 -0
  126. package/templates/skills/llm-evaluation/SKILL.md +471 -0
  127. package/templates/skills/microservices-patterns/SKILL.md +595 -0
  128. package/templates/skills/modern-javascript-patterns/SKILL.md +911 -0
  129. package/templates/skills/monorepo-management/SKILL.md +622 -0
  130. package/templates/skills/nextjs-app-router-patterns/SKILL.md +544 -0
  131. package/templates/skills/nodejs-backend-patterns/SKILL.md +1020 -0
  132. package/templates/skills/nx-workspace-patterns/SKILL.md +452 -0
  133. package/templates/skills/openapi-spec-generation/SKILL.md +1028 -0
  134. package/templates/skills/paypal-integration/SKILL.md +467 -0
  135. package/templates/skills/pci-compliance/SKILL.md +466 -0
  136. package/templates/skills/postgresql/SKILL.md +204 -0
  137. package/templates/skills/projection-patterns/SKILL.md +490 -0
  138. package/templates/skills/prometheus-configuration/SKILL.md +392 -0
  139. package/templates/skills/prompt-engineering-patterns/SKILL.md +201 -0
  140. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
  141. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
  142. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
  143. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
  144. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
  145. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
  146. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
  147. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
  148. package/templates/skills/python-packaging/SKILL.md +870 -0
  149. package/templates/skills/python-performance-optimization/SKILL.md +869 -0
  150. package/templates/skills/python-testing-patterns/SKILL.md +907 -0
  151. package/templates/skills/rag-implementation/SKILL.md +403 -0
  152. package/templates/skills/react-modernization/SKILL.md +513 -0
  153. package/templates/skills/react-native-architecture/SKILL.md +671 -0
  154. package/templates/skills/react-state-management/SKILL.md +429 -0
  155. package/templates/skills/risk-metrics-calculation/SKILL.md +555 -0
  156. package/templates/skills/rust-async-patterns/SKILL.md +517 -0
  157. package/templates/skills/secrets-management/SKILL.md +346 -0
  158. package/templates/skills/security-requirement-extraction/SKILL.md +677 -0
  159. package/templates/skills/shellcheck-configuration/SKILL.md +454 -0
  160. package/templates/skills/similarity-search-patterns/SKILL.md +558 -0
  161. package/templates/skills/slo-implementation/SKILL.md +329 -0
  162. package/templates/skills/sql-optimization-patterns/SKILL.md +493 -0
  163. package/templates/skills/stripe-integration/SKILL.md +442 -0
  164. package/templates/skills/tailwind-design-system/SKILL.md +666 -0
  165. package/templates/skills/temporal-python-testing/SKILL.md +158 -0
  166. package/templates/skills/temporal-python-testing/resources/integration-testing.md +455 -0
  167. package/templates/skills/temporal-python-testing/resources/local-setup.md +553 -0
  168. package/templates/skills/temporal-python-testing/resources/replay-testing.md +462 -0
  169. package/templates/skills/temporal-python-testing/resources/unit-testing.md +328 -0
  170. package/templates/skills/terraform-module-library/SKILL.md +249 -0
  171. package/templates/skills/terraform-module-library/references/aws-modules.md +63 -0
  172. package/templates/skills/threat-mitigation-mapping/SKILL.md +745 -0
  173. package/templates/skills/track-management/SKILL.md +593 -0
  174. package/templates/skills/typescript-advanced-types/SKILL.md +717 -0
  175. package/templates/skills/uv-package-manager/SKILL.md +831 -0
  176. package/templates/skills/vector-index-tuning/SKILL.md +521 -0
  177. package/templates/skills/wcag-audit-patterns/SKILL.md +555 -0
  178. package/templates/skills/workflow-orchestration-patterns/SKILL.md +316 -0
  179. package/templates/skills/workflow-patterns/SKILL.md +623 -0
  180. package/templates/agents/game-developer.agent.md +0 -57
  181. package/templates/agents/kubernetes-specialist.agent.md +0 -56
  182. package/templates/agents/market-researcher.agent.md +0 -47
@@ -0,0 +1,544 @@
1
+ ---
2
+ name: nextjs-app-router-patterns
3
+ description: Master Next.js 14+ App Router with Server Components, streaming, parallel routes, and advanced data fetching. Use when building Next.js applications, implementing SSR/SSG, or optimizing React Server Components.
4
+ ---
5
+
6
+ # Next.js App Router Patterns
7
+
8
+ Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Building new Next.js applications with App Router
13
+ - Migrating from Pages Router to App Router
14
+ - Implementing Server Components and streaming
15
+ - Setting up parallel and intercepting routes
16
+ - Optimizing data fetching and caching
17
+ - Building full-stack features with Server Actions
18
+
19
+ ## Core Concepts
20
+
21
+ ### 1. Rendering Modes
22
+
23
+ | Mode | Where | When to Use |
24
+ |------|-------|-------------|
25
+ | **Server Components** | Server only | Data fetching, heavy computation, secrets |
26
+ | **Client Components** | Browser | Interactivity, hooks, browser APIs |
27
+ | **Static** | Build time | Content that rarely changes |
28
+ | **Dynamic** | Request time | Personalized or real-time data |
29
+ | **Streaming** | Progressive | Large pages, slow data sources |
30
+
31
+ ### 2. File Conventions
32
+
33
+ ```
34
+ app/
35
+ ├── layout.tsx # Shared UI wrapper
36
+ ├── page.tsx # Route UI
37
+ ├── loading.tsx # Loading UI (Suspense)
38
+ ├── error.tsx # Error boundary
39
+ ├── not-found.tsx # 404 UI
40
+ ├── route.ts # API endpoint
41
+ ├── template.tsx # Re-mounted layout
42
+ ├── default.tsx # Parallel route fallback
43
+ └── opengraph-image.tsx # OG image generation
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ```typescript
49
+ // app/layout.tsx
50
+ import { Inter } from 'next/font/google'
51
+ import { Providers } from './providers'
52
+
53
+ const inter = Inter({ subsets: ['latin'] })
54
+
55
+ export const metadata = {
56
+ title: { default: 'My App', template: '%s | My App' },
57
+ description: 'Built with Next.js App Router',
58
+ }
59
+
60
+ export default function RootLayout({
61
+ children,
62
+ }: {
63
+ children: React.ReactNode
64
+ }) {
65
+ return (
66
+ <html lang="en" suppressHydrationWarning>
67
+ <body className={inter.className}>
68
+ <Providers>{children}</Providers>
69
+ </body>
70
+ </html>
71
+ )
72
+ }
73
+
74
+ // app/page.tsx - Server Component by default
75
+ async function getProducts() {
76
+ const res = await fetch('https://api.example.com/products', {
77
+ next: { revalidate: 3600 }, // ISR: revalidate every hour
78
+ })
79
+ return res.json()
80
+ }
81
+
82
+ export default async function HomePage() {
83
+ const products = await getProducts()
84
+
85
+ return (
86
+ <main>
87
+ <h1>Products</h1>
88
+ <ProductGrid products={products} />
89
+ </main>
90
+ )
91
+ }
92
+ ```
93
+
94
+ ## Patterns
95
+
96
+ ### Pattern 1: Server Components with Data Fetching
97
+
98
+ ```typescript
99
+ // app/products/page.tsx
100
+ import { Suspense } from 'react'
101
+ import { ProductList, ProductListSkeleton } from '@/components/products'
102
+ import { FilterSidebar } from '@/components/filters'
103
+
104
+ interface SearchParams {
105
+ category?: string
106
+ sort?: 'price' | 'name' | 'date'
107
+ page?: string
108
+ }
109
+
110
+ export default async function ProductsPage({
111
+ searchParams,
112
+ }: {
113
+ searchParams: Promise<SearchParams>
114
+ }) {
115
+ const params = await searchParams
116
+
117
+ return (
118
+ <div className="flex gap-8">
119
+ <FilterSidebar />
120
+ <Suspense
121
+ key={JSON.stringify(params)}
122
+ fallback={<ProductListSkeleton />}
123
+ >
124
+ <ProductList
125
+ category={params.category}
126
+ sort={params.sort}
127
+ page={Number(params.page) || 1}
128
+ />
129
+ </Suspense>
130
+ </div>
131
+ )
132
+ }
133
+
134
+ // components/products/ProductList.tsx - Server Component
135
+ async function getProducts(filters: ProductFilters) {
136
+ const res = await fetch(
137
+ `${process.env.API_URL}/products?${new URLSearchParams(filters)}`,
138
+ { next: { tags: ['products'] } }
139
+ )
140
+ if (!res.ok) throw new Error('Failed to fetch products')
141
+ return res.json()
142
+ }
143
+
144
+ export async function ProductList({ category, sort, page }: ProductFilters) {
145
+ const { products, totalPages } = await getProducts({ category, sort, page })
146
+
147
+ return (
148
+ <div>
149
+ <div className="grid grid-cols-3 gap-4">
150
+ {products.map((product) => (
151
+ <ProductCard key={product.id} product={product} />
152
+ ))}
153
+ </div>
154
+ <Pagination currentPage={page} totalPages={totalPages} />
155
+ </div>
156
+ )
157
+ }
158
+ ```
159
+
160
+ ### Pattern 2: Client Components with 'use client'
161
+
162
+ ```typescript
163
+ // components/products/AddToCartButton.tsx
164
+ 'use client'
165
+
166
+ import { useState, useTransition } from 'react'
167
+ import { addToCart } from '@/app/actions/cart'
168
+
169
+ export function AddToCartButton({ productId }: { productId: string }) {
170
+ const [isPending, startTransition] = useTransition()
171
+ const [error, setError] = useState<string | null>(null)
172
+
173
+ const handleClick = () => {
174
+ setError(null)
175
+ startTransition(async () => {
176
+ const result = await addToCart(productId)
177
+ if (result.error) {
178
+ setError(result.error)
179
+ }
180
+ })
181
+ }
182
+
183
+ return (
184
+ <div>
185
+ <button
186
+ onClick={handleClick}
187
+ disabled={isPending}
188
+ className="btn-primary"
189
+ >
190
+ {isPending ? 'Adding...' : 'Add to Cart'}
191
+ </button>
192
+ {error && <p className="text-red-500 text-sm">{error}</p>}
193
+ </div>
194
+ )
195
+ }
196
+ ```
197
+
198
+ ### Pattern 3: Server Actions
199
+
200
+ ```typescript
201
+ // app/actions/cart.ts
202
+ 'use server'
203
+
204
+ import { revalidateTag } from 'next/cache'
205
+ import { cookies } from 'next/headers'
206
+ import { redirect } from 'next/navigation'
207
+
208
+ export async function addToCart(productId: string) {
209
+ const cookieStore = await cookies()
210
+ const sessionId = cookieStore.get('session')?.value
211
+
212
+ if (!sessionId) {
213
+ redirect('/login')
214
+ }
215
+
216
+ try {
217
+ await db.cart.upsert({
218
+ where: { sessionId_productId: { sessionId, productId } },
219
+ update: { quantity: { increment: 1 } },
220
+ create: { sessionId, productId, quantity: 1 },
221
+ })
222
+
223
+ revalidateTag('cart')
224
+ return { success: true }
225
+ } catch (error) {
226
+ return { error: 'Failed to add item to cart' }
227
+ }
228
+ }
229
+
230
+ export async function checkout(formData: FormData) {
231
+ const address = formData.get('address') as string
232
+ const payment = formData.get('payment') as string
233
+
234
+ // Validate
235
+ if (!address || !payment) {
236
+ return { error: 'Missing required fields' }
237
+ }
238
+
239
+ // Process order
240
+ const order = await processOrder({ address, payment })
241
+
242
+ // Redirect to confirmation
243
+ redirect(`/orders/${order.id}/confirmation`)
244
+ }
245
+ ```
246
+
247
+ ### Pattern 4: Parallel Routes
248
+
249
+ ```typescript
250
+ // app/dashboard/layout.tsx
251
+ export default function DashboardLayout({
252
+ children,
253
+ analytics,
254
+ team,
255
+ }: {
256
+ children: React.ReactNode
257
+ analytics: React.ReactNode
258
+ team: React.ReactNode
259
+ }) {
260
+ return (
261
+ <div className="dashboard-grid">
262
+ <main>{children}</main>
263
+ <aside className="analytics-panel">{analytics}</aside>
264
+ <aside className="team-panel">{team}</aside>
265
+ </div>
266
+ )
267
+ }
268
+
269
+ // app/dashboard/@analytics/page.tsx
270
+ export default async function AnalyticsSlot() {
271
+ const stats = await getAnalytics()
272
+ return <AnalyticsChart data={stats} />
273
+ }
274
+
275
+ // app/dashboard/@analytics/loading.tsx
276
+ export default function AnalyticsLoading() {
277
+ return <ChartSkeleton />
278
+ }
279
+
280
+ // app/dashboard/@team/page.tsx
281
+ export default async function TeamSlot() {
282
+ const members = await getTeamMembers()
283
+ return <TeamList members={members} />
284
+ }
285
+ ```
286
+
287
+ ### Pattern 5: Intercepting Routes (Modal Pattern)
288
+
289
+ ```typescript
290
+ // File structure for photo modal
291
+ // app/
292
+ // ├── @modal/
293
+ // │ ├── (.)photos/[id]/page.tsx # Intercept
294
+ // │ └── default.tsx
295
+ // ├── photos/
296
+ // │ └── [id]/page.tsx # Full page
297
+ // └── layout.tsx
298
+
299
+ // app/@modal/(.)photos/[id]/page.tsx
300
+ import { Modal } from '@/components/Modal'
301
+ import { PhotoDetail } from '@/components/PhotoDetail'
302
+
303
+ export default async function PhotoModal({
304
+ params,
305
+ }: {
306
+ params: Promise<{ id: string }>
307
+ }) {
308
+ const { id } = await params
309
+ const photo = await getPhoto(id)
310
+
311
+ return (
312
+ <Modal>
313
+ <PhotoDetail photo={photo} />
314
+ </Modal>
315
+ )
316
+ }
317
+
318
+ // app/photos/[id]/page.tsx - Full page version
319
+ export default async function PhotoPage({
320
+ params,
321
+ }: {
322
+ params: Promise<{ id: string }>
323
+ }) {
324
+ const { id } = await params
325
+ const photo = await getPhoto(id)
326
+
327
+ return (
328
+ <div className="photo-page">
329
+ <PhotoDetail photo={photo} />
330
+ <RelatedPhotos photoId={id} />
331
+ </div>
332
+ )
333
+ }
334
+
335
+ // app/layout.tsx
336
+ export default function RootLayout({
337
+ children,
338
+ modal,
339
+ }: {
340
+ children: React.ReactNode
341
+ modal: React.ReactNode
342
+ }) {
343
+ return (
344
+ <html>
345
+ <body>
346
+ {children}
347
+ {modal}
348
+ </body>
349
+ </html>
350
+ )
351
+ }
352
+ ```
353
+
354
+ ### Pattern 6: Streaming with Suspense
355
+
356
+ ```typescript
357
+ // app/product/[id]/page.tsx
358
+ import { Suspense } from 'react'
359
+
360
+ export default async function ProductPage({
361
+ params,
362
+ }: {
363
+ params: Promise<{ id: string }>
364
+ }) {
365
+ const { id } = await params
366
+
367
+ // This data loads first (blocking)
368
+ const product = await getProduct(id)
369
+
370
+ return (
371
+ <div>
372
+ {/* Immediate render */}
373
+ <ProductHeader product={product} />
374
+
375
+ {/* Stream in reviews */}
376
+ <Suspense fallback={<ReviewsSkeleton />}>
377
+ <Reviews productId={id} />
378
+ </Suspense>
379
+
380
+ {/* Stream in recommendations */}
381
+ <Suspense fallback={<RecommendationsSkeleton />}>
382
+ <Recommendations productId={id} />
383
+ </Suspense>
384
+ </div>
385
+ )
386
+ }
387
+
388
+ // These components fetch their own data
389
+ async function Reviews({ productId }: { productId: string }) {
390
+ const reviews = await getReviews(productId) // Slow API
391
+ return <ReviewList reviews={reviews} />
392
+ }
393
+
394
+ async function Recommendations({ productId }: { productId: string }) {
395
+ const products = await getRecommendations(productId) // ML-based, slow
396
+ return <ProductCarousel products={products} />
397
+ }
398
+ ```
399
+
400
+ ### Pattern 7: Route Handlers (API Routes)
401
+
402
+ ```typescript
403
+ // app/api/products/route.ts
404
+ import { NextRequest, NextResponse } from 'next/server'
405
+
406
+ export async function GET(request: NextRequest) {
407
+ const searchParams = request.nextUrl.searchParams
408
+ const category = searchParams.get('category')
409
+
410
+ const products = await db.product.findMany({
411
+ where: category ? { category } : undefined,
412
+ take: 20,
413
+ })
414
+
415
+ return NextResponse.json(products)
416
+ }
417
+
418
+ export async function POST(request: NextRequest) {
419
+ const body = await request.json()
420
+
421
+ const product = await db.product.create({
422
+ data: body,
423
+ })
424
+
425
+ return NextResponse.json(product, { status: 201 })
426
+ }
427
+
428
+ // app/api/products/[id]/route.ts
429
+ export async function GET(
430
+ request: NextRequest,
431
+ { params }: { params: Promise<{ id: string }> }
432
+ ) {
433
+ const { id } = await params
434
+ const product = await db.product.findUnique({ where: { id } })
435
+
436
+ if (!product) {
437
+ return NextResponse.json(
438
+ { error: 'Product not found' },
439
+ { status: 404 }
440
+ )
441
+ }
442
+
443
+ return NextResponse.json(product)
444
+ }
445
+ ```
446
+
447
+ ### Pattern 8: Metadata and SEO
448
+
449
+ ```typescript
450
+ // app/products/[slug]/page.tsx
451
+ import { Metadata } from 'next'
452
+ import { notFound } from 'next/navigation'
453
+
454
+ type Props = {
455
+ params: Promise<{ slug: string }>
456
+ }
457
+
458
+ export async function generateMetadata({ params }: Props): Promise<Metadata> {
459
+ const { slug } = await params
460
+ const product = await getProduct(slug)
461
+
462
+ if (!product) return {}
463
+
464
+ return {
465
+ title: product.name,
466
+ description: product.description,
467
+ openGraph: {
468
+ title: product.name,
469
+ description: product.description,
470
+ images: [{ url: product.image, width: 1200, height: 630 }],
471
+ },
472
+ twitter: {
473
+ card: 'summary_large_image',
474
+ title: product.name,
475
+ description: product.description,
476
+ images: [product.image],
477
+ },
478
+ }
479
+ }
480
+
481
+ export async function generateStaticParams() {
482
+ const products = await db.product.findMany({ select: { slug: true } })
483
+ return products.map((p) => ({ slug: p.slug }))
484
+ }
485
+
486
+ export default async function ProductPage({ params }: Props) {
487
+ const { slug } = await params
488
+ const product = await getProduct(slug)
489
+
490
+ if (!product) notFound()
491
+
492
+ return <ProductDetail product={product} />
493
+ }
494
+ ```
495
+
496
+ ## Caching Strategies
497
+
498
+ ### Data Cache
499
+
500
+ ```typescript
501
+ // No cache (always fresh)
502
+ fetch(url, { cache: 'no-store' })
503
+
504
+ // Cache forever (static)
505
+ fetch(url, { cache: 'force-cache' })
506
+
507
+ // ISR - revalidate after 60 seconds
508
+ fetch(url, { next: { revalidate: 60 } })
509
+
510
+ // Tag-based invalidation
511
+ fetch(url, { next: { tags: ['products'] } })
512
+
513
+ // Invalidate via Server Action
514
+ 'use server'
515
+ import { revalidateTag, revalidatePath } from 'next/cache'
516
+
517
+ export async function updateProduct(id: string, data: ProductData) {
518
+ await db.product.update({ where: { id }, data })
519
+ revalidateTag('products')
520
+ revalidatePath('/products')
521
+ }
522
+ ```
523
+
524
+ ## Best Practices
525
+
526
+ ### Do's
527
+ - **Start with Server Components** - Add 'use client' only when needed
528
+ - **Colocate data fetching** - Fetch data where it's used
529
+ - **Use Suspense boundaries** - Enable streaming for slow data
530
+ - **Leverage parallel routes** - Independent loading states
531
+ - **Use Server Actions** - For mutations with progressive enhancement
532
+
533
+ ### Don'ts
534
+ - **Don't pass serializable data** - Server → Client boundary limitations
535
+ - **Don't use hooks in Server Components** - No useState, useEffect
536
+ - **Don't fetch in Client Components** - Use Server Components or React Query
537
+ - **Don't over-nest layouts** - Each layout adds to the component tree
538
+ - **Don't ignore loading states** - Always provide loading.tsx or Suspense
539
+
540
+ ## Resources
541
+
542
+ - [Next.js App Router Documentation](https://nextjs.org/docs/app)
543
+ - [Server Components RFC](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md)
544
+ - [Vercel Templates](https://vercel.com/templates/next.js)