AgentSkillsCN

vkc-api-route-pattern

在 src/app/api/** 目录下,统一规范 Next.js App Router 的 API 路由实现(包括身份验证与会话管理、输入校验、Drizzle 查询、速率限制以及响应结构)。在本仓库中创建或重构 API 路由时采用此规范。

SKILL.md
--- frontmatter
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.
metadata:
  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) or getAdminSession (admin)
  • DB: db from @/lib/db, tables from @/lib/db/schema
  • Rate limit (if needed): checkRateLimit + rateLimitResponse
  • Responses:
    • Public APIs: prefer @/lib/api/response helpers
    • Admin APIs: typically NextResponse.json(...) directly (keep consistent within /api/admin/**)
  • Validation: this repo uses Zod. For new/refactor APIs, prefer @/lib/api/validation (src/lib/api/validation.ts) helpers like validateBody + createJsonBodyReader.

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
  • Validation helpers: src/lib/api/validation.ts

Template

  • Full skeleton (copy + customize): .codex/skills/vkc-api-route-pattern/references/api-route-template.ts