agentleFS
LeahyCCLeahyCC/claude-skills/skills/nextjs-app-router/SKILL.md

nextjs-app-router

Skill3 starsChanged 8 months agoMITView on GitHub

Use when building or reviewing Next.js App Router applications. Covers Server vs Client Components, data fetching, Server Functions, Route Handlers, Cache Components, revalidation, routing, metadata, proxy.ts, error handling, streaming, and migration from the Pages Router. Verified against the official Next.js 16 App Router documentation.

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Next.js App Router

Production guidance for Next.js 16 App Router applications. Server-first: keep rendering, data access, and secrets on the server; add 'use client' only for interactivity.

Architecture Overview

Request → proxy.ts → Route (layout/page) → Server Components → DB/API
                              │                    │
                              │                    ▼
                              │              RSC Payload + HTML
                              │                    │
                              ▼                    ▼
                        Route Handlers      Streaming + Suspense
                                                   │
                                                   ▼
                                          Client Components (hydrate)

Quick Reference

Need help with...Resource
Server vs Client Componentsserver-components.md
Data fetching, Suspense, use()data-fetching.md
Cache Components, revalidationcaching.md
Layouts, navigation, dynamic routesrouting.md
proxy.ts, auth gatesproxy.md
error.tsx, loading.tsx, notFound()error-handling.md
Metadata, App Router ownershipmetadata-and-seo.md
next/image, next/fontassets.md
Pages Router migrationmigration.md
Next.js 15 → 16 upgradeversion-changes.md

Decision Matrix: "What Do I Use?"

NeedSolutionResource
Read database / APIServer Componentserver-components, data-fetching
User interaction / stateClient Componentserver-components
Form mutationServer Actiondata-fetching
HTTP endpoint / webhookRoute Handlerdata-fetching
Cache expensive data'use cache' + cacheLifecaching
Invalidate after user editupdateTag()caching
Invalidate from webhookrevalidateTag(tag, 'max')caching
Auth redirect before renderproxy.tsproxy
Loading UIloading.tsx or <Suspense>error-handling, data-fetching
Uncaught errorerror.tsxerror-handling
Missing resourcenotFound()error-handling
SEO metadatametadata / generateMetadatametadata-and-seo
Optimize images/fontsnext/image, next/fontassets

Component Decision Tree

Need useState, useEffect, onClick, or browser APIs?
├── YES → Client Component ('use client' at leaf)
└── NO  → Server Component (default — no directive)

Need to mutate data?
├── HTML form / button → Server Action
└── External HTTP API  → Route Handler

Data & Caching

ScenarioPattern
Independent fetchesPromise.all() in Server Component
Slow section<Suspense> + streaming
User-specific data'use cache: private' (or Suspense — no shared 'use cache')
Shared catalog'use cache' + cacheTag
After mutationupdateTag() (actions) or revalidateTag (webhooks)

Routing Conventions

FilePurpose
page.tsxRoute UI
layout.tsxShared chrome (persists on navigation)
loading.tsxSuspense fallback
error.tsxError boundary (Client Component)
not-found.tsx404 UI
route.tsHTTP handler
proxy.tsPre-render interception (root or src/)

Code Review Checklist

Components & Data

  • Server Components by default; 'use client' only at leaves
  • Data fetched in Server Components, not via client useEffect
  • Parallel fetching with Promise.all() where independent
  • params / searchParams / cookies() / headers() awaited
  • No secrets or DB clients in Client Components

Mutations & Cache

  • Server Actions authenticate and authorize
  • updateTag or revalidateTag after mutations
  • No cookies() inside shared 'use cache' scopes (use 'use cache: private' for per-user)

Routing & UX

  • Nested layouts; no duplicated page wrappers
  • loading.tsx / error.tsx on slow or critical routes
  • notFound() for missing resources

Security

  • proxy.ts gates auth; Server Actions re-verify
  • Input validated in Server Actions and Route Handlers

Performance & SEO

  • next/image and next/font used
  • Metadata on every public page
  • Suspense for slow streaming sections

Anti-Patterns

  • 'use client' on entire pages or layouts
  • Client Component fetching data the server could fetch
  • Route Handlers for internal reads (use Server Components)
  • Sequential awaits for independent requests
  • middleware.ts instead of proxy.ts (Next.js 16)
  • Sync params or cookies() (removed)
  • revalidateTag(tag) without second argument
  • Auth only in proxy — not in Server Actions

Resource Map

ResourceOwns
server-components.mdRSC, Client boundaries, composition, context, server-only
data-fetching.mdfetch, ORM, parallel fetch, Suspense, use(), Route Handlers
caching.md'use cache', cacheLife, cacheTag, revalidation, PPR
routing.mdLayouts, pages, parallel/intercepting routes, Link
proxy.mdproxy.ts, matcher, redirects, auth gates
error-handling.mdloading, error, not-found boundaries
metadata-and-seo.mdMetadata API ownership; SEO depth → seo skill
assets.mdnext/image, next/font
migration.mdPages Router → App Router
version-changes.mdNext.js 15 → 16 breaking changes

References

Verified against Next.js 16 App Router documentation.

Last verified: July 2026

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.