api-design

Design Next.js App Router REST APIs with layered Route, Controller, Service, and Repository structure.

Updated Feb 16, 2026
One-click install
npx skills add https://github.com/Fivents/one-id --skill api-design-fivents
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-design
Source: https://github.com/Fivents/one-id/tree/main/.claude/skills/api-design
Command: npx skills add https://github.com/Fivents/one-id --skill api-design-fivents

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill captures and enforces consistent API structure and best practices to prevent business logic sprawl, inconsistent error handling, and unvalidated inputs in Next.js App Router backends so teams deliver reliable, maintainable endpoints.

Core Features & Use Cases

  • Clear Layering: Enforces Route → Controller → Service → Repository to separate concerns and simplify testing.
  • Validation & DTOs: Mandates use of DTOs and Zod validation to reduce runtime errors and improve input safety.
  • Standardized Responses: Defines predictable success payloads and mapped error responses for client stability.
  • Use Case: Implement a totem check-in API that validates attendee payloads, centralizes business rules in services, and confines Prisma access to repositories.

Quick Start

Design a Next.js App Router endpoint that follows Route → Controller → Service → Repository, uses DTOs and Zod for validation, returns standardized success and error responses, and keeps Prisma queries inside repositories.

Frequently Asked Questions about api-design

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

FAQPage Schema
How do I structure a Next.js App Router backend with clean architecture?

Next.js App Router clean architecture separates Route, Controller, Service, and Repository layers to prevent business logic sprawl. This structure confines Prisma queries to repositories and standardizes API responses for maintainable endpoints.

What's the best way to validate API inputs in Next.js without runtime errors?

Validating API inputs in Next.js requires defining DTOs and applying Zod validation. This approach reduces runtime errors by ensuring type safety and validating incoming payloads before they reach your business logic.

Where should I put Prisma queries in a Next.js API route?

Prisma queries belong exclusively in the Repository layer of a clean architecture. Calling Prisma directly from controllers or route handlers is forbidden to ensure proper separation of concerns and simplify testing.

How do I standardize REST API responses in a Next.js backend?

Standardizing REST API responses involves wrapping successful returns in a predictable { data } payload and mapping errors to consistent response formats. This ensures client applications receive stable and predictable API outputs.

Can I use Zod and DTOs together for API validation in Next.js?

Yes, using Zod and DTOs together enforces input safety in Next.js APIs. DTOs define data transfer structures while Zod validates runtime payloads, preventing unvalidated inputs from entering your service layer.

Why does my Next.js route handler contain business logic and how do I fix it?

Business logic in route handlers indicates a missing clean architecture layer separation. Fix it by moving logic into Service classes and keeping route handlers strictly for HTTP request handling and controller delegation.