alpha

Lays out Next.js 16 App Router best practices for an AI coding tool: project structure, server and client components, caching and tooling.
description: "Best practices for building Next.js (App Router) apps with modern caching, tooling, and server/client boundaries (aligned with Next.js 16.1.1)."
applyTo: "**/.tsx, **/.ts, **/.jsx, **/.js, **/*.css"
Last updated: January 2026 (aligned to Next.js 16.1.1)
This document summarizes the latest, authoritative best practices for building, structuring, and maintaining Next.js applications. It is intended for use by LLMs and developers to ensure code quality, maintainability, and scalability.
app/ directory (App Router) for all new projects. Prefer it over the legacy pages/ directory.app/ — Routing, layouts, pages, and route handlerspublic/ — Static assets (images, fonts, etc.)lib/ — Shared utilities, API clients, and logiccomponents/ — Reusable UI componentscontexts/ — React context providersstyles/ — Global and modular stylesheetshooks/ — Custom React hookstypes/ — TypeScript type definitions(admin)) to group routes without affecting the URL path._ (e.g., _internal) to opt out of routing and signal implementation details.app/dashboard/, app/auth/).src/ (optional): Place all source code in src/ to separate from config files.Never use next/dynamic with { ssr: false } inside a Server Component. This is not supported and will cause a build/runtime error.
Correct Approach:
'use client' at the top).next/dynamic).Example:
// Server Component
import DashboardNavbar from "@/components/DashboardNavbar";
export default async function DashboardPage() {
// ...server logic...
return (
<>
<DashboardNavbar /> {/* This is a Client Component */}
{/* ...rest of server-rendered page... */}
</>
);
}
Why:
Summary:
Always move client-only UI into a Client Component and import it directly in your Server Component. Never use next/dynamic with { ssr: false } in a Server Component.
cookies(), headers(), and draftMode() are async in the App Router.params / searchParams may be Promises in Server Components. Prefer awaiting them instead of treating them as plain objects.Suspense boundaries when appropriate.'use client' at the top. Use for interactivity, state, or browser APIs.PascalCase for component files and exports (e.g., UserCard.tsx).camelCase for hooks (e.g., useUser.ts).snake_case or kebab-case for static assets (e.g., logo_dark.svg).XyzProvider (e.g., ThemeProvider).index.ts barrel file.components/.UserCard.test.tsx).kebab-case (e.g., user-profile/)PascalCase for components, camelCase for utilities/hooks, kebab-case for static assetscamelCasePascalCaseUPPER_SNAKE_CASEapp/api/ (e.g., app/api/users/route.ts).GET, POST, etc.).Request and Response APIs. Use NextRequest/NextResponse for advanced features.[param] for dynamic API routes (e.g., app/api/users/[id]/route.ts).zod or yup.fetch('/api/...')) just to reuse logic. Prefer extracting shared logic into modules (e.g., lib/) and calling it directly to avoid extra server hops.strict mode in tsconfig.json.next lint)..env.local. Never commit secrets to version control.serverRuntimeConfig / publicRuntimeConfig are removed. Use environment variables instead.NEXT_PUBLIC_ variables are inlined at build time (changing them after build won’t affect a deployed build).connection() before reading process.env).cacheComponents + use cache) over legacy caching patterns.next.config.* via cacheComponents: true.use cache directive to opt a component/function into caching.cacheTag(...) to associate cached results with tags.cacheLife(...) to control cache lifetime (presets or configured profiles).revalidateTag(tag, 'max') (stale-while-revalidate) for most cases.revalidateTag(tag) is legacy/deprecated.updateTag(...) inside Server Actions when you need “read-your-writes” / immediate consistency.unstable_cache for new code; treat it as legacy and migrate toward Cache Components.turbopack field in next.config.* (do not use the removed experimental.turbo).typedRoutes (TypeScript required).Do not create example/demo files (like ModalExample.tsx) in the main codebase unless the user specifically requests a live example, Storybook story, or explicit documentation component. Keep the repository clean and production-focused by default.
resolve_library_id to resolve the package/library name in the docs.get_library_docs for up-to-date documentation.© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com


Seated woman over giant graphite watercolor face
Paints an elegant watercolor fashion portrait of a seated woman in lavender and ivory in front of a giant graphite-and-watercolor close-up of her own face.
image-prompt, gpt-image, watercolor, portrait, woman, fashion, fashion-shoot, editorial, double-exposure, black-and-white, muted-colors, soft-lighting, full-body, vertical-format, negative-prompt, illustration, sketch, negative-space, fine-art, character-design, structured-output, for-artists, jewelry, long-form

Woman with hot cup at Christmas market
Creates a candid smartphone-style photo of a woman in a white fur coat holding a hot drink at an evening Christmas market, keeping the face from a reference photo.
image-prompt, gpt-image, nano-banana, face-reference, reference-image, negative-prompt, photorealistic, portrait, woman, christmas, holiday, winter, night-scene, candid, smartphone-photo, medium-shot, fashion, street-photography, cozy, warm-colors, structured-output, for-photographers, long-form, guardrails, cityscape

Suited man enters glowing elevator, floor display at 13
Writes a 30-second Korean mystery thriller in which a man's elevator opens onto an impossible floor 0, with scene beats, cinematography and sound design.
video-prompt, seedance, horror, thriller, short-film, cinematic, multi-shot, timed-beats, character-consistency, camera-movement, sound-effects, guardrails, structured-output, photorealistic, korea, night-scene, symmetry, moody, for-filmmakers, long-form, advanced, film-noir
Loading reviews…
Loading comments…