@uocnv1998/agent-kit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +56 -0
  2. package/bin/index.js +161 -0
  3. package/package.json +14 -0
  4. package/templates/.agent/ARCHITECTURE.md +37 -0
  5. package/templates/.agent/common/workflows/brainstorm.md +113 -0
  6. package/templates/.agent/designer/ARCHITECTURE.md +24 -0
  7. package/templates/.agent/designer/rules/GEMINI.md +110 -0
  8. package/templates/.agent/designer/skills/SKILL.md +46 -0
  9. package/templates/.agent/designer/workflows/designer-workflow.md +29 -0
  10. package/templates/.agent/dev/backend/ARCHITECTURE.md +49 -0
  11. package/templates/.agent/dev/backend/agents/backend-specialist.md +116 -0
  12. package/templates/.agent/dev/backend/rules/GEMINI.md +114 -0
  13. package/templates/.agent/dev/backend/skills/clichouse-expert/SKILL.md +144 -0
  14. package/templates/.agent/dev/backend/skills/docker/SKILL.md +409 -0
  15. package/templates/.agent/dev/backend/skills/laravel/SKILL.md +63 -0
  16. package/templates/.agent/dev/backend/skills/laravel-tdd/SKILL.md +146 -0
  17. package/templates/.agent/dev/backend/skills/mysql/SKILL.md +83 -0
  18. package/templates/.agent/dev/backend/skills/mysql/references/character-sets.md +66 -0
  19. package/templates/.agent/dev/backend/skills/mysql/references/composite-indexes.md +59 -0
  20. package/templates/.agent/dev/backend/skills/mysql/references/connection-management.md +70 -0
  21. package/templates/.agent/dev/backend/skills/mysql/references/covering-indexes.md +47 -0
  22. package/templates/.agent/dev/backend/skills/mysql/references/data-types.md +69 -0
  23. package/templates/.agent/dev/backend/skills/mysql/references/deadlocks.md +72 -0
  24. package/templates/.agent/dev/backend/skills/mysql/references/explain-analysis.md +66 -0
  25. package/templates/.agent/dev/backend/skills/mysql/references/fulltext-indexes.md +28 -0
  26. package/templates/.agent/dev/backend/skills/mysql/references/index-maintenance.md +110 -0
  27. package/templates/.agent/dev/backend/skills/mysql/references/isolation-levels.md +49 -0
  28. package/templates/.agent/dev/backend/skills/mysql/references/json-column-patterns.md +77 -0
  29. package/templates/.agent/dev/backend/skills/mysql/references/n-plus-one.md +77 -0
  30. package/templates/.agent/dev/backend/skills/mysql/references/online-ddl.md +53 -0
  31. package/templates/.agent/dev/backend/skills/mysql/references/partitioning.md +92 -0
  32. package/templates/.agent/dev/backend/skills/mysql/references/primary-keys.md +70 -0
  33. package/templates/.agent/dev/backend/skills/mysql/references/query-optimization-pitfalls.md +117 -0
  34. package/templates/.agent/dev/backend/skills/mysql/references/replication-lag.md +46 -0
  35. package/templates/.agent/dev/backend/skills/mysql/references/row-locking-gotchas.md +63 -0
  36. package/templates/.agent/dev/common/rules/GIT_COMMIT.md +9 -0
  37. package/templates/.agent/dev/common/skills/tdd-workflow/SKILL.md +149 -0
  38. package/templates/.agent/dev/common/workflows/dev-workflow.md +46 -0
  39. package/templates/.agent/dev/frontend/ARCHITECTURE.md +47 -0
  40. package/templates/.agent/dev/frontend/agents/frontend-specialist.md +593 -0
  41. package/templates/.agent/dev/frontend/rules/GEMINI.md +117 -0
  42. package/templates/.agent/dev/frontend/skills/frontend-design/SKILL.md +418 -0
  43. package/templates/.agent/dev/frontend/skills/frontend-design/animation-guide.md +331 -0
  44. package/templates/.agent/dev/frontend/skills/frontend-design/color-system.md +311 -0
  45. package/templates/.agent/dev/frontend/skills/frontend-design/decision-trees.md +418 -0
  46. package/templates/.agent/dev/frontend/skills/frontend-design/motion-graphics.md +306 -0
  47. package/templates/.agent/dev/frontend/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  48. package/templates/.agent/dev/frontend/skills/frontend-design/scripts/ux_audit.py +722 -0
  49. package/templates/.agent/dev/frontend/skills/frontend-design/typography-system.md +345 -0
  50. package/templates/.agent/dev/frontend/skills/frontend-design/ux-psychology.md +1116 -0
  51. package/templates/.agent/dev/frontend/skills/frontend-design/visual-effects.md +383 -0
  52. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +312 -0
  53. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +240 -0
  54. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/3-server-server-side-performance.md +490 -0
  55. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +264 -0
  56. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
  57. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/6-rendering-rendering-performance.md +432 -0
  58. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/7-js-javascript-performance.md +684 -0
  59. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +150 -0
  60. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/SKILL.md +286 -0
  61. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
  62. package/templates/.agent/dev/frontend/skills/nextjs-react-expert/scripts/react_performance_checker.py +252 -0
  63. package/templates/.agent/dev/frontend/skills/tailwind-patterns/SKILL.md +269 -0
  64. package/templates/.agent/dev/frontend/skills/web-design-guidelines/SKILL.md +57 -0
  65. package/templates/.agent/po_ba/ARCHITECTURE.md +28 -0
  66. package/templates/.agent/po_ba/agents/documentation-writer.md +104 -0
  67. package/templates/.agent/po_ba/agents/product-manager.md +112 -0
  68. package/templates/.agent/po_ba/agents/product-owner.md +95 -0
  69. package/templates/.agent/po_ba/rules/GEMINI.md +142 -0
  70. package/templates/.agent/po_ba/skills/SKILL.md +42 -0
  71. package/templates/.agent/po_ba/workflows/po_ba-workflow.md +21 -0
  72. package/templates/.agent/tester/ARCHITECTURE.md +27 -0
  73. package/templates/.agent/tester/agents/qa-automation-engineer.md +103 -0
  74. package/templates/.agent/tester/agents/test-engineer.md +158 -0
  75. package/templates/.agent/tester/rules/GEMINI.md +147 -0
  76. package/templates/.agent/tester/skills/SKILL.md +57 -0
  77. package/templates/.agent/tester/workflows/tester-workflow.md +32 -0
