vkc-api-route-pattern
Standardize Next.js App Router API route implementations under src/app/api/** (auth/session, input validation, Drizzle queries, rate limiting, response shape). Use when creating or refactoring API routes in this repo.
When & Why to Use This Skill
This Claude skill standardizes Next.js App Router API route implementations, ensuring consistent patterns for authentication, database interactions via Drizzle, rate limiting, and response formatting. It streamlines the development process by providing a canonical skeleton for robust and secure backend endpoints, reducing boilerplate and architectural drift.
Use Cases
- Creating new API endpoints: Quickly generate boilerplate-free routes under src/app/api/ with integrated session handling and input validation.
- Refactoring existing routes: Systematically update legacy endpoints to match the project's house style for consistent error handling and response shapes.
- Implementing Rate Limiting: Easily add checkRateLimit and rateLimitResponse patterns to public-facing APIs to prevent abuse.
- Database Integration: Seamlessly incorporate Drizzle ORM queries and schema-compliant data fetching within the Next.js App Router structure.
| name | vkc-api-route-pattern |
|---|---|
| description | Standardize Next.js App Router API route implementations under src/app/api/** (auth/session, input validation, Drizzle queries, rate limiting, response shape). Use when creating or refactoring API routes in this repo. |
| short-description | API Route skeleton + rules |
VKC API Route Pattern
When to use
- Creating new endpoints under
src/app/api/** - Refactoring existing endpoints to match house style
House style (this repo)
- Auth:
getSession(user) orgetAdminSession(admin) - DB:
dbfrom@/lib/db, tables from@/lib/db/schema - Rate limit (if needed):
checkRateLimit+rateLimitResponse - Responses:
- Public APIs: prefer
@/lib/api/responsehelpers - Admin APIs: typically
NextResponse.json(...)directly (keep consistent within/api/admin/**)
- Public APIs: prefer
- Validation: repo currently uses explicit runtime checks (no Zod dependency yet). If Zod is added later, migrate route-by-route.
Canonical references
- Public route w/ validation + rate-limit:
src/app/api/reports/route.ts - Public route w/ typed allowlists:
src/app/api/events/route.ts - Admin CRUD + schedule fields:
src/app/api/admin/news/route.ts
Template
- Full skeleton (copy + customize):
.codex/skills/vkc-api-route-pattern/references/api-route-template.ts