Next.js API Route Architect skill for Claude and Codex
Builds a strict-TypeScript Next.js API route with a zod-validated request, a typed response, next-auth session checks, and composed middleware, so the…
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when a Next.js API route must be strict TypeScript with zod validation, typed responses, and a next-auth or token check before it ships. Do not use for a quick JavaScript route, debugging a failing route, or writing route documentation. Related topics: coding, next.js.
What it will ask you for
- Route path (free text, e.g. "/api/example")
- HTTP method (choose one: GET, POST, PUT, DELETE, PATCH)
- Authentication (choose one: None, JWT, NextAuth, API Key)
- Request body schema (longer free text)
- Success response schema (longer free text)
- Middleware (choose any: rateLimit, cors, validateBody, logRequest)
How it works
- Convert the request and response schemas into zod objects and infer their TypeScript types, so runtime checks and types share one source.
- Add the method guard that answers 405 with an Allow header for anything but the chosen method.
- Implement the chosen authentication ahead of validation and return 401 before any schema detail is exposed.
- Compose the selected middleware as typed higher-order wrappers in the listed order, with validateBody returning 400 and flattened zod issues.
- Write the handler with a typed response union and a try/catch that logs with the route path, then output the full ts file in order.
What you get
One code block tagged ts containing the full route file in this order: imports, zod schemas and inferred types, middleware wrappers, the handler, the default export.
What it watches out for
- Validating the body before checking the session, which lets anonymous callers probe the schema through error messages.
- Declaring request types by hand next to the zod schema, so the two drift the first time a field changes.
- Returning the caught error message in the 500 body, which leaks stack and database details.
- Forgetting the Allow header on the 405 response, which clients and proxies rely on.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.