@@ -0,0 +1,383 @@
1
+ # Visual Effects Reference
2
+
3
+ > Modern CSS effect principles and techniques - learn the concepts, create variations.
4
+ > **No fixed values to copy - understand the patterns.**
5
+
6
+ ---
7
+
8
+ ## 1. Glassmorphism Principles
9
+
10
+ ### What Makes Glassmorphism Work
11
+
12
+ ```
13
+ Key Properties:
14
+ ├── Semi-transparent background (not solid)
15
+ ├── Backdrop blur (frosted glass effect)
16
+ ├── Subtle border (for definition)
17
+ └── Often: light shadow for depth
18
+ ```
19
+
20
+ ### The Pattern (Customize Values)
21
+
22
+ ```css
23
+ .glass {
24
+ /* Transparency: adjust opacity based on content readability */
25
+ background: rgba(R, G, B, OPACITY);
26
+ /* OPACITY: 0.1-0.3 for dark bg, 0.5-0.8 for light bg */
27
+
28
+ /* Blur: higher = more frosted */
29
+ backdrop-filter: blur(AMOUNT);
30
+ /* AMOUNT: 8-12px subtle, 16-24px strong */
31
+
32
+ /* Border: defines edges */
33
+ border: 1px solid rgba(255, 255, 255, OPACITY);
34
+ /* OPACITY: 0.1-0.3 typically */
35
+
36
+ /* Radius: match your design system */
37
+ border-radius: YOUR_RADIUS;
38
+ }
39
+ ```
40
+
41
+ ### When to Use Glassmorphism
42
+ - ✅ Over colorful/image backgrounds
43
+ - ✅ Modals, overlays, cards
44
+ - ✅ Navigation bars with scrolling content behind
45
+ - ❌ Text-heavy content (readability issues)
46
+ - ❌ Simple solid backgrounds (pointless)
47
+
48
+ ### When NOT to Use
49
+ - Low contrast situations
50
+ - Accessibility-critical content
51
+ - Performance-constrained devices
52
+
53
+ ---
54
+
55
+ ## 2. Neomorphism Principles
56
+
57
+ ### What Makes Neomorphism Work
58
+
59
+ ```
60
+ Key Concept: Soft, extruded elements using DUAL shadows
61
+ ├── Light shadow (from light source direction)
62
+ ├── Dark shadow (opposite direction)
63
+ └── Background matches surrounding (same color)
64
+ ```
65
+
66
+ ### The Pattern
67
+
68
+ ```css
69
+ .neo-raised {
70
+ /* Background MUST match parent */
71
+ background: SAME_AS_PARENT;
72
+
73
+ /* Two shadows: light direction + dark direction */
74
+ box-shadow:
75
+ OFFSET OFFSET BLUR rgba(light-color),
76
+ -OFFSET -OFFSET BLUR rgba(dark-color);
77
+
78
+ /* OFFSET: typically 6-12px */
79
+ /* BLUR: typically 12-20px */
80
+ }
81
+
82
+ .neo-pressed {
83
+ /* Inset creates "pushed in" effect */
84
+ box-shadow:
85
+ inset OFFSET OFFSET BLUR rgba(dark-color),
86
+ inset -OFFSET -OFFSET BLUR rgba(light-color);
87
+ }
88
+ ```
89
+
90
+ ### Accessibility Warning
91
+ ⚠️ **Low contrast** - use sparingly, ensure clear boundaries
92
+
93
+ ### When to Use
94
+ - Decorative elements
95
+ - Subtle interactive states
96
+ - Minimalist UI with flat colors
97
+
98
+ ---
99
+
100
+ ## 3. Shadow Hierarchy Principles
101
+
102
+ ### Concept: Shadows Indicate Elevation
103
+
104
+ ```
105
+ Higher elevation = larger shadow
106
+ ├── Level 0: No shadow (flat on surface)
107
+ ├── Level 1: Subtle shadow (slightly raised)
108
+ ├── Level 2: Medium shadow (cards, buttons)
109
+ ├── Level 3: Large shadow (modals, dropdowns)
110
+ └── Level 4: Deep shadow (floating elements)
111
+ ```
112
+
113
+ ### Shadow Properties to Adjust
114
+
115
+ ```css
116
+ box-shadow: OFFSET-X OFFSET-Y BLUR SPREAD COLOR;
117
+
118
+ /* Offset: direction of shadow */
119
+ /* Blur: softness (larger = softer) */
120
+ /* Spread: size expansion */
121
+ /* Color: typically black with low opacity */
122
+ ```
123
+
124
+ ### Principles for Natural Shadows
125
+
126
+ 1. **Y-offset larger than X** (light comes from above)
127
+ 2. **Low opacity** (5-15% for subtle, 15-25% for pronounced)
128
+ 3. **Multiple layers** for realism (ambient + direct)
129
+ 4. **Blur scales with offset** (larger offset = larger blur)
130
+
131
+ ### Dark Mode Shadows
132
+ - Shadows less visible on dark backgrounds
133
+ - May need to increase opacity
134
+ - Or use glow/highlight instead
135
+
136
+ ---
137
+
138
+ ## 4. Gradient Principles
139
+
140
+ ### Types and When to Use
141
+
142
+ | Type | Pattern | Use Case |
143
+ |------|---------|----------|
144
+ | **Linear** | Color A → Color B along line | Backgrounds, buttons, headers |
145
+ | **Radial** | Center → outward | Spotlights, focal points |
146
+ | **Conic** | Around center | Pie charts, creative effects |
147
+
148
+ ### Creating Harmonious Gradients
149
+
150
+ ```
151
+ Good Gradient Rules:
152
+ ├── Use ADJACENT colors on wheel (analogous)
153
+ ├── Or same hue with different lightness
154
+ ├── Avoid complementary (can look harsh)
155
+ └── Add middle stops for smoother transitions
156
+ ```
157
+
158
+ ### Gradient Syntax Pattern
159
+
160
+ ```css
161
+ .gradient {
162
+ background: linear-gradient(
163
+ DIRECTION, /* angle or to-keyword */
164
+ COLOR-STOP-1, /* color + optional position */
165
+ COLOR-STOP-2,
166
+ /* ... more stops */
167
+ );
168
+ }
169
+
170
+ /* DIRECTION examples: */
171
+ /* 90deg, 135deg, to right, to bottom right */
172
+ ```
173
+
174
+ ### Mesh Gradients
175
+
176
+ ```
177
+ Multiple radial gradients overlapped:
178
+ ├── Each at different position
179
+ ├── Each with transparent falloff
180
+ ├── **Mandatory for "Wow" factor in Hero sections**
181
+ └── Creates organic, colorful effect (Search: "Aurora Gradient CSS")
182
+ ```
183
+
184
+ ---
185
+
186
+ ## 5. Border Effects Principles
187
+
188
+ ### Gradient Borders
189
+
190
+ ```
191
+ Technique: Pseudo-element with gradient background
192
+ ├── Element has padding = border width
193
+ ├── Pseudo-element fills with gradient
194
+ └── Mask or clip creates border effect
195
+ ```
196
+
197
+ ### Animated Borders
198
+
199
+ ```
200
+ Technique: Rotating gradient or conic sweep
201
+ ├── Pseudo-element larger than content
202
+ ├── Animation rotates the gradient
203
+ └── Overflow hidden clips to shape
204
+ ```
205
+
206
+ ### Glow Borders
207
+
208
+ ```css
209
+ /* Multiple box-shadows create glow */
210
+ box-shadow:
211
+ 0 0 SMALL-BLUR COLOR,
212
+ 0 0 MEDIUM-BLUR COLOR,
213
+ 0 0 LARGE-BLUR COLOR;
214
+
215
+ /* Each layer adds to the glow */
216
+ ```
217
+
218
+ ---
219
+
220
+ ## 6. Glow Effects Principles
221
+
222
+ ### Text Glow
223
+
224
+ ```css
225
+ text-shadow:
226
+ 0 0 BLUR-1 COLOR,
227
+ 0 0 BLUR-2 COLOR,
228
+ 0 0 BLUR-3 COLOR;
229
+
230
+ /* Multiple layers = stronger glow */
231
+ /* Larger blur = softer spread */
232
+ ```
233
+
234
+ ### Element Glow
235
+
236
+ ```css
237
+ box-shadow:
238
+ 0 0 BLUR-1 COLOR,
239
+ 0 0 BLUR-2 COLOR;
240
+
241
+ /* Use color matching element for realistic glow */
242
+ /* Lower opacity for subtle, higher for neon */
243
+ ```
244
+
245
+ ### Pulsing Glow Animation
246
+
247
+ ```css
248
+ @keyframes glow-pulse {
249
+ 0%, 100% { box-shadow: 0 0 SMALL-BLUR COLOR; }
250
+ 50% { box-shadow: 0 0 LARGE-BLUR COLOR; }
251
+ }
252
+
253
+ /* Easing and duration affect feel */
254
+ ```
255
+
256
+ ---
257
+
258
+ ## 7. Overlay Techniques
259
+
260
+ ### Gradient Overlay on Images
261
+
262
+ ```
263
+ Purpose: Improve text readability over images
264
+ Pattern: Gradient from transparent to opaque
265
+ Position: Where text will appear
266
+ ```
267
+
268
+ ```css
269
+ .overlay::after {
270
+ content: '';
271
+ position: absolute;
272
+ inset: 0;
273
+ background: linear-gradient(
274
+ DIRECTION,
275
+ transparent PERCENTAGE,
276
+ rgba(0,0,0,OPACITY) 100%
277
+ );
278
+ }
279
+ ```
280
+
281
+ ### Colored Overlay
282
+
283
+ ```css
284
+ /* Blend mode or layered gradient */
285
+ background:
286
+ linear-gradient(YOUR-COLOR-WITH-OPACITY),
287
+ url('image.jpg');
288
+ ```
289
+
290
+ ---
291
+
292
+ ## 8. Modern CSS Techniques
293
+
294
+ ### Container Queries (Concept)
295
+
296
+ ```
297
+ Instead of viewport breakpoints:
298
+ ├── Component responds to ITS container
299
+ ├── Truly modular, reusable components
300
+ └── Syntax: @container (condition) { }
301
+ ```
302
+
303
+ ### :has() Selector (Concept)
304
+
305
+ ```
306
+ Parent styling based on children:
307
+ ├── "Parent that has X child"
308
+ ├── Enables previously impossible patterns
309
+ └── Progressive enhancement approach
310
+ ```
311
+
312
+ ### Scroll-Driven Animations (Concept)
313
+
314
+ ```
315
+ Animation progress tied to scroll:
316
+ ├── Entry/exit animations on scroll
317
+ ├── Parallax effects
318
+ ├── Progress indicators
319
+ └── View-based or scroll-based timeline
320
+ ```
321
+
322
+ ---
323
+
324
+ ## 9. Performance Principles
325
+
326
+ ### GPU-Accelerated Properties
327
+
328
+ ```
329
+ CHEAP to animate (GPU):
330
+ ├── transform (translate, scale, rotate)
331
+ └── opacity
332
+
333
+ EXPENSIVE to animate (CPU):
334
+ ├── width, height
335
+ ├── top, left, right, bottom
336
+ ├── margin, padding
337
+ └── box-shadow (recalculates)
338
+ ```
339
+
340
+ ### will-change Usage
341
+
342
+ ```css
343
+ /* Use sparingly, only for heavy animations */
344
+ .heavy-animation {
345
+ will-change: transform;
346
+ }
347
+
348
+ /* Remove after animation if possible */
349
+ ```
350
+
351
+ ### Reduced Motion
352
+
353
+ ```css
354
+ @media (prefers-reduced-motion: reduce) {
355
+ /* Disable or minimize animations */
356
+ /* Respect user preference */
357
+ }
358
+ ```
359
+
360
+ ---
361
+
362
+ ## 10. Effect Selection Checklist
363
+
364
+ Before applying any effect:
365
+
366
+ - [ ] **Does it serve a purpose?** (not just decoration)
367
+ - [ ] **Is it appropriate for the context?** (brand, audience)
368
+ - [ ] **Have you varied from previous projects?** (avoid repetition)
369
+ - [ ] **Is it accessible?** (contrast, motion sensitivity)
370
+ - [ ] **Is it performant?** (especially on mobile)
371
+ - [ ] **Did you ask user preference?** (if style open-ended)
372
+
373
+ ### Anti-Patterns
374
+
375
+ - ❌ Glassmorphism on every element (kitsch)
376
+ - ❌ Dark + neon as default (lazy AI look)
377
+ - ❌ **Static/Flat designs with no depth (FAILED)**
378
+ - ❌ Effects that hurt readability
379
+ - ❌ Animations without purpose
380
+
381
+ ---
382
+
383
+ > **Remember**: Effects enhance meaning. Choose based on purpose and context, not because it "looks cool."
@@ -0,0 +1,312 @@
1
+ # 1. Eliminating Waterfalls
2
+
3
+ > **Impact:** CRITICAL
4
+ > **Focus:** Waterfalls are the #1 performance killer. Each sequential await adds full network latency. Eliminating them yields the largest gains.
5
+
6
+ ---
7
+
8
+ ## Overview
9
+
10
+ This section contains **5 rules** focused on eliminating waterfalls.
11
+
12
+ ---
13
+
14
+ ## Rule 1.1: Defer Await Until Needed
15
+
16
+ **Impact:** HIGH
17
+ **Tags:** async, await, conditional, optimization
18
+
19
+ ## Defer Await Until Needed
20
+
21
+ Move `await` operations into the branches where they're actually used to avoid blocking code paths that don't need them.
22
+
23
+ **Incorrect (blocks both branches):**
24
+
25
+ ```typescript
26
+ async function handleRequest(userId: string, skipProcessing: boolean) {
27
+ const userData = await fetchUserData(userId)
28
+
29
+ if (skipProcessing) {
30
+ // Returns immediately but still waited for userData
31
+ return { skipped: true }
32
+ }
33
+
34
+ // Only this branch uses userData
35
+ return processUserData(userData)
36
+ }
37
+ ```
38
+
39
+ **Correct (only blocks when needed):**
40
+
41
+ ```typescript
42
+ async function handleRequest(userId: string, skipProcessing: boolean) {
43
+ if (skipProcessing) {
44
+ // Returns immediately without waiting
45
+ return { skipped: true }
46
+ }
47
+
48
+ // Fetch only when needed
49
+ const userData = await fetchUserData(userId)
50
+ return processUserData(userData)
51
+ }
52
+ ```
53
+
54
+ **Another example (early return optimization):**
55
+
56
+ ```typescript
57
+ // Incorrect: always fetches permissions
58
+ async function updateResource(resourceId: string, userId: string) {
59
+ const permissions = await fetchPermissions(userId)
60
+ const resource = await getResource(resourceId)
61
+
62
+ if (!resource) {
63
+ return { error: 'Not found' }
64
+ }
65
+
66
+ if (!permissions.canEdit) {
67
+ return { error: 'Forbidden' }
68
+ }
69
+
70
+ return await updateResourceData(resource, permissions)
71
+ }
72
+
73
+ // Correct: fetches only when needed
74
+ async function updateResource(resourceId: string, userId: string) {
75
+ const resource = await getResource(resourceId)
76
+
77
+ if (!resource) {
78
+ return { error: 'Not found' }
79
+ }
80
+
81
+ const permissions = await fetchPermissions(userId)
82
+
83
+ if (!permissions.canEdit) {
84
+ return { error: 'Forbidden' }
85
+ }
86
+
87
+ return await updateResourceData(resource, permissions)
88
+ }
89
+ ```
90
+
91
+ This optimization is especially valuable when the skipped branch is frequently taken, or when the deferred operation is expensive.
92
+
93
+ ---
94
+
95
+ ## Rule 1.2: Dependency-Based Parallelization
96
+
97
+ **Impact:** CRITICAL
98
+ **Tags:** async, parallelization, dependencies, better-all
99
+
100
+ ## Dependency-Based Parallelization
101
+
102
+ For operations with partial dependencies, use `better-all` to maximize parallelism. It automatically starts each task at the earliest possible moment.
103
+
104
+ **Incorrect (profile waits for config unnecessarily):**
105
+
106
+ ```typescript
107
+ const [user, config] = await Promise.all([
108
+ fetchUser(),
109
+ fetchConfig()
110
+ ])
111
+ const profile = await fetchProfile(user.id)
112
+ ```
113
+
114
+ **Correct (config and profile run in parallel):**
115
+
116
+ ```typescript
117
+ import { all } from 'better-all'
118
+
119
+ const { user, config, profile } = await all({
120
+ async user() { return fetchUser() },
121
+ async config() { return fetchConfig() },
122
+ async profile() {
123
+ return fetchProfile((await this.$.user).id)
124
+ }
125
+ })
126
+ ```
127
+
128
+ **Alternative without extra dependencies:**
129
+
130
+ We can also create all the promises first, and do `Promise.all()` at the end.
131
+
132
+ ```typescript
133
+ const userPromise = fetchUser()
134
+ const profilePromise = userPromise.then(user => fetchProfile(user.id))
135
+
136
+ const [user, config, profile] = await Promise.all([
137
+ userPromise,
138
+ fetchConfig(),
139
+ profilePromise
140
+ ])
141
+ ```
142
+
143
+ Reference: [https://github.com/shuding/better-all](https://github.com/shuding/better-all)
144
+
145
+ ---
146
+
147
+ ## Rule 1.3: Prevent Waterfall Chains in API Routes
148
+
149
+ **Impact:** CRITICAL
150
+ **Tags:** api-routes, server-actions, waterfalls, parallelization
151
+
152
+ ## Prevent Waterfall Chains in API Routes
153
+
154
+ In API routes and Server Actions, start independent operations immediately, even if you don't await them yet.
155
+
156
+ **Incorrect (config waits for auth, data waits for both):**
157
+
158
+ ```typescript
159
+ export async function GET(request: Request) {
160
+ const session = await auth()
161
+ const config = await fetchConfig()
162
+ const data = await fetchData(session.user.id)
163
+ return Response.json({ data, config })
164
+ }
165
+ ```
166
+
167
+ **Correct (auth and config start immediately):**
168
+
169
+ ```typescript
170
+ export async function GET(request: Request) {
171
+ const sessionPromise = auth()
172
+ const configPromise = fetchConfig()
173
+ const session = await sessionPromise
174
+ const [config, data] = await Promise.all([
175
+ configPromise,
176
+ fetchData(session.user.id)
177
+ ])
178
+ return Response.json({ data, config })
179
+ }
180
+ ```
181
+
182
+ For operations with more complex dependency chains, use `better-all` to automatically maximize parallelism (see Dependency-Based Parallelization).
183
+
184
+ ---
185
+
186
+ ## Rule 1.4: Promise.all() for Independent Operations
187
+
188
+ **Impact:** CRITICAL
189
+ **Tags:** async, parallelization, promises, waterfalls
190
+
191
+ ## Promise.all() for Independent Operations
192
+
193
+ When async operations have no interdependencies, execute them concurrently using `Promise.all()`.
194
+
195
+ **Incorrect (sequential execution, 3 round trips):**
196
+
197
+ ```typescript
198
+ const user = await fetchUser()
199
+ const posts = await fetchPosts()
200
+ const comments = await fetchComments()
201
+ ```
202
+
203
+ **Correct (parallel execution, 1 round trip):**
204
+
205
+ ```typescript
206
+ const [user, posts, comments] = await Promise.all([
207
+ fetchUser(),
208
+ fetchPosts(),
209
+ fetchComments()
210
+ ])
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Rule 1.5: Strategic Suspense Boundaries
216
+
217
+ **Impact:** HIGH
218
+ **Tags:** async, suspense, streaming, layout-shift
219
+
220
+ ## Strategic Suspense Boundaries
221
+
222
+ Instead of awaiting data in async components before returning JSX, use Suspense boundaries to show the wrapper UI faster while data loads.
223
+
224
+ **Incorrect (wrapper blocked by data fetching):**
225
+
226
+ ```tsx
227
+ async function Page() {
228
+ const data = await fetchData() // Blocks entire page
229
+
230
+ return (
231
+ <div>
232
+ <div>Sidebar</div>
233
+ <div>Header</div>
234
+ <div>
235
+ <DataDisplay data={data} />
236
+ </div>
237
+ <div>Footer</div>
238
+ </div>
239
+ )
240
+ }
241
+ ```
242
+
243
+ The entire layout waits for data even though only the middle section needs it.
244
+
245
+ **Correct (wrapper shows immediately, data streams in):**
246
+
247
+ ```tsx
248
+ function Page() {
249
+ return (
250
+ <div>
251
+ <div>Sidebar</div>
252
+ <div>Header</div>
253
+ <div>
254
+ <Suspense fallback={<Skeleton />}>
255
+ <DataDisplay />
256
+ </Suspense>
257
+ </div>
258
+ <div>Footer</div>
259
+ </div>
260
+ )
261
+ }
262
+
263
+ async function DataDisplay() {
264
+ const data = await fetchData() // Only blocks this component
265
+ return <div>{data.content}</div>
266
+ }
267
+ ```
268
+
269
+ Sidebar, Header, and Footer render immediately. Only DataDisplay waits for data.
270
+
271
+ **Alternative (share promise across components):**
272
+
273
+ ```tsx
274
+ function Page() {
275
+ // Start fetch immediately, but don't await
276
+ const dataPromise = fetchData()
277
+
278
+ return (
279
+ <div>
280
+ <div>Sidebar</div>
281
+ <div>Header</div>
282
+ <Suspense fallback={<Skeleton />}>
283
+ <DataDisplay dataPromise={dataPromise} />
284
+ <DataSummary dataPromise={dataPromise} />
285
+ </Suspense>
286
+ <div>Footer</div>
287
+ </div>
288
+ )
289
+ }
290
+
291
+ function DataDisplay({ dataPromise }: { dataPromise: Promise<Data> }) {
292
+ const data = use(dataPromise) // Unwraps the promise
293
+ return <div>{data.content}</div>
294
+ }
295
+
296
+ function DataSummary({ dataPromise }: { dataPromise: Promise<Data> }) {
297
+ const data = use(dataPromise) // Reuses the same promise
298
+ return <div>{data.summary}</div>
299
+ }
300
+ ```
301
+
302
+ Both components share the same promise, so only one fetch occurs. Layout renders immediately while both components wait together.
303
+
304
+ **When NOT to use this pattern:**
305
+
306
+ - Critical data needed for layout decisions (affects positioning)
307
+ - SEO-critical content above the fold
308
+ - Small, fast queries where suspense overhead isn't worth it
309
+ - When you want to avoid layout shift (loading → content jump)
310
+
311
+ **Trade-off:** Faster initial paint vs potential layout shift. Choose based on your UX priorities.
312
+