Backend API Architecture
Purpose
Define how the backend is organized internally — layers, domain boundaries, dependency direction, and homes for cross-cutting concerns — so every feature lands in a predictable place regardless of framework.
When to Use
- After the stack decision, before or alongside the foundation skill.
- When an existing backend's structure is being reworked (
../../refactor-planning).
- Not for the external API shape — that's
rest-api-design / graphql-api-design.
Inputs
- Architecture design (
../../architecture-design) and domain list.
- Chosen framework (
backend-stack-selection) and data layer (../../database/).
Discovery Questions
- What are the domains, and which depend on which?
- Where must transactions and authorization be enforced (service layer, typically)?
- What is shared across domains (auth context, errors, config, utilities)?
Responsibilities
- Define layers and dependency direction: transport (routes/controllers) → services (business rules) → data layer; lower layers never import upward.
- Draw domain boundaries; cross-domain calls go through service interfaces, not each other's tables.
- Place cross-cutting concerns: validation at the edge (
backend-validation), authorization at the edge + service (backend-authorization), transactions in services (../../database/transactions), errors centrally (backend-error-handling).
- Define DTO/model separation: transport shapes ≠ database entities (
api-contracts).
- Document the unit as it is built —
docs/<app>/README.md and the per-resource files under docs/<app>/api/ (../../application-documentation).
Required Workflow
- List domains and their dependencies; break cycles by extracting shared concepts.
- Fix the layer rules and dependency direction.
- Assign each cross-cutting concern a single home.
- Define transport-vs-entity mapping rules.
- Record the architecture for the foundation skill to apply.
Decision Rules
- Business rules live in services — testable without HTTP.
- A domain owns its data access; other domains ask its service.
- Controllers stay thin: parse/validate → call service → map result to response.
- Start modular-monolith; extract services only under real scaling/ownership pressure (
../../architecture-design).
Rules
- One home per concern — no validation/authz scattered across layers ad hoc.
- Never return database entities directly from the transport layer.
- Record deviations explicitly; silent exceptions rot the architecture.
Anti-Patterns
- Fat controllers / anemic services.
- Domain A querying domain B's tables directly.
- Circular service dependencies.
- "Utils" folders accumulating business logic.
Validation Checklist
Definition of Done
A recorded internal architecture — layers, boundaries, concern placement, mapping rules — that the foundation skill can apply and reviewers can enforce.
Related Skills
../../architecture-design, express-foundation, nestjs-foundation, rest-api-design, api-contracts, backend-validation, backend-authorization, backend-error-handling, ../../database/transactions, ../../application-documentation.
Related Knowledge
../../../knowledge/ (domain model, boundary decisions).
Related References
../../../references/backend/ (architecture notes, when populated).
Context Loading Guidance
- Requires: domain list, stack decision, architecture summary.
- Does not require: endpoint-level detail, framework docs, other packs.
- May load: one foundation skill,
api-contracts.
- Stop when: the internal architecture is recorded.
Token Efficiency Guidance
Work at boundary altitude — a dependency table and layer rules, not code. Delegate endpoint shape to the API-design skills.
1---2name: backend-api-architecture3description: Use to define the internal architecture of a backend API — layering (transport/controllers/services/data), domain boundaries, where cross-cutting concerns live, and how modules communicate. Framework-agnostic; foundations apply it per framework.4---56# Backend API Architecture78## Purpose910Define how the backend is organized internally — layers, domain boundaries, dependency direction, and homes for cross-cutting concerns — so every feature lands in a predictable place regardless of framework.1112## When to Use1314- After the stack decision, before or alongside the foundation skill.15- When an existing backend's structure is being reworked (`../../refactor-planning`).16- **Not** for the external API shape — that's `rest-api-design` / `graphql-api-design`.1718## Inputs1920- Architecture design (`../../architecture-design`) and domain list.21- Chosen framework (`backend-stack-selection`) and data layer (`../../database/`).2223## Discovery Questions2425- What are the domains, and which depend on which?26- Where must transactions and authorization be enforced (service layer, typically)?27- What is shared across domains (auth context, errors, config, utilities)?2829## Responsibilities3031- Define layers and dependency direction: **transport (routes/controllers) → services (business rules) → data layer**; lower layers never import upward.32- Draw **domain boundaries**; cross-domain calls go through service interfaces, not each other's tables.33- Place cross-cutting concerns: validation at the edge (`backend-validation`), authorization at the edge + service (`backend-authorization`), transactions in services (`../../database/transactions`), errors centrally (`backend-error-handling`).34- Define DTO/model separation: transport shapes ≠ database entities (`api-contracts`).35- Document the unit as it is built — `docs/<app>/README.md` and the per-resource files under `docs/<app>/api/` (`../../application-documentation`).3637## Required Workflow38391. List domains and their dependencies; break cycles by extracting shared concepts.402. Fix the layer rules and dependency direction.413. Assign each cross-cutting concern a single home.424. Define transport-vs-entity mapping rules.435. Record the architecture for the foundation skill to apply.4445## Decision Rules4647- Business rules live in **services** — testable without HTTP.48- A domain owns its data access; other domains ask its service.49- Controllers stay thin: parse/validate → call service → map result to response.50- Start modular-monolith; extract services only under real scaling/ownership pressure (`../../architecture-design`).5152## Rules5354- One home per concern — no validation/authz scattered across layers ad hoc.55- Never return database entities directly from the transport layer.56- Record deviations explicitly; silent exceptions rot the architecture.5758## Anti-Patterns5960- Fat controllers / anemic services.61- Domain A querying domain B's tables directly.62- Circular service dependencies.63- "Utils" folders accumulating business logic.6465## Validation Checklist6667- [ ] Layers + dependency direction defined.68- [ ] Domain boundaries drawn; cross-domain access via services.69- [ ] Cross-cutting concerns each assigned one home.70- [ ] DTO/entity separation defined.71- [ ] Recorded for the foundation skill.7273## Definition of Done7475A recorded internal architecture — layers, boundaries, concern placement, mapping rules — that the foundation skill can apply and reviewers can enforce.7677## Related Skills7879`../../architecture-design`, `express-foundation`, `nestjs-foundation`, `rest-api-design`, `api-contracts`, `backend-validation`, `backend-authorization`, `backend-error-handling`, `../../database/transactions`, `../../application-documentation`.8081## Related Knowledge8283`../../../knowledge/` (domain model, boundary decisions).8485## Related References8687`../../../references/backend/` (architecture notes, when populated).8889## Context Loading Guidance9091- **Requires:** domain list, stack decision, architecture summary.92- **Does not require:** endpoint-level detail, framework docs, other packs.93- **May load:** one foundation skill, `api-contracts`.94- **Stop when:** the internal architecture is recorded.9596## Token Efficiency Guidance9798Work at boundary altitude — a dependency table and layer rules, not code. Delegate endpoint shape to the API-design skills.