/be:api-architecturefrom Backend Skills
How an API route is built in a Next.js API — the fixed order of rate limit, authorise, validate, delegate, audit, respond; thin routes over services; the response envelope and typed errors; caching headers; concurrent edits; long-running work; cursor pagination and allowlisted sorts; resource paths, versions, deprecation and state-transition sub-routes; and what every new route ships with. Cron, webhooks and audit logs are references. Use when adding, changing or reviewing a route handler or the API layer's structure.
Ships in Backend Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A route handler is the HTTP edge and nothing else. Business logic lives in services, so a rule holds in one place whether a route, a cron task or another service triggers it, and every route is short enough to review against one checklist.
Before applying this skill, read the project's root AGENTS.md, the AGENTS.md closest to the files in question, and any doc they link for this skill's topic. Names, values and choices — budgets, tiers, tokens, voice, paths — come from those files, never from this skill.
Every handler runs the same sequence, in this order — rate limit → authorise → validate → delegate → audit → respond:
export async function POST(request: Request, ctx: { params: Promise<{ eventId: string }> }) {
try {
await applyRateLimit(request, "WRITE", "events:publish");
const { actor, event } = await loadEventWithPermission(request, (await ctx.params).eventId, "event.publish");
const input = await validateBody(request, PublishEventSchema);
const published = await publishEvent(event, input, actor); // one service call
auditLog(request, actor, { action: "event.publish", targetId: event.id }); // privileged only
return ok(published, "Event published");
} catch (error) {
return errorResponse(error);
}
}
rate-limiting's.auth; what they may do → access-control. A guard that loads the resource checks existence before permission, so a caller without access gets 404, never a 403 that confirms the id exists.validate… helpers; write schemas are .pick() allowlists (schemas-and-contracts). ctx.params is a Promise — await it, then validate it.audit-log).Response.code-structure).firestore); clients are the configured SDKs.{ success: true, data, message?, metadata? } or { success: false, error: { code, message, details? } }, typed in the shared contracts — built only by ok, created, noContent, paginated and errorResponse. A hand-rolled body breaks every consumer's unwrap.code clients branch on: validation (400, with every failing field in details), bad request (400), unauthorised (401), forbidden (403, or a plan's FEATURE_NOT_IN_PLAN and PLAN_LIMIT_REACHED — plan-entitlements), not found (404), conflict (409), precondition failed (412), too many requests (429, with Retry-After), service unavailable (503). errorResponse maps them; an unexpected error is a 500 whose message is hidden outside local.firestore).Cache-Control: no-store (OWASP), set once in the shared builders, so no browser or shared cache keeps a copy of someone's data. Consumers cache reads in their own server cache and expire them after a mutation (nextjs). A public read with nothing personal in it may opt into a shared-cache policy, deliberately and per route.Two people editing the same record must not silently overwrite each other. A read returns the record's version — an ETag, or a version field the store increments on every write — and an update sends it back, in If-Match or the body. The service compares it in the same transaction as the write: a mismatch is a 412 for If-Match, a 409 for a body field, and the client reloads and shows what changed. Counters and toggles that can't conflict use atomic increments instead (firestore).
A request that can outlast the host's timeout — an export, a bulk import, a report — answers 202 with the id of an operation record and its path; the work runs from a queue, and the client polls the operation (status, progress, the result or an error) until it's done. Never hold a request open waiting for it.
Cursor pagination, never offset. One shared helper runs the paged query; the service returns the page, its cursors and a total from a stored counter; paginated builds the metadata (limit, total, totalPages, nextCursor, prevCursor, hasNext, hasPrevious). Every ordered query has its composite index committed (firestore). A list returns a projection, never whole documents (schemas-and-contracts).
Sort and filter only on allowlisted fields, each an enum in the list's query schema with its index committed; an unknown field is a 400. A client's field name never reaches the query unchecked.
app/api/v1/<resource>/…. A breaking change adds v2 beside v1, never edits v1 in place, because deployed clients still call it; additive changes go into the current version. Consumers build every path from one version constant (code-structure). Before a version is retired, its responses send Deprecation (RFC 9745) and Sunset (RFC 8594) with a Link to the migration notes, and integrators are told; it's deleted after the sunset date, once nothing calls it — the API reference is the inventory to check.account/profile, account/preferences) whichever feature edits them; the feature is the route's API-reference tag (openapi-registry).<resource>/route.ts lists and creates; <resource>/[id]/route.ts reads, updates and deletes.POST sub-route — publish/unpublish, suspend/unsuspend, archive — with its own permission and audit action. DELETE removes a thing; it never turns one off.webhook-delivery.backend-security, maintenance-mode).In the same change: the request and response schemas (schemas-and-contracts), the data function and any composite index, the service, the route in six steps, its API-reference entry (openapi-registry), a colocated route.test.ts calling the exported handler with a real Request (testing), and the path in each consumer's endpoints file.
no-store; check the version on every update; answer slow work with 202 and an operation; page with cursors; allowlist sort and filter fields; announce a version's sunset; group paths by resource; make transitions sub-routes; ship the reference entry and the test with the route.v1 for a breaking change; let a stale edit overwrite a newer one; hold a request open for slow work; use DELETE to switch something off; let an audit write fail the request.Rate limits rate-limiting · sessions auth · permissions access-control · schemas schemas-and-contracts · the store firestore · the API reference openapi-registry · route tests testing · server-side threats backend-security · the audit log audit-log · where files live code-structure.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub timonwa/engineering-skills --plugin be22 skills in this plugin
/access-controlAccess control for a Next.js API on Firebase — roles, relationships and attributes (RBAC, ReBAC, ABAC) behind permission verbs and one pure can(); guards as the only gate, 404 before 403; tenant scoping; invitations; escalation limits; two-person approval and access reviews; stale claims; API-key scopes; share links and passcodes; where plan and flag checks sit; UI gates that only hide; and tests. Use when adding a permission, role, guarded route, API key, share link, or a control only some people see./access-control-auditManually invoked. Access-control audit — guards on every route and Server Action (BFLA), 404 before 403 and tenant scoping (BOLA), allowlisted writes and projected reads (BOPLA), verbs never role names, roles that add up, escalation and invitations, claims and revocation, sessions and sign-in, API keys and share links, the plan and flag order, UI gates, data rules and the tests. Verifies each finding and writes a prioritised report./api-auditManually invoked. API-layer audit — the six-step route, thin routes over services, validation at every boundary, the envelope, typed errors and no-store, concurrent edits and long-running work, a named rate limit on every route, cursor lists, versions and transitions, the audit log, each route's reference entry and test, cron, webhook and proxy rules, and where present maintenance mode, flags, plan entitlements, outgoing webhooks and email sending. Verifies each finding and writes a prioritised report.Other plugins' skills for the same job