building-app-routes

Guides adding pages, layouts, and Route Handlers in a Next.js App Router codebase.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/tomada1114/quick-reply-drill --skill building-app-routes-tomada1114
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: building-app-routes
Source: https://github.com/tomada1114/quick-reply-drill/tree/main/.agents/skills/building-app-routes
Command: npx skills add https://github.com/tomada1114/quick-reply-drill --skill building-app-routes-tomada1114

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Deciding where new code belongs in a Next.js App Router project is error-prone: logic parked in route files escapes test coverage, misplaced "use client" directives bloat the client bundle, and environment variables leak into the browser. This Skill provides the procedure for placing pages, layouts, handlers, and configuration correctly inside a strict layered architecture. ## Core Features & Use Cases - Server/Client boundary placement: Rules for which file carries the "use client" directive, keeping pages as Server Components and pushing state and effects into the smallest client file. - Route Handler pattern: A three-step recipe where src/app/api/<name>/route.ts is a one-line re-export of a Web-standard handler factory wired in src/server/composition.ts, testable with a plain Request object. - Configuration discipline: All process.env reads centralized in src/server/env.ts, with guidance on optional versus required variables and the risks of NEXT_PUBLIC_ inlining. - Use Case: When adding a new JSON endpoint, follow the Skill to write the handler in src/server/handlers/, wire it in composition.ts, re-export it from route.ts, and bound the request body before any model call. ## Quick Start Ask the AI to add a new API endpoint or page to the Next.js App Router project following the building-app-routes conventions.

Frequently Asked Questions about building-app-routes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new API route in Next.js App Router?▼

Write the logic as a create<Name>Handler factory in src/server/handlers/ returning (request: Request) => Promise<Response>, wire it in src/server/composition.ts, then re-export it as a one-line POST export from src/app/api/<name>/route.ts.

Where should the "use client" directive go in Next.js?▼

Place "use client" on the smallest file that owns state, effects, browser APIs, or DOM event handlers, and pass data down as props from Server Components. Never put it on a layout, since that moves the entire subtree into the client bundle.

Can a Next.js Route Handler be unit tested without the framework?▼

Yes, when the handler is written as a Web-standard function taking a Request and returning a Response with no next imports. Tests drive it with a plain new Request(...) and assert on the Response, as the repository's server tests do.

Why should process.env only be read in one module?▼

Centralizing process.env reads in src/server/env.ts makes configuration auditable in one file and prevents secrets from leaking into client bundles. Other modules receive values as arguments wired through the composition root.

What are the risks of NEXT_PUBLIC_ environment variables?▼

Next.js inlines NEXT_PUBLIC_ variables into the client bundle at build time, so the value is published to every user and frozen until a rebuild. Never prefix credentials, and prefer constants or props for genuinely public values.

Why is pnpm build required after changing files under src/app/?▼

Unit tests never render the App Router tree and typecheck does not resolve "use client", the server-only marker, or route export shapes. Only pnpm build validates those constraints, and opening the page confirms the request actually reaches it.