Next.js Senior Developer
Transform into Senior Next.js 15+/16 Engineer for production-ready App Router applications.
When to Use
- Scaffolding new Next.js App Router projects
- RSC vs Client Component decisions
- Server Actions and data fetching patterns
- Performance optimization (CWV, bundle, caching)
- Middleware and authentication setup
- Next.js 15/16 migration or audit
Version Notes
| Version |
Key Changes |
| Next.js 16 |
middleware.ts → proxy.ts, Node.js runtime only, Cache Components |
| Next.js 15 |
fetch uncached by default, React 19, Turbopack stable |
Triggers
| Command |
Purpose |
/next-init |
Scaffold new App Router project |
/next-route |
Generate route folder (page, layout, loading, error) |
/next-audit |
Audit codebase for patterns, security, performance |
/next-opt |
Optimize bundle, images, fonts, caching |
Reference Files (20 Total)
Load based on task context:
Core References
| Category |
Reference |
When |
| Routing |
references/app_router.md |
Route groups, parallel, intercepting |
| Components |
references/components.md |
RSC vs Client decision, patterns |
| Data |
references/data_fetching.md |
fetch, cache, revalidation, streaming |
| Security |
references/security.md |
Server Actions, auth, OWASP |
| Performance |
references/performance.md |
CWV, images, fonts, bundle, memory |
| Middleware |
references/middleware.md |
Auth, redirects, Edge vs Node |
Architecture & Quality
| Category |
Reference |
When |
| Architecture |
references/architecture.md |
File structure, feature-sliced design |
| Shared Components |
references/shared_components.md |
DRY patterns, composition, reusability |
| Code Quality |
references/code_quality.md |
Error handling, testing, accessibility |
Features & Integrations
| Category |
Reference |
When |
| SEO & Metadata |
references/seo_metadata.md |
generateMetadata, sitemap, OpenGraph |
| Database |
references/database.md |
Prisma, Drizzle, queries, migrations |
| Authentication |
references/authentication.md |
Auth.js, sessions, RBAC |
| Forms |
references/forms.md |
React Hook Form, Zod, file uploads |
| i18n |
references/i18n.md |
next-intl, routing, RTL support |
| Real-Time |
references/realtime.md |
SSE, WebSockets, polling, Pusher |
| API Design |
references/api_design.md |
REST, tRPC, webhooks, versioning |
DevOps & Migration
| Category |
Reference |
When |
| Deployment |
references/deployment.md |
Vercel, Docker, CI/CD, env management |
| Monorepo |
references/monorepo.md |
Turborepo, shared packages, workspaces |
| Migration |
references/migration.md |
Pages→App Router, version upgrades |
| Debugging |
references/debugging.md |
DevTools, profiling, error tracking |
Core Tenets
1. Server-First
Default to Server Components. Use Client only when required.
RSC when: data fetching, secrets, heavy deps, no interactivity
Client when: useState, useEffect, onClick, browser APIs
2. Component Archetypes
| Pattern |
Runtime |
Must Have |
page.tsx |
Server |
async, data fetching |
*.action.ts |
Server |
"use server", Zod, 7-step security |
*.interactive.tsx |
Client |
"use client", event handlers |
*.ui.tsx |
Either |
Pure presentation, stateless |
3. 7-Step Server Action Security
"use server"
// 1. Rate limit (IP/user)
// 2. Auth verification
// 3. Zod validation (sanitize errors!)
// 4. Authorization check (IDOR prevention)
// 5. Mutation
// 6. Granular revalidateTag() (NOT revalidatePath)
// 7. Audit log (async)
4. Data Fetching Strategy
Static → generateStaticParams + fetch
ISR → fetch(url, { next: { revalidate: 60 }})
Dynamic → fetch(url, { cache: 'no-store' })
Real-time → Client fetch (SWR)
Next.js 15 Change: fetch is UNCACHED by default (opposite of 14).
5. Caching
| Type |
Scope |
Invalidation |
| Request Memoization |
Request |
Automatic |
| Data Cache |
Server |
revalidateTag() |
| Full Route Cache |
Server |
Rebuild |
| Router Cache |
Client |
router.refresh() |
Prefer revalidateTag() over revalidatePath() to avoid cache storms.
6. Feature-Sliced Architecture
For large apps (50+ routes), use domain-driven structure:
src/
├── app/ # Routing only
├── components/ # Shared UI (ui/, shared/)
├── features/ # Business logic per domain
│ └── [feature]/
│ ├── components/
│ ├── actions/
│ ├── queries/
│ └── hooks/
├── lib/ # Global utilities
└── types/ # Global types
7. Component Sharing Rules
| Used 3+ places? |
Contains business logic? |
Action |
| Yes |
No |
Move to components/ui/ or shared/ |
| Yes |
Yes |
Keep in features/ |
| No |
Any |
Keep local (_components/) |
8. State Management Hierarchy
| State Type |
Tool |
Example |
| URL State |
searchParams |
Filters, pagination |
| Server State |
Server Components |
User data, posts |
| Form State |
useFormState |
Form submissions |
| UI State |
useState |
Modals, dropdowns |
| Shared Client |
Context/Zustand |
Theme, cart |
Rule: Prefer URL state for shareable/bookmarkable state.
9. DRY with createSafeAction
// lib/safe-action.ts - Reuse for all Server Actions
export const createPost = createSafeAction(schema, handler, {
revalidateTags: ["posts"]
})
Eliminates duplicate auth/validation/error handling.
Anti-Patterns
| Don't |
Do |
| "use client" at tree root |
Push boundary down to leaves |
| API routes for server data |
Direct DB in Server Components |
| useEffect for fetching |
Server Component async fetch |
| revalidatePath('/') |
Granular revalidateTag() |
| Trust middleware alone |
Validate at data layer too |
| Prop drill 5+ levels |
Context or composition |
any types |
Proper types or unknown |
| Barrel exports in features |
Direct imports |
| localStorage for auth |
httpOnly cookies |
| Global caches (memory leak) |
LRU cache or React cache() |
Middleware: Deny by Default
// middleware.ts - Public routes MUST be allowlisted
const publicRoutes = ['/login', '/register', '/api/health']
if (!publicRoutes.some(r => pathname.startsWith(r))) {
// Require auth
}
CRITICAL: Upgrade to Next.js 15.2.3+ (CVE-2025-29927 fix).
Scripts
| Script |
Purpose |
scripts/scaffold_route.py |
Generate route folder w/ all files |
Templates
| File |
Purpose |
templates/page.tsx |
Standard async page |
templates/layout.tsx |
Layout w/ metadata |
templates/action.ts |
7-step secure Server Action |
templates/loading.tsx |
Loading UI skeleton |
templates/error.tsx |
Error boundary |
Assets
| File |
Purpose |
assets/next.config.ts |
Production config w/ security headers |
assets/middleware.ts |
Deny-by-default auth (Next.js 15) |
assets/proxy.ts |
Deny-by-default auth (Next.js 16+) |
Quick Reference: Senior Code Review
Before merging any PR, verify:
Performance
Security
Architecture
Quality
1---2name: nextjs-senior-dev3description: Senior Next.js 15+/16 Engineer skill for App Router. Use when scaffolding production apps, enforcing RSC patterns, auditing codebases, or optimizing performance.4---56# Next.js Senior Developer78Transform into Senior Next.js 15+/16 Engineer for production-ready App Router applications.910## When to Use1112- Scaffolding new Next.js App Router projects13- RSC vs Client Component decisions14- Server Actions and data fetching patterns15- Performance optimization (CWV, bundle, caching)16- Middleware and authentication setup17- Next.js 15/16 migration or audit1819## Version Notes2021| Version | Key Changes |22|---------|-------------|23| Next.js 16 | `middleware.ts` → `proxy.ts`, Node.js runtime only, Cache Components |24| Next.js 15 | fetch uncached by default, React 19, Turbopack stable |2526## Triggers2728| Command | Purpose |29|---------|---------|30| `/next-init` | Scaffold new App Router project |31| `/next-route` | Generate route folder (page, layout, loading, error) |32| `/next-audit` | Audit codebase for patterns, security, performance |33| `/next-opt` | Optimize bundle, images, fonts, caching |3435## Reference Files (20 Total)3637Load based on task context:3839### Core References4041| Category | Reference | When |42|----------|-----------|------|43| Routing | `references/app_router.md` | Route groups, parallel, intercepting |44| Components | `references/components.md` | RSC vs Client decision, patterns |45| Data | `references/data_fetching.md` | fetch, cache, revalidation, streaming |46| Security | `references/security.md` | Server Actions, auth, OWASP |47| Performance | `references/performance.md` | CWV, images, fonts, bundle, memory |48| Middleware | `references/middleware.md` | Auth, redirects, Edge vs Node |4950### Architecture & Quality5152| Category | Reference | When |53|----------|-----------|------|54| Architecture | `references/architecture.md` | File structure, feature-sliced design |55| Shared Components | `references/shared_components.md` | DRY patterns, composition, reusability |56| Code Quality | `references/code_quality.md` | Error handling, testing, accessibility |5758### Features & Integrations5960| Category | Reference | When |61|----------|-----------|------|62| SEO & Metadata | `references/seo_metadata.md` | generateMetadata, sitemap, OpenGraph |63| Database | `references/database.md` | Prisma, Drizzle, queries, migrations |64| Authentication | `references/authentication.md` | Auth.js, sessions, RBAC |65| Forms | `references/forms.md` | React Hook Form, Zod, file uploads |66| i18n | `references/i18n.md` | next-intl, routing, RTL support |67| Real-Time | `references/realtime.md` | SSE, WebSockets, polling, Pusher |68| API Design | `references/api_design.md` | REST, tRPC, webhooks, versioning |6970### DevOps & Migration7172| Category | Reference | When |73|----------|-----------|------|74| Deployment | `references/deployment.md` | Vercel, Docker, CI/CD, env management |75| Monorepo | `references/monorepo.md` | Turborepo, shared packages, workspaces |76| Migration | `references/migration.md` | Pages→App Router, version upgrades |77| Debugging | `references/debugging.md` | DevTools, profiling, error tracking |7879## Core Tenets8081### 1. Server-First8283Default to Server Components. Use Client only when required.8485```86RSC when: data fetching, secrets, heavy deps, no interactivity87Client when: useState, useEffect, onClick, browser APIs88```8990### 2. Component Archetypes9192| Pattern | Runtime | Must Have |93|---------|---------|-----------|94| `page.tsx` | Server | async, data fetching |95| `*.action.ts` | Server | "use server", Zod, 7-step security |96| `*.interactive.tsx` | Client | "use client", event handlers |97| `*.ui.tsx` | Either | Pure presentation, stateless |9899### 3. 7-Step Server Action Security100101```typescript102"use server"103// 1. Rate limit (IP/user)104// 2. Auth verification105// 3. Zod validation (sanitize errors!)106// 4. Authorization check (IDOR prevention)107// 5. Mutation108// 6. Granular revalidateTag() (NOT revalidatePath)109// 7. Audit log (async)110```111112### 4. Data Fetching Strategy113114```115Static → generateStaticParams + fetch116ISR → fetch(url, { next: { revalidate: 60 }})117Dynamic → fetch(url, { cache: 'no-store' })118Real-time → Client fetch (SWR)119```120121**Next.js 15 Change**: fetch is UNCACHED by default (opposite of 14).122123### 5. Caching124125| Type | Scope | Invalidation |126|------|-------|--------------|127| Request Memoization | Request | Automatic |128| Data Cache | Server | revalidateTag() |129| Full Route Cache | Server | Rebuild |130| Router Cache | Client | router.refresh() |131132Prefer `revalidateTag()` over `revalidatePath()` to avoid cache storms.133134### 6. Feature-Sliced Architecture135136For large apps (50+ routes), use domain-driven structure:137138```139src/140├── app/ # Routing only141├── components/ # Shared UI (ui/, shared/)142├── features/ # Business logic per domain143│ └── [feature]/144│ ├── components/145│ ├── actions/146│ ├── queries/147│ └── hooks/148├── lib/ # Global utilities149└── types/ # Global types150```151152### 7. Component Sharing Rules153154| Used 3+ places? | Contains business logic? | Action |155|-----------------|-------------------------|--------|156| Yes | No | Move to `components/ui/` or `shared/` |157| Yes | Yes | Keep in `features/` |158| No | Any | Keep local (`_components/`) |159160### 8. State Management Hierarchy161162| State Type | Tool | Example |163|------------|------|---------|164| URL State | searchParams | Filters, pagination |165| Server State | Server Components | User data, posts |166| Form State | useFormState | Form submissions |167| UI State | useState | Modals, dropdowns |168| Shared Client | Context/Zustand | Theme, cart |169170**Rule**: Prefer URL state for shareable/bookmarkable state.171172### 9. DRY with createSafeAction173174```typescript175// lib/safe-action.ts - Reuse for all Server Actions176export const createPost = createSafeAction(schema, handler, {177 revalidateTags: ["posts"]178})179```180181Eliminates duplicate auth/validation/error handling.182183## Anti-Patterns184185| Don't | Do |186|-------|-----|187| "use client" at tree root | Push boundary down to leaves |188| API routes for server data | Direct DB in Server Components |189| useEffect for fetching | Server Component async fetch |190| revalidatePath('/') | Granular revalidateTag() |191| Trust middleware alone | Validate at data layer too |192| Prop drill 5+ levels | Context or composition |193| `any` types | Proper types or `unknown` |194| Barrel exports in features | Direct imports |195| localStorage for auth | httpOnly cookies |196| Global caches (memory leak) | LRU cache or React cache() |197198## Middleware: Deny by Default199200```typescript201// middleware.ts - Public routes MUST be allowlisted202const publicRoutes = ['/login', '/register', '/api/health']203if (!publicRoutes.some(r => pathname.startsWith(r))) {204 // Require auth205}206```207208**CRITICAL**: Upgrade to Next.js 15.2.3+ (CVE-2025-29927 fix).209210## Scripts211212| Script | Purpose |213|--------|---------|214| `scripts/scaffold_route.py` | Generate route folder w/ all files |215216## Templates217218| File | Purpose |219|------|---------|220| `templates/page.tsx` | Standard async page |221| `templates/layout.tsx` | Layout w/ metadata |222| `templates/action.ts` | 7-step secure Server Action |223| `templates/loading.tsx` | Loading UI skeleton |224| `templates/error.tsx` | Error boundary |225226## Assets227228| File | Purpose |229|------|---------|230| `assets/next.config.ts` | Production config w/ security headers |231| `assets/middleware.ts` | Deny-by-default auth (Next.js 15) |232| `assets/proxy.ts` | Deny-by-default auth (Next.js 16+) |233234## Quick Reference: Senior Code Review235236Before merging any PR, verify:237238**Performance**239- [ ] No unnecessary "use client"240- [ ] Images use next/image with dimensions241- [ ] Heavy components dynamic imported242- [ ] Parallel fetching (Promise.all)243244**Security**245- [ ] Server Actions validate with Zod246- [ ] Auth in actions (not just middleware)247- [ ] IDOR prevention (user owns resource)248- [ ] No secrets in client bundles249250**Architecture**251- [ ] Components in correct layer252- [ ] No cross-feature imports253- [ ] DRY patterns used (createSafeAction)254- [ ] URL state for shareable state255256**Quality**257- [ ] No `any` types258- [ ] Error boundaries present259- [ ] Loading states for async260- [ ] Accessibility (semantic HTML, alt text)