← ClaudeAtlas

api-craftlisted

Design, build, and structure an HTTP/REST API server — the layered architecture (route, schema, service, repository, model), what each layer is allowed to know and return, the rejection cascade that maps every failure to a status code, outside-in build order, and what belongs in OpenAPI/schema descriptions that ship to consumers. Use when starting an API, adding an endpoint, deciding which layer a piece of logic belongs in, designing error handling and status codes, or cleaning up a generated API reference. Triggers on FastAPI, Pydantic, route vs service vs repository, schema vs model, "where does this go", 4xx/422/409 status-code design, ErrorResponse envelopes, OpenAPI summary/description hygiene, and idempotency keys. Consult before writing the first endpoint, not after. Not for client-side HTTP calls, GraphQL schema design, or non-HTTP RPC.
hsb3/dotfiles-agents · ★ 0 · API & Backend · score 70
Install: claude install-skill hsb3/dotfiles-agents
# API craft An API server is a **containment strategy, not a folder layout**. Every layer exists to absorb one kind of change so the others don't have to. Don't memorize the layers — derive them from the pressures, then keep each layer honest about what it may touch. ## The one principle **Each layer absorbs one kind of change.** Routes absorb HTTP. Schemas absorb the wire contract. Services absorb business rules. Repositories absorb storage. Models absorb the row shape. Violate this and a change in one concern ripples through all five. ## The five layers, at a glance | Layer | Role | Knows | Never | |---|---|---|---| | **route** | wire binding · HTTP only | status codes, schemas, services, auth | business `if`-branches, SQL | | **schema** | wire contract | Pydantic/validation only | the DB, the ORM model | | **service** | brain · pure logic | domain types, repositories, other services | `fastapi`, SQL, `HTTPException` | | **repository** | storage binding | ORM/driver, models, queries | domain exceptions, business intent | | **model** | storage contract | tables, columns, constraints | `.save()`, validation, business methods | The shape compresses to a mnemonic: **two contracts** (schema on the wire, model on storage), **two bindings** (routes wire↔service, repositories storage↔service), **one brain** (services, blind to both surfaces). Routes and repositories are mirror images. ## Build outside-in The ordering is the payoff — by the time you write service logic, ever