On-demand loading: Read this skill only when the task clearly matches the description above or trigger phrases below. Do not load for unrelated work.
Node.js Backend Patterns
When to Use This Skill
- Building REST APIs or GraphQL servers
- Creating microservices with Node.js
- Implementing authentication and authorization
- Designing scalable backend architectures
- Setting up middleware and error handling
- Integrating databases (SQL and NoSQL)
- Building real-time applications with WebSockets
- Implementing background job processing
Key Principles
Structure: Separate transport (HTTP layer) from business logic; keep auth, validation, and domain rules in clear layers.
Validation: Validate inputs at the boundary with Zod or class-validator; never trust upstream callers.
Errors: Named error types per domain; never swallow errors silently; consistent response shapes.
Database: Parameterized queries only; transactions for multi-step mutations; paginate unbounded reads; migrations for schema changes.
Auth: Verify authentication before authorization; short-lived tokens; validate scope/audience/expiry on every request.
Background jobs: Design for idempotency (safe to retry); log start/success/failure; use dead-letter queues for critical jobs.
Observability: Structured JSON logging with correlation IDs; P50/P95/P99 latency metrics; error-rate alerts.
Framework Quick Reference
| Framework |
Use when |
| Express.js |
Flexibility needed, large ecosystem of middleware |
| Fastify |
High throughput, structured logging built-in, schema validation |
| NestJS |
Enterprise, large team, strong DI and module conventions |
Detailed Patterns
For complete code examples covering all patterns below, read REFERENCE.md in this directory:
- Core Frameworks — Express setup, Fastify setup, NestJS module structure
- Architectural Patterns — Layered architecture, Repository pattern, CQRS, Event-driven
- Middleware Patterns — Rate limiting, request validation, correlation IDs, caching middleware
- Error Handling — Custom error classes, global error middleware, async error propagation
- Database Patterns — Connection pooling, query builders, transaction management, migrations
- Authentication & Authorization — JWT validation, session management, RBAC, API key auth
- Caching Strategies — Redis caching, cache invalidation, cache-aside pattern
- API Response Format — Consistent envelope shape, pagination, error response format
- Testing Patterns — Unit tests for services, integration tests for routes, test containers
Execution
- Read
REFERENCE.md for the specific pattern(s) needed
- Follow existing repo conventions before introducing new patterns
- Validate: lint + typecheck + targeted tests before declaring done
Source: kscius/KS-Cursor-Orchestrator — distributed by TomeVault.
1---2name: nodejs-backend-patterns-223description: Build production-ready Node.js backend services with Express/Fastify, implementing middleware patterns, error handling, authentication, database integration, and API design best practices. Use when creating Node.js servers, REST APIs, GraphQL backends, or microservices architectures. Use when this capability is needed.4---56> **On-demand loading:** Read this skill only when the task clearly matches the description above or trigger phrases below. Do not load for unrelated work.78# Node.js Backend Patterns910## When to Use This Skill1112- Building REST APIs or GraphQL servers13- Creating microservices with Node.js14- Implementing authentication and authorization15- Designing scalable backend architectures16- Setting up middleware and error handling17- Integrating databases (SQL and NoSQL)18- Building real-time applications with WebSockets19- Implementing background job processing2021## Key Principles2223**Structure:** Separate transport (HTTP layer) from business logic; keep auth, validation, and domain rules in clear layers.2425**Validation:** Validate inputs at the boundary with Zod or class-validator; never trust upstream callers.2627**Errors:** Named error types per domain; never swallow errors silently; consistent response shapes.2829**Database:** Parameterized queries only; transactions for multi-step mutations; paginate unbounded reads; migrations for schema changes.3031**Auth:** Verify authentication before authorization; short-lived tokens; validate scope/audience/expiry on every request.3233**Background jobs:** Design for idempotency (safe to retry); log start/success/failure; use dead-letter queues for critical jobs.3435**Observability:** Structured JSON logging with correlation IDs; P50/P95/P99 latency metrics; error-rate alerts.3637## Framework Quick Reference3839| Framework | Use when |40|-----------|----------|41| Express.js | Flexibility needed, large ecosystem of middleware |42| Fastify | High throughput, structured logging built-in, schema validation |43| NestJS | Enterprise, large team, strong DI and module conventions |4445## Detailed Patterns4647For complete code examples covering all patterns below, read `REFERENCE.md` in this directory:4849- **Core Frameworks** — Express setup, Fastify setup, NestJS module structure50- **Architectural Patterns** — Layered architecture, Repository pattern, CQRS, Event-driven51- **Middleware Patterns** — Rate limiting, request validation, correlation IDs, caching middleware52- **Error Handling** — Custom error classes, global error middleware, async error propagation53- **Database Patterns** — Connection pooling, query builders, transaction management, migrations54- **Authentication & Authorization** — JWT validation, session management, RBAC, API key auth55- **Caching Strategies** — Redis caching, cache invalidation, cache-aside pattern56- **API Response Format** — Consistent envelope shape, pagination, error response format57- **Testing Patterns** — Unit tests for services, integration tests for routes, test containers5859## Execution60611. Read `REFERENCE.md` for the specific pattern(s) needed622. Follow existing repo conventions before introducing new patterns633. Validate: lint + typecheck + targeted tests before declaring done6465---66> Source: [kscius/KS-Cursor-Orchestrator](https://github.com/kscius/KS-Cursor-Orchestrator) — distributed by [TomeVault](https://tomevault.io).67<!-- tomevault:4.0:skill_md:2026-06-15 -->