@vudovn/antigravity-kit 1.0.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.
- package/README.md +311 -0
- package/bin/index.js +240 -0
- package/package.json +39 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/core.py +245 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/search.py +69 -0
- package/templates/.agent/rules/01-identity.md +17 -0
- package/templates/.agent/rules/02-task-classification.md +36 -0
- package/templates/.agent/rules/03-mode-consulting.md +54 -0
- package/templates/.agent/rules/04-mode-build.md +54 -0
- package/templates/.agent/rules/05-mode-debug.md +66 -0
- package/templates/.agent/rules/06-mode-optimize.md +64 -0
- package/templates/.agent/rules/07-technical-standards.md +61 -0
- package/templates/.agent/rules/08-communication.md +34 -0
- package/templates/.agent/rules/09-checklist.md +45 -0
- package/templates/.agent/rules/10-special-situations.md +81 -0
- package/templates/.agent/skills/accessibility-expert/SKILL.md +430 -0
- package/templates/.agent/skills/ai-sdk-expert/SKILL.md +541 -0
- package/templates/.agent/skills/auth-expert/SKILL.md +105 -0
- package/templates/.agent/skills/cli-expert/SKILL.md +848 -0
- package/templates/.agent/skills/code-review/SKILL.md +424 -0
- package/templates/.agent/skills/css-expert/SKILL.md +401 -0
- package/templates/.agent/skills/database-expert/SKILL.md +324 -0
- package/templates/.agent/skills/devops-expert/SKILL.md +784 -0
- package/templates/.agent/skills/docker-expert/SKILL.md +409 -0
- package/templates/.agent/skills/documentation-expert/SKILL.md +493 -0
- package/templates/.agent/skills/git-expert/SKILL.md +522 -0
- package/templates/.agent/skills/github-actions-expert/SKILL.md +454 -0
- package/templates/.agent/skills/jest-expert/SKILL.md +957 -0
- package/templates/.agent/skills/mongodb-expert/SKILL.md +761 -0
- package/templates/.agent/skills/nestjs-expert/SKILL.md +552 -0
- package/templates/.agent/skills/nextjs-expert/SKILL.md +443 -0
- package/templates/.agent/skills/nodejs-expert/SKILL.md +192 -0
- package/templates/.agent/skills/oracle/SKILL.md +340 -0
- package/templates/.agent/skills/playwright-expert/SKILL.md +214 -0
- package/templates/.agent/skills/postgres-expert/SKILL.md +642 -0
- package/templates/.agent/skills/prisma-expert/SKILL.md +355 -0
- package/templates/.agent/skills/react-expert/SKILL.md +310 -0
- package/templates/.agent/skills/react-performance/SKILL.md +816 -0
- package/templates/.agent/skills/refactoring-expert/SKILL.md +394 -0
- package/templates/.agent/skills/research-expert/SKILL.md +231 -0
- package/templates/.agent/skills/rest-api-expert/SKILL.md +469 -0
- package/templates/.agent/skills/state-management-expert/SKILL.md +157 -0
- package/templates/.agent/skills/testing-expert/SKILL.md +621 -0
- package/templates/.agent/skills/triage-expert/SKILL.md +419 -0
- package/templates/.agent/skills/typescript-expert/SKILL.md +429 -0
- package/templates/.agent/skills/typescript-type/SKILL.md +790 -0
- package/templates/.agent/skills/ui-ux-pro-max/SKILL.md +228 -0
- package/templates/.agent/skills/vite-expert/SKILL.md +785 -0
- package/templates/.agent/skills/vitest-expert/SKILL.md +325 -0
- package/templates/.agent/skills/webpack-expert/SKILL.md +745 -0
- package/templates/.agent/workflows/request.md +82 -0
- package/templates/.agent/workflows/ui-ux-pro-max.md +231 -0
- package/templates/web/README.md +36 -0
- package/templates/web/eslint.config.mjs +18 -0
- package/templates/web/next.config.ts +8 -0
- package/templates/web/package-lock.json +6549 -0
- package/templates/web/package.json +27 -0
- package/templates/web/postcss.config.mjs +7 -0
- package/templates/web/public/favicon.ico +0 -0
- package/templates/web/public/images/antigravity-kit-logo.png +0 -0
- package/templates/web/public/images/claudekit.png +0 -0
- package/templates/web/public/images/logo.png +0 -0
- package/templates/web/src/app/globals.css +276 -0
- package/templates/web/src/app/layout.tsx +55 -0
- package/templates/web/src/app/page.tsx +23 -0
- package/templates/web/src/components/Credits.tsx +162 -0
- package/templates/web/src/components/Features.tsx +92 -0
- package/templates/web/src/components/Footer.tsx +74 -0
- package/templates/web/src/components/Hero.tsx +117 -0
- package/templates/web/src/components/HowItWorks.tsx +96 -0
- package/templates/web/src/components/Navbar.tsx +87 -0
- package/templates/web/src/components/Skills.tsx +182 -0
- package/templates/web/tsconfig.json +34 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nextjs-expert
|
|
3
|
+
description: Next.js framework expert specializing in App Router, Server Components, performance optimization, data fetching patterns, and full-stack development. Use this skill for Next.js routing issues, hydration errors, build problems, or deployment challenges.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Next.js Expert
|
|
7
|
+
|
|
8
|
+
You are an expert in Next.js 13-15 with deep knowledge of App Router, Server Components, data fetching patterns, performance optimization, and deployment strategies.
|
|
9
|
+
|
|
10
|
+
## When Invoked
|
|
11
|
+
|
|
12
|
+
### Step 0: Recommend Specialist and Stop
|
|
13
|
+
If the issue is specifically about:
|
|
14
|
+
- **React component patterns**: Stop and recommend react-expert
|
|
15
|
+
- **TypeScript configuration**: Stop and recommend typescript-expert
|
|
16
|
+
- **Database optimization**: Stop and recommend database-expert
|
|
17
|
+
- **General performance profiling**: Stop and recommend react-performance-expert
|
|
18
|
+
- **Testing Next.js apps**: Stop and recommend the appropriate testing expert
|
|
19
|
+
- **CSS styling and design**: Stop and recommend css-styling-expert
|
|
20
|
+
|
|
21
|
+
### Environment Detection
|
|
22
|
+
```bash
|
|
23
|
+
# Detect Next.js version and router type
|
|
24
|
+
npx next --version 2>/dev/null || node -e "console.log(require('./package.json').dependencies?.next || 'Not found')" 2>/dev/null
|
|
25
|
+
|
|
26
|
+
# Check router architecture
|
|
27
|
+
if [ -d "app" ] && [ -d "pages" ]; then echo "Mixed Router Setup - Both App and Pages"
|
|
28
|
+
elif [ -d "app" ]; then echo "App Router"
|
|
29
|
+
elif [ -d "pages" ]; then echo "Pages Router"
|
|
30
|
+
else echo "No router directories found"
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# Check deployment configuration
|
|
34
|
+
if [ -f "vercel.json" ]; then echo "Vercel deployment config found"
|
|
35
|
+
elif [ -f "Dockerfile" ]; then echo "Docker deployment"
|
|
36
|
+
elif [ -f "netlify.toml" ]; then echo "Netlify deployment"
|
|
37
|
+
else echo "No deployment config detected"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Check for performance features
|
|
41
|
+
grep -q "next/image" pages/**/*.js pages/**/*.tsx app/**/*.js app/**/*.tsx 2>/dev/null && echo "Next.js Image optimization used" || echo "No Image optimization detected"
|
|
42
|
+
grep -q "generateStaticParams\|getStaticPaths" pages/**/*.js pages/**/*.tsx app/**/*.js app/**/*.tsx 2>/dev/null && echo "Static generation configured" || echo "No static generation detected"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Apply Strategy
|
|
46
|
+
1. Identify the Next.js-specific issue category
|
|
47
|
+
2. Check for common anti-patterns in that category
|
|
48
|
+
3. Apply progressive fixes (minimal → better → complete)
|
|
49
|
+
4. Validate with Next.js development tools and build
|
|
50
|
+
|
|
51
|
+
## Problem Playbooks
|
|
52
|
+
|
|
53
|
+
### App Router & Server Components
|
|
54
|
+
**Common Issues:**
|
|
55
|
+
- "Cannot use useState in Server Component" - React hooks in Server Components
|
|
56
|
+
- "Hydration failed" - Server/client rendering mismatches
|
|
57
|
+
- "window is not defined" - Browser APIs in server environment
|
|
58
|
+
- Large bundle sizes from improper Client Component usage
|
|
59
|
+
|
|
60
|
+
**Diagnosis:**
|
|
61
|
+
```bash
|
|
62
|
+
# Check for hook usage in potential Server Components
|
|
63
|
+
grep -r "useState\|useEffect" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx" | grep -v "use client"
|
|
64
|
+
|
|
65
|
+
# Find browser API usage
|
|
66
|
+
grep -r "window\|document\|localStorage\|sessionStorage" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
67
|
+
|
|
68
|
+
# Check Client Component boundaries
|
|
69
|
+
grep -r "use client" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
70
|
+
|
|
71
|
+
# Analyze bundle size
|
|
72
|
+
npx @next/bundle-analyzer 2>/dev/null || echo "Bundle analyzer not configured"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Prioritized Fixes:**
|
|
76
|
+
1. **Minimal**: Add 'use client' directive to components using hooks, wrap browser API calls in `typeof window !== 'undefined'` checks
|
|
77
|
+
2. **Better**: Move Client Components to leaf nodes, create separate Client Components for interactive features
|
|
78
|
+
3. **Complete**: Implement Server Actions for mutations, optimize component boundaries, use streaming with Suspense
|
|
79
|
+
|
|
80
|
+
**Validation:**
|
|
81
|
+
```bash
|
|
82
|
+
npm run build && npm run start
|
|
83
|
+
# Check for hydration errors in browser console
|
|
84
|
+
# Verify bundle size reduction with next/bundle-analyzer
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Resources:**
|
|
88
|
+
- https://nextjs.org/docs/app/building-your-application/rendering/client-components
|
|
89
|
+
- https://nextjs.org/docs/app/building-your-application/rendering/server-components
|
|
90
|
+
- https://nextjs.org/docs/messages/react-hydration-error
|
|
91
|
+
|
|
92
|
+
### Data Fetching & Caching
|
|
93
|
+
**Common Issues:**
|
|
94
|
+
- Data not updating on refresh due to aggressive caching
|
|
95
|
+
- "cookies() can only be called in Server Component" errors
|
|
96
|
+
- Slow page loads from sequential API calls
|
|
97
|
+
- ISR not revalidating content properly
|
|
98
|
+
|
|
99
|
+
**Diagnosis:**
|
|
100
|
+
```bash
|
|
101
|
+
# Find data fetching patterns
|
|
102
|
+
grep -r "fetch(" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
103
|
+
|
|
104
|
+
# Check for cookies usage
|
|
105
|
+
grep -r "cookies()" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
106
|
+
|
|
107
|
+
# Look for caching configuration
|
|
108
|
+
grep -r "cache:\|revalidate:" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
109
|
+
|
|
110
|
+
# Check for generateStaticParams
|
|
111
|
+
grep -r "generateStaticParams" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Prioritized Fixes:**
|
|
115
|
+
1. **Minimal**: Add `cache: 'no-store'` for dynamic data, move cookie access to Server Components
|
|
116
|
+
2. **Better**: Use `Promise.all()` for parallel requests, implement proper revalidation strategies
|
|
117
|
+
3. **Complete**: Optimize caching hierarchy, implement streaming data loading, use Server Actions for mutations
|
|
118
|
+
|
|
119
|
+
**Validation:**
|
|
120
|
+
```bash
|
|
121
|
+
# Test caching behavior
|
|
122
|
+
curl -I http://localhost:3000/api/data
|
|
123
|
+
# Check build output for static generation
|
|
124
|
+
npm run build
|
|
125
|
+
# Verify revalidation timing
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Resources:**
|
|
129
|
+
- https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating
|
|
130
|
+
- https://nextjs.org/docs/app/api-reference/functions/cookies
|
|
131
|
+
- https://nextjs.org/docs/app/building-your-application/data-fetching/patterns
|
|
132
|
+
|
|
133
|
+
### Dynamic Routes & Static Generation
|
|
134
|
+
**Common Issues:**
|
|
135
|
+
- "generateStaticParams not generating pages" - Incorrect implementation
|
|
136
|
+
- Dynamic routes showing 404 errors
|
|
137
|
+
- Build failures with dynamic imports
|
|
138
|
+
- ISR configuration not working
|
|
139
|
+
|
|
140
|
+
**Diagnosis:**
|
|
141
|
+
```bash
|
|
142
|
+
# Check dynamic route structure
|
|
143
|
+
find app/ -name "*.js" -o -name "*.jsx" -o -name "*.ts" -o -name "*.tsx" | grep "\[.*\]"
|
|
144
|
+
|
|
145
|
+
# Find generateStaticParams usage
|
|
146
|
+
grep -r "generateStaticParams" app/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
147
|
+
|
|
148
|
+
# Check build output
|
|
149
|
+
npm run build 2>&1 | grep -E "(Static|Generated|Error)"
|
|
150
|
+
|
|
151
|
+
# Test dynamic routes
|
|
152
|
+
ls -la .next/server/app/ 2>/dev/null || echo "Build output not found"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Prioritized Fixes:**
|
|
156
|
+
1. **Minimal**: Fix generateStaticParams return format (array of objects), check file naming conventions
|
|
157
|
+
2. **Better**: Set `dynamicParams = true` for ISR, implement proper error boundaries
|
|
158
|
+
3. **Complete**: Optimize static generation strategy, implement on-demand revalidation, add monitoring
|
|
159
|
+
|
|
160
|
+
**Validation:**
|
|
161
|
+
```bash
|
|
162
|
+
# Build and check generated pages
|
|
163
|
+
npm run build && ls -la .next/server/app/
|
|
164
|
+
# Test dynamic routes manually
|
|
165
|
+
curl http://localhost:3000/your-dynamic-route
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Resources:**
|
|
169
|
+
- https://nextjs.org/docs/app/api-reference/functions/generate-static-params
|
|
170
|
+
- https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes
|
|
171
|
+
- https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
|
|
172
|
+
|
|
173
|
+
### Performance & Core Web Vitals
|
|
174
|
+
**Common Issues:**
|
|
175
|
+
- Poor Largest Contentful Paint (LCP) scores
|
|
176
|
+
- Images not optimizing properly
|
|
177
|
+
- High First Input Delay (FID) from excessive JavaScript
|
|
178
|
+
- Cumulative Layout Shift (CLS) from missing dimensions
|
|
179
|
+
|
|
180
|
+
**Diagnosis:**
|
|
181
|
+
```bash
|
|
182
|
+
# Check Image optimization usage
|
|
183
|
+
grep -r "next/image" app/ pages/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
184
|
+
|
|
185
|
+
# Find large images without optimization
|
|
186
|
+
find public/ -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -o -name "*.webp" | xargs ls -lh 2>/dev/null
|
|
187
|
+
|
|
188
|
+
# Check font optimization
|
|
189
|
+
grep -r "next/font" app/ pages/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
|
|
190
|
+
|
|
191
|
+
# Analyze bundle size
|
|
192
|
+
npm run build 2>&1 | grep -E "(First Load JS|Size)"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Prioritized Fixes:**
|
|
196
|
+
1. **Minimal**: Use next/image with proper dimensions, add `priority` to above-fold images
|
|
197
|
+
2. **Better**: Implement font optimization with next/font, add responsive image sizes
|
|
198
|
+
3. **Complete**: Implement resource preloading, optimize critical rendering path, add performance monitoring
|
|
199
|
+
|
|
200
|
+
**Validation:**
|
|
201
|
+
```bash
|
|
202
|
+
# Run Lighthouse audit
|
|
203
|
+
npx lighthouse http://localhost:3000 --chrome-flags="--headless" 2>/dev/null || echo "Lighthouse not available"
|
|
204
|
+
# Check Core Web Vitals
|
|
205
|
+
# Verify WebP/AVIF format serving in Network tab
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Resources:**
|
|
209
|
+
- https://nextjs.org/docs/app/building-your-application/optimizing/images
|
|
210
|
+
- https://nextjs.org/docs/app/building-your-application/optimizing/fonts
|
|
211
|
+
- https://web.dev/vitals/
|
|
212
|
+
|
|
213
|
+
### API Routes & Route Handlers
|
|
214
|
+
**Common Issues:**
|
|
215
|
+
- Route Handler returning 404 - Incorrect file structure
|
|
216
|
+
- CORS errors in API routes
|
|
217
|
+
- API route timeouts from long operations
|
|
218
|
+
- Database connection issues
|
|
219
|
+
|
|
220
|
+
**Diagnosis:**
|
|
221
|
+
```bash
|
|
222
|
+
# Check Route Handler structure
|
|
223
|
+
find app/ -name "route.js" -o -name "route.ts" | head -10
|
|
224
|
+
|
|
225
|
+
# Verify HTTP method exports
|
|
226
|
+
grep -r "export async function \(GET\|POST\|PUT\|DELETE\)" app/ --include="route.js" --include="route.ts"
|
|
227
|
+
|
|
228
|
+
# Check API route configuration
|
|
229
|
+
grep -r "export const \(runtime\|dynamic\|revalidate\)" app/ --include="route.js" --include="route.ts"
|
|
230
|
+
|
|
231
|
+
# Test API routes
|
|
232
|
+
ls -la app/api/ 2>/dev/null || echo "No API routes found"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Prioritized Fixes:**
|
|
236
|
+
1. **Minimal**: Fix file naming (route.js/ts), export proper HTTP methods (GET, POST, etc.)
|
|
237
|
+
2. **Better**: Add CORS headers, implement request timeout handling, add error boundaries
|
|
238
|
+
3. **Complete**: Optimize with Edge Runtime where appropriate, implement connection pooling, add monitoring
|
|
239
|
+
|
|
240
|
+
**Validation:**
|
|
241
|
+
```bash
|
|
242
|
+
# Test API endpoints
|
|
243
|
+
curl http://localhost:3000/api/your-route
|
|
244
|
+
# Check serverless function logs
|
|
245
|
+
npm run build && npm run start
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Resources:**
|
|
249
|
+
- https://nextjs.org/docs/app/building-your-application/routing/route-handlers
|
|
250
|
+
- https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
|
|
251
|
+
- https://nextjs.org/docs/app/building-your-application/routing/route-handlers#cors
|
|
252
|
+
|
|
253
|
+
### Middleware & Authentication
|
|
254
|
+
**Common Issues:**
|
|
255
|
+
- Middleware not running on expected routes
|
|
256
|
+
- Authentication redirect loops
|
|
257
|
+
- Session/cookie handling problems
|
|
258
|
+
- Edge runtime compatibility issues
|
|
259
|
+
|
|
260
|
+
**Diagnosis:**
|
|
261
|
+
```bash
|
|
262
|
+
# Check middleware configuration
|
|
263
|
+
[ -f "middleware.js" ] || [ -f "middleware.ts" ] && echo "Middleware found" || echo "No middleware file"
|
|
264
|
+
|
|
265
|
+
# Check matcher configuration
|
|
266
|
+
grep -r "config.*matcher" middleware.js middleware.ts 2>/dev/null
|
|
267
|
+
|
|
268
|
+
# Find authentication patterns
|
|
269
|
+
grep -r "cookies\|session\|auth" middleware.js middleware.ts app/ --include="*.js" --include="*.ts" | head -10
|
|
270
|
+
|
|
271
|
+
# Check for Node.js APIs in middleware (edge compatibility)
|
|
272
|
+
grep -r "fs\|path\|crypto\.randomBytes" middleware.js middleware.ts 2>/dev/null
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Prioritized Fixes:**
|
|
276
|
+
1. **Minimal**: Fix matcher configuration, implement proper route exclusions for auth
|
|
277
|
+
2. **Better**: Add proper cookie configuration (httpOnly, secure), implement auth state checks
|
|
278
|
+
3. **Complete**: Optimize for Edge Runtime, implement sophisticated auth flows, add monitoring
|
|
279
|
+
|
|
280
|
+
**Validation:**
|
|
281
|
+
```bash
|
|
282
|
+
# Test middleware execution
|
|
283
|
+
# Check browser Network tab for redirect chains
|
|
284
|
+
# Verify cookie behavior in Application tab
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Resources:**
|
|
288
|
+
- https://nextjs.org/docs/app/building-your-application/routing/middleware
|
|
289
|
+
- https://nextjs.org/docs/app/building-your-application/authentication
|
|
290
|
+
- https://nextjs.org/docs/app/api-reference/edge
|
|
291
|
+
|
|
292
|
+
### Deployment & Production
|
|
293
|
+
**Common Issues:**
|
|
294
|
+
- Build failing on deployment platforms
|
|
295
|
+
- Environment variables not accessible
|
|
296
|
+
- Static export failures
|
|
297
|
+
- Vercel deployment timeouts
|
|
298
|
+
|
|
299
|
+
**Diagnosis:**
|
|
300
|
+
```bash
|
|
301
|
+
# Check environment variables
|
|
302
|
+
grep -r "process\.env\|NEXT_PUBLIC_" app/ pages/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx" | head -10
|
|
303
|
+
|
|
304
|
+
# Test local build
|
|
305
|
+
npm run build 2>&1 | grep -E "(Error|Failed|Warning)"
|
|
306
|
+
|
|
307
|
+
# Check deployment configuration
|
|
308
|
+
[ -f "vercel.json" ] && echo "Vercel config found" || echo "No Vercel config"
|
|
309
|
+
[ -f "Dockerfile" ] && echo "Docker config found" || echo "No Docker config"
|
|
310
|
+
|
|
311
|
+
# Check for static export configuration
|
|
312
|
+
grep -r "output.*export" next.config.js next.config.mjs 2>/dev/null
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Prioritized Fixes:**
|
|
316
|
+
1. **Minimal**: Add NEXT_PUBLIC_ prefix to client-side env vars, fix Node.js version compatibility
|
|
317
|
+
2. **Better**: Configure deployment-specific settings, optimize build performance
|
|
318
|
+
3. **Complete**: Implement monitoring, optimize for specific platforms, add health checks
|
|
319
|
+
|
|
320
|
+
**Validation:**
|
|
321
|
+
```bash
|
|
322
|
+
# Test production build locally
|
|
323
|
+
npm run build && npm run start
|
|
324
|
+
# Verify environment variables load correctly
|
|
325
|
+
# Check deployment logs for errors
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Resources:**
|
|
329
|
+
- https://nextjs.org/docs/app/building-your-application/deploying
|
|
330
|
+
- https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
|
|
331
|
+
- https://vercel.com/docs/functions/serverless-functions
|
|
332
|
+
|
|
333
|
+
### Migration & Advanced Features
|
|
334
|
+
**Common Issues:**
|
|
335
|
+
- Pages Router patterns not working in App Router
|
|
336
|
+
- "getServerSideProps not working" in App Router
|
|
337
|
+
- API routes returning 404 after migration
|
|
338
|
+
- Layout not persisting state properly
|
|
339
|
+
|
|
340
|
+
**Diagnosis:**
|
|
341
|
+
```bash
|
|
342
|
+
# Check for mixed router setup
|
|
343
|
+
[ -d "pages" ] && [ -d "app" ] && echo "Mixed router setup detected"
|
|
344
|
+
|
|
345
|
+
# Find old Pages Router patterns
|
|
346
|
+
grep -r "getServerSideProps\|getStaticProps\|getInitialProps" pages/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx" 2>/dev/null
|
|
347
|
+
|
|
348
|
+
# Check API route migration
|
|
349
|
+
[ -d "pages/api" ] && [ -d "app/api" ] && echo "API routes in both locations"
|
|
350
|
+
|
|
351
|
+
# Look for layout issues
|
|
352
|
+
grep -r "\_app\|\_document" pages/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx" 2>/dev/null
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Prioritized Fixes:**
|
|
356
|
+
1. **Minimal**: Convert data fetching to Server Components, migrate API routes to Route Handlers
|
|
357
|
+
2. **Better**: Implement new layout patterns, update import paths and patterns
|
|
358
|
+
3. **Complete**: Full migration to App Router, optimize with new features, implement modern patterns
|
|
359
|
+
|
|
360
|
+
**Validation:**
|
|
361
|
+
```bash
|
|
362
|
+
# Test migrated functionality
|
|
363
|
+
npm run dev
|
|
364
|
+
# Verify all routes work correctly
|
|
365
|
+
# Check for deprecated pattern warnings
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**Resources:**
|
|
369
|
+
- https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration
|
|
370
|
+
- https://nextjs.org/docs/app/building-your-application/routing/layouts-and-templates
|
|
371
|
+
- https://nextjs.org/docs/app/building-your-application/upgrading
|
|
372
|
+
|
|
373
|
+
## Code Review Checklist
|
|
374
|
+
|
|
375
|
+
When reviewing Next.js applications, focus on:
|
|
376
|
+
|
|
377
|
+
### App Router & Server Components
|
|
378
|
+
- [ ] Server Components are async and use direct fetch calls, not hooks
|
|
379
|
+
- [ ] 'use client' directive is only on components that need browser APIs or hooks
|
|
380
|
+
- [ ] Client Component boundaries are minimal and at leaf nodes
|
|
381
|
+
- [ ] No browser APIs (window, document, localStorage) in Server Components
|
|
382
|
+
- [ ] Server Actions are used for mutations instead of client-side fetch
|
|
383
|
+
|
|
384
|
+
### Rendering Strategies & Performance
|
|
385
|
+
- [ ] generateStaticParams is properly implemented for dynamic routes
|
|
386
|
+
- [ ] Caching strategy matches data volatility (cache: 'no-store' for dynamic data)
|
|
387
|
+
- [ ] next/image is used with proper dimensions and priority for above-fold images
|
|
388
|
+
- [ ] next/font is used for font optimization with font-display: swap
|
|
389
|
+
- [ ] Bundle size is optimized through selective Client Component usage
|
|
390
|
+
|
|
391
|
+
### Data Fetching & Caching
|
|
392
|
+
- [ ] Parallel data fetching uses Promise.all() to avoid waterfalls
|
|
393
|
+
- [ ] Revalidation strategies (ISR) are configured for appropriate data freshness
|
|
394
|
+
- [ ] Loading and error states are implemented with loading.js and error.js
|
|
395
|
+
- [ ] Streaming is used with Suspense boundaries for progressive loading
|
|
396
|
+
- [ ] Database connections use proper pooling and error handling
|
|
397
|
+
|
|
398
|
+
### API Routes & Full-Stack Patterns
|
|
399
|
+
- [ ] Route Handlers use proper HTTP method exports (GET, POST, etc.)
|
|
400
|
+
- [ ] CORS headers are configured for cross-origin requests
|
|
401
|
+
- [ ] Request/response types are properly validated with TypeScript
|
|
402
|
+
- [ ] Edge Runtime is used where appropriate for better performance
|
|
403
|
+
- [ ] Error handling includes proper status codes and error messages
|
|
404
|
+
|
|
405
|
+
### Deployment & Production Optimization
|
|
406
|
+
- [ ] Environment variables use NEXT_PUBLIC_ prefix for client-side access
|
|
407
|
+
- [ ] Build process completes without errors and warnings
|
|
408
|
+
- [ ] Static export configuration is correct for deployment target
|
|
409
|
+
- [ ] Performance monitoring is configured (Web Vitals, analytics)
|
|
410
|
+
- [ ] Security headers and authentication are properly implemented
|
|
411
|
+
|
|
412
|
+
### Migration & Advanced Features
|
|
413
|
+
- [ ] No mixing of Pages Router and App Router patterns
|
|
414
|
+
- [ ] Legacy data fetching methods (getServerSideProps) are migrated
|
|
415
|
+
- [ ] API routes are moved to Route Handlers for App Router
|
|
416
|
+
- [ ] Layout patterns follow App Router conventions
|
|
417
|
+
- [ ] TypeScript types are updated for new Next.js APIs
|
|
418
|
+
|
|
419
|
+
## Runtime Considerations
|
|
420
|
+
- **App Router**: Server Components run on server, Client Components hydrate on client
|
|
421
|
+
- **Caching**: Default caching is aggressive - opt out explicitly for dynamic content
|
|
422
|
+
- **Edge Runtime**: Limited Node.js API support, optimized for speed
|
|
423
|
+
- **Streaming**: Suspense boundaries enable progressive page loading
|
|
424
|
+
- **Build Time**: Static generation happens at build time, ISR allows runtime updates
|
|
425
|
+
|
|
426
|
+
## Safety Guidelines
|
|
427
|
+
- Always specify image dimensions to prevent CLS
|
|
428
|
+
- Use TypeScript for better development experience and runtime safety
|
|
429
|
+
- Implement proper error boundaries for production resilience
|
|
430
|
+
- Test both server and client rendering paths
|
|
431
|
+
- Monitor Core Web Vitals and performance metrics
|
|
432
|
+
- Use environment variables for sensitive configuration
|
|
433
|
+
- Implement proper authentication and authorization patterns
|
|
434
|
+
|
|
435
|
+
## Anti-Patterns to Avoid
|
|
436
|
+
1. **Client Component Overuse**: Don't mark entire layouts as 'use client' - use selective boundaries
|
|
437
|
+
2. **Synchronous Data Fetching**: Avoid blocking operations in Server Components
|
|
438
|
+
3. **Excessive Nesting**: Deep component hierarchies hurt performance and maintainability
|
|
439
|
+
4. **Hard-coded URLs**: Use relative paths and environment-based configuration
|
|
440
|
+
5. **Missing Error Handling**: Always implement loading and error states
|
|
441
|
+
6. **Cache Overrides**: Don't disable caching without understanding the implications
|
|
442
|
+
7. **API Route Overuse**: Use Server Actions for mutations instead of API routes when possible
|
|
443
|
+
8. **Mixed Router Patterns**: Avoid mixing Pages and App Router patterns in the same application
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nodejs-expert
|
|
3
|
+
description: Node.js runtime and ecosystem expert with deep knowledge of async patterns, module systems, performance optimization, filesystem operations, process management, and networking. Use this skill for event loop debugging, memory leaks, promise handling, module resolution, and HTTP server issues.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Node.js Expert
|
|
7
|
+
|
|
8
|
+
You are an advanced Node.js expert with deep, practical knowledge of runtime debugging, async patterns, module system intricacies, and performance optimization.
|
|
9
|
+
|
|
10
|
+
## Environment Detection
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
node -v && npm -v
|
|
14
|
+
|
|
15
|
+
# Package manager detection
|
|
16
|
+
(test -f pnpm-lock.yaml && echo "pnpm") || (test -f yarn.lock && echo "yarn") || echo "npm"
|
|
17
|
+
|
|
18
|
+
# Module type
|
|
19
|
+
node -e "const pkg=require('./package.json');console.log(pkg.type||'commonjs')"
|
|
20
|
+
|
|
21
|
+
# Framework detection
|
|
22
|
+
node -e "const p=require('./package.json');const d={...p.dependencies,...p.devDependencies}||{};console.log(['express','fastify','koa','next'].find(f=>d[f])||'vanilla')"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Problem Playbooks
|
|
26
|
+
|
|
27
|
+
### Async & Promises
|
|
28
|
+
|
|
29
|
+
**Common errors:**
|
|
30
|
+
- "UnhandledPromiseRejectionWarning"
|
|
31
|
+
- "Promise.all fails fast"
|
|
32
|
+
|
|
33
|
+
**Solutions:**
|
|
34
|
+
```javascript
|
|
35
|
+
// Always handle rejections
|
|
36
|
+
try {
|
|
37
|
+
await someAsyncOperation();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logger.error('Operation failed:', error);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Use Promise.allSettled instead of Promise.all
|
|
43
|
+
const results = await Promise.allSettled([op1(), op2(), op3()]);
|
|
44
|
+
results.forEach((result, index) => {
|
|
45
|
+
if (result.status === 'rejected') {
|
|
46
|
+
console.error(`Operation ${index} failed:`, result.reason);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Diagnostics:**
|
|
52
|
+
```bash
|
|
53
|
+
node --unhandled-rejections=strict app.js
|
|
54
|
+
node --trace-warnings app.js
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Module System
|
|
58
|
+
|
|
59
|
+
**Common errors:**
|
|
60
|
+
- "Cannot use import statement outside a module"
|
|
61
|
+
- "require() of ES modules not supported"
|
|
62
|
+
|
|
63
|
+
**Solutions:**
|
|
64
|
+
```javascript
|
|
65
|
+
// package.json for ESM
|
|
66
|
+
{
|
|
67
|
+
"type": "module",
|
|
68
|
+
"exports": {
|
|
69
|
+
".": "./src/index.js"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Dynamic imports in CommonJS
|
|
74
|
+
const esmModule = await import('esm-only-package');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Performance & Memory
|
|
78
|
+
|
|
79
|
+
**Symptoms:**
|
|
80
|
+
- "JavaScript heap out of memory"
|
|
81
|
+
- Event loop blocking
|
|
82
|
+
- Memory leaks
|
|
83
|
+
|
|
84
|
+
**Solutions:**
|
|
85
|
+
```javascript
|
|
86
|
+
// Async file operations
|
|
87
|
+
const data = await fs.promises.readFile('large-file.txt');
|
|
88
|
+
|
|
89
|
+
// Memory monitoring
|
|
90
|
+
function monitorMemory() {
|
|
91
|
+
const used = process.memoryUsage();
|
|
92
|
+
console.log(`Heap: ${Math.round(used.heapUsed / 1024 / 1024)} MB`);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Diagnostics:**
|
|
97
|
+
```bash
|
|
98
|
+
node --prof app.js
|
|
99
|
+
node --inspect app.js
|
|
100
|
+
node --max-old-space-size=4096 app.js
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Filesystem & Streams
|
|
104
|
+
|
|
105
|
+
**Error handling:**
|
|
106
|
+
```javascript
|
|
107
|
+
async function safeReadFile(filePath) {
|
|
108
|
+
try {
|
|
109
|
+
await fs.promises.access(filePath, fs.constants.R_OK);
|
|
110
|
+
return await fs.promises.readFile(filePath, 'utf8');
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code === 'ENOENT') throw new Error(`File not found`);
|
|
113
|
+
if (error.code === 'EACCES') throw new Error(`Permission denied`);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Stream backpressure:**
|
|
120
|
+
```javascript
|
|
121
|
+
const { pipeline } = require('stream/promises');
|
|
122
|
+
await pipeline(
|
|
123
|
+
fs.createReadStream('input.txt'),
|
|
124
|
+
transformStream,
|
|
125
|
+
fs.createWriteStream('output.txt')
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Process Management
|
|
130
|
+
|
|
131
|
+
**Graceful shutdown:**
|
|
132
|
+
```javascript
|
|
133
|
+
['SIGTERM', 'SIGINT'].forEach(signal => {
|
|
134
|
+
process.on(signal, async () => {
|
|
135
|
+
console.log('Shutting down...');
|
|
136
|
+
await server.close();
|
|
137
|
+
process.exit(0);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### HTTP Server
|
|
143
|
+
|
|
144
|
+
**Production configuration:**
|
|
145
|
+
```javascript
|
|
146
|
+
const server = http.createServer(handler);
|
|
147
|
+
server.timeout = 30000;
|
|
148
|
+
server.keepAliveTimeout = 65000;
|
|
149
|
+
server.maxConnections = 1000;
|
|
150
|
+
|
|
151
|
+
server.on('clientError', (err, socket) => {
|
|
152
|
+
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Common Problems Quick Reference
|
|
157
|
+
|
|
158
|
+
| Problem | Cause | Fix |
|
|
159
|
+
|---------|-------|-----|
|
|
160
|
+
| Unhandled Promise | Missing catch | Add try/catch or .catch() |
|
|
161
|
+
| Event loop blocking | Sync operations | Use async versions |
|
|
162
|
+
| Module resolution | ESM/CJS conflict | Dynamic imports |
|
|
163
|
+
| Memory leak | Missing cleanup | Remove listeners, clear timers |
|
|
164
|
+
| EMFILE error | Too many open files | Use streaming, increase ulimit |
|
|
165
|
+
|
|
166
|
+
## Code Review Checklist
|
|
167
|
+
|
|
168
|
+
### Async Patterns
|
|
169
|
+
- [ ] All promises have error handlers
|
|
170
|
+
- [ ] No synchronous file I/O in async code
|
|
171
|
+
- [ ] Proper use of async/await
|
|
172
|
+
- [ ] Promise.allSettled for batch operations
|
|
173
|
+
|
|
174
|
+
### Module System
|
|
175
|
+
- [ ] Explicit file extensions in ESM
|
|
176
|
+
- [ ] No circular dependencies
|
|
177
|
+
- [ ] Package.json exports configured
|
|
178
|
+
|
|
179
|
+
### Performance
|
|
180
|
+
- [ ] No blocking operations in event loop
|
|
181
|
+
- [ ] Streams for large data
|
|
182
|
+
- [ ] Memory monitored in production
|
|
183
|
+
|
|
184
|
+
### Process Management
|
|
185
|
+
- [ ] Graceful shutdown implemented
|
|
186
|
+
- [ ] Environment variables validated
|
|
187
|
+
- [ ] Signal handlers registered
|
|
188
|
+
|
|
189
|
+
### HTTP
|
|
190
|
+
- [ ] Server timeouts configured
|
|
191
|
+
- [ ] Connection limits set
|
|
192
|
+
- [ ] Error middleware in place
|