backend-api-mastery
Skill1 starsChanged 11 days agoMITView on GitHub
Design production-grade APIs with intentional architecture before writing endpoints. Covers protocol, database, auth, validation, testing. Do NOT use for frontend-only or config changes.
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 4 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Built on
engineering-fundamentals: Read that skill first. This document adds backend-specific implementation to the universal philosophy. - Very specific: line 50
Before applying any backend-specific instruction, check for STACK_CONFIG.md in the project root.
- Distinctive: line 53
Read it. Adapt all examples, ORM choices, and tooling to the chosen backend stack.
- Very specific: line 59
Default to Node.js + TypeScript + Express/Fastify + Prisma + PostgreSQL.
- Distinctive: line 60
Ask the user for their preferred stack and adapt patterns accordingly (middleware→decorators, Zod→Pydantic, etc.).
- Very specific: line 84
Read guides/PROTOCOL-GUIDE.md in this skill directory for the complete protocol decision matrix.
- Distinctive: line 109
Consider soft deletes vs hard deletes
- Very specific: line 112
Document in API-DESIGN.md → Section "Data Model"
- Very specific: line 120
Read guides/AUTH-GUIDE.md in this skill directory for the complete auth strategy matrix.
- Very specific: line 135
Errors: Use structured { error: { code, message, details, requestId } }.
- Very specific: line 157
All decisions must be durable: Create/Update API-DESIGN.md (Overview, Protocol Decision, Data Model, Authentication, Endpoints, Error …
- Distinctive: line 171
Before proceeding to implementation, confirm:
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Backend API Mastery
Built on engineering-fundamentals. Read that skill first. This document adds
backend-specific implementation to the universal philosophy.
No endpoint is written until the API contract is designed, justified, and locked.
When to Use
MANDATORY when:
- Building any API layer (REST, GraphQL, tRPC, WebSocket, gRPC)
- Adding a database or persistence layer to a project
- Implementing authentication or authorization
- Designing error handling, validation, or rate limiting
- Creating data models, schemas, or migrations
Triggered automatically by:
spec-driven-development(if SPEC.md indicates backend needs)architecture-analysis(if non-trivial backend is chosen)frontend-weborfrontend-mobile(if frontend needs a backend to persist data)
When NOT to Use
- The project is frontend-only with no persistence (static site, landing page)
- The backend is already designed and documented in
API-DESIGN.md - The task is purely operational (fix a bug in existing API, add one field)
Output Contract
| Artifact | Format | Location | Quality Criteria |
| API implementation + design document | Source code (framework-agnostic) + API-DESIGN.md | src/ (implementation), API-DESIGN.md (root) | Protocol decision justified (REST/GraphQL/tRPC/WebSocket), noun-based resource URIs, correct HTTP status codes, input validation (Zod/schema), object-level authorization (OWASP API1), rate limiting, structured errors { error: { code, message, details, requestId } }, pagination + filtering, API documentation (OpenAPI/GraphQL introspection/tRPC types), distributed tracing (Correlation-ID), additive-only migrations, unit + integration + contract tests passing |
Stack Detection
Before applying any backend-specific instruction, check for STACK_CONFIG.md in the project root.
If STACK_CONFIG.md exists:
- Read it. Adapt all examples, ORM choices, and tooling to the chosen backend stack.
- Protocol decisions (REST vs GraphQL vs tRPC) are framework-agnostic.
- Auth patterns (JWT vs sessions) are framework-agnostic.
- Database decisions (SQL vs NoSQL) are framework-agnostic.
If no STACK_CONFIG.md exists:
- Default to Node.js + TypeScript + Express/Fastify + Prisma + PostgreSQL.
- Ask the user for their preferred stack and adapt patterns accordingly (middleware→decorators, Zod→Pydantic, etc.).
Core Process
Phase 0 — Language Detection
→ See engineering-fundamentals Phase 0.
Phase 1 — Domain Discovery
→ See engineering-fundamentals Phase 1. Then guides/DISCOVERY-GUIDE.md for backend-specific checklist (10 questions: data/consumers/volume/auth/protocol/DB/ORM/integrations → 15 for non-trivial).
Phase 2 — Research (MANDATORY for non-trivial)
Do not propose protocols, ORMs, or auth strategies without current research. Search for best practices with [current year], check official documentation for latest versions and known limitations, and find benchmarks. Present findings concisely before proceeding.
Phase 3 — Protocol Decision
Read guides/PROTOCOL-GUIDE.md in this skill directory for the complete protocol decision matrix.
Summary: Generate 2-3 options (REST, GraphQL, tRPC, WebSocket). Never default to REST without justification. Include honest pros AND cons for each. Present to user for selection.
| Protocol | Best For | Avoid When |
| REST | Standard HTTP, caching, simple CRUD, public APIs | Complex nested queries, real-time needs |
| GraphQL | Multiple consumers, mobile apps, public APIs with exploration | Simple CRUD, caching complexity unacceptable |
| tRPC | Fullstack TypeScript, end-to-end type safety | Non-TypeScript consumers, public API for third parties |
| WebSocket/SSE | Real-time updates, chat, live dashboards | Standard request/response is sufficient |
Phase 4 — Database Design
Type: PostgreSQL (complex/relational/transactions), MySQL (simple relational), SQLite (prototype/edge), MongoDB (flexible schema/rapid iteration).
ORM: Prisma (DX/type safety), Drizzle (performance/edge), TypeORM (legacy only).
Schema:
- Identify core entities from discovery answers
- Define relationships (1:1, 1:N, N:M)
- Choose primary keys (auto-increment vs UUID vs ULID)
- Plan indexes for common query patterns
- Consider soft deletes vs hard deletes
- Plan for migrations (additive only? destructive changes?)
Document in API-DESIGN.md → Section "Data Model"
Critical Challenge: MongoDB for relational data → explain document vs relational tradeoffs. Raw SQL "for performance" → ORM adds ~10% overhead for significant type safety and DX; drop to raw SQL for hot paths only.
Phase 5 — Auth & Security
Read guides/AUTH-GUIDE.md in this skill directory for the complete auth strategy matrix.
Summary: Choose auth strategy (Session/Cookie, JWT, OAuth, API Keys). Implement validation with Zod. Apply security checklist (HTTPS, CORS, input validation, SQL injection prevention, XSS prevention, rate limiting, secrets management, security headers).
| Strategy | Best For | Avoid When |
| Session + Cookie | Traditional web apps, same-domain | Mobile apps, cross-domain |
| JWT (short-lived + refresh) | SPAs, mobile apps, stateless APIs | Long-lived tokens, revocation critical |
| OAuth 2.0 / OIDC | Third-party login, SSO | Simple internal app |
| API Keys | Service-to-service, IoT | User-facing auth |
Phase 6 — Error Handling & Testing
Errors: Use structured { error: { code, message, details, requestId } }. Correct HTTP codes (200/201/204/400/401/403/404/409/422/429/500).
Testing: See guides/TESTING-GUIDE.md. Unit (Vitest) for services. Integration (Vitest + test DB) for endpoints. Contract (Zod/OpenAPI) for shapes. E2E (browser testing tools) for flows. Always separate test DB.
Phase 7 — Documentation & Versioning
7A: Documentation
- OpenAPI/Swagger for REST APIs (generate from Zod or code)
- GraphQL introspection for GraphQL APIs
- tRPC router types serve as documentation for tRPC
Versioning: URL versioning (/v1/) for public APIs. Header versioning for internal. No versioning for CI/CD-only internal apps. Deprecate in V(N), remove in V(N+2). Return Deprecation header + sunset date.
Phase 8 — Lock & Document
Log metrics: LOG METRIC: discovery — project, skill_used, duration_minutes, questions_asked, user_confirms, research_queries
All decisions must be durable. Create/Update API-DESIGN.md (Overview, Protocol Decision, Data Model, Authentication, Endpoints, Error Handling, Testing, Security, Versioning). Update SPEC.md referencing API-DESIGN.md.
Reference
See references/REFERENCE.md for common rationalizations, red flags, and full walkthrough examples.
Verification
Verification
Before proceeding to implementation, confirm:
- Phase 1: Discovery complete with 10+ questions answered. (Verify in
guides/DISCOVERY-GUIDE.md) - Phase 2: Research completed with current year sources.
- Phase 3: Protocol chosen with 2-3 options evaluated. (Verify in
guides/PROTOCOL-GUIDE.md) - Phase 4: Database type, ORM, and schema designed.
- Phase 5: Auth strategy justified and security checklist complete. (Verify in
guides/AUTH-GUIDE.md) - Phase 6: Error format defined and testing strategy documented. (Verify in
guides/TESTING-GUIDE.md) - Phase 7: Documentation strategy (OpenAPI/GraphQL/tRPC types) chosen.
- Phase 8:
API-DESIGN.mdcreated with all sections. SPEC.mdupdated with API Design Decisions.
In this repository59 other files it gives its agents.
- AGENTS.mdAGENTS.md
- templates/CLAUDE.mdCLAUDE.md
- adapt-skillSkill
- api-and-interface-designSkill
- architecture-analysisSkill
- audit-skillSkill
- browser-testing-with-devtoolsSkill
- ci-cd-and-automationSkill
- clarify-skillSkill
- cli-toolsSkill
- code-review-and-qualitySkill
- code-simplificationSkill
- context-engineeringSkill
- critique-skillSkill
- customize-opencodeSkill
- debugging-and-error-recoverySkill
- debugging-three-strikesSkill
- delight-skillSkill
- deprecation-and-migrationSkill
- dev-environment-auditSkill
- documentation-and-adrsSkill
- doubt-driven-developmentSkill
- engineering-fundamentalsSkill
- frontend-desktopSkill
- frontend-mobileSkill
- frontend-pwaSkill
- frontend-ui-engineeringSkill
- frontend-webSkill
- fullstack-shippingSkill
- gateSkill
- git-init-and-versioningSkill
- git-workflow-and-versioningSkill
- hard-skillSkill
- idea-refineSkill
- incremental-implementationSkill
- industrial-brutalist-uiSkill
- interview-meSkill
- minimalist-uiSkill
- multi-agent-orchestrationSkill
- observability-and-instrumentationSkill
- optimize-skillSkill
- output-skillSkill
- performance-optimizationSkill
- planning-and-task-breakdownSkill
- polish-skillSkill
- project-health-checkSkill
- project-metricsSkill
- redesign-skillSkill
- security-and-hardeningSkill
- self-improvementSkill
- shipping-and-launchSkill
- skill-creatorSkill
- skill-improverSkill
- soft-premium-uiSkill
- source-driven-developmentSkill
- spec-driven-developmentSkill
- test-driven-developmentSkill
- typeset-skillSkill
- user-onboardingSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

