Skip to content
Skills Library
Programming · Building & coding

nodejs-backend-patterns

/nodejs-backend-patterns

Node.js backend architecture: use when building or refactoring Fastify/Express services that need fail-fast schema validation, layered controller/service/repository separation, pooled transactional data access, a single error envelope, or drain-based shutdown.

Licence
MIT
Last repository change
27.10.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Node.js backend architecture: use when building or refactoring Fastify/Express services that need fail-fast schema validation, layered controller/service/repository separation, pooled transactional data access, a single error envelope, or drain-based shutdown.

Original author description

Node.js backend architecture: use when building or refactoring Fastify/Express services that need fail-fast schema validation, layered controller/service/repository separation, pooled transactional data access, a single error envelope, or drain-based shutdown.

How it works

  1. Stack Defaults
  2. Core Steps
  3. Disclosed Reference
Original SKILL.md headings · 51 lines, 403 words
SKILL.md preview
---
name: nodejs-backend-patterns
description: 'Node.js backend architecture: use when building or refactoring Fastify/Express services that need fail-fast schema validation, layered controller/service/repository separation, pooled transactional data access, a single error envelope, or drain-based shutdown.'
metadata:
  category: reference
---

# Node.js Backend Patterns

Operational architecture guide for Node.js backends: `fail-fast` contracts, `layered` responsibilities, `pooled` data access, one `envelope`, graceful `drain`.

## Stack Defaults

- **Default**: Fastify + TypeScript + PostgreSQL (`pg`) + Zod + Pino.
- **Express**: Use when integrating into existing Express middleware pipelines.
- **MongoDB**: Use when document datastores are mandated by existing schema design.

## Core Steps

### 1. Define Boundary Contracts (`fail-fast`)

- Type every public route with explicit schemas for params, query, body, and responses.
- Validate at the HTTP layer; schema failures return 400 before reaching service logic.
- **Completion criterion**: Every public route defines strict schemas and returns 400 on schema failure.

### 2. Isolate Responsibilities (`layered`)

- **Controller**: Parse HTTP requests, delegate to service, return HTTP response codes.
- **Service**: Domain and business logic, authorization checks, transaction orchestration.
- **Repository**: Raw SQL/queries, data mapping, direct database pool interactions.
- Wire components using constructor-based dependency injection.
- **Completion criterion**: Every controller handles transport only (no SQL/DB imports); every service handles domain logic only (no HTTP request/response imports).

### 3. Manage Connections & Transactions (`pooled`)

- Configure database connection pools with explicit max connections, idle timeouts, and connection timeouts.
- Wrap multi-operation writes in atomic transactions (`BEGIN` / `COMMIT` / `ROLLBACK`).
- Release checked-out pool clients in `finally` blocks.
- **Completion criterion**: Every multi-statement write runs in a transaction that rolls back on error; every checked-out pool client is released on all execution paths.

### 4. Standardize Responses & Errors (`envelope`)

- Use a single top-level error handler mapping typed `AppError` subclasses to status codes.
- Return one JSON envelope for success (`{ status: "success", data }`) and failure (`{ status: "error", code, message }`); sanitize messages in production.
- **Completion criterion**: Every request-scoped error passes through the global error handler and returns the failure envelope with a sanitized message.

### 5. Wire Process Lifecycle (`drain`)

- Bind `SIGTERM` and `SIGINT` to a coordinated shutdown handler.
- Stop accepting new HTTP requests, drain in-flight requests within a grace timeout (e.g., 10s), then close DB pools and cache connections.
- Keep the force-exit timer unref'd so it never holds the event loop open.
- **Completion criterion**: Application exits with code 0 on termination signal after in-flight connections drain and pools close.

## Disclosed Reference

Implementation blueprints — schema definitions, DI container, pool configuration, transaction helper, error handler, shutdown handler — in [`resources/implementation-playbook.md`](resources/implementation-playbook.md). Load when implementing any step.
Files in this package (2)
  • SKILL.md 3 KB
  • resources/implementation-playbook.md 8 KB

Versions

RepositoryScoreLicence
This page · j0hanz/j0hanz-marketplace90MIT
rootcastleco/rei-skills100MIT
wshobson/agents100MIT
HermeticOrmus/LibreUIUX-Claude-Code91MIT
LeoYeAI/openclaw-master-skills91MIT

Database snapshot: 13.11.2026 · package version 75553979cc63 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100nodejs-backend
    Node.js backend patterns: framework selection, layered architecture, TypeScript, validation, error handling, security, production deployment. Use when building REST APIs, Express/Fastify servers, microservices, or server-side TypeScript.
  • 100nodejs-backend
    Guides Node.js backend services built on Fastify, NestJS, Hono or Express. Use when writing, reviewing or hardening a Node.js HTTP service or moving one off Express, or a service leaks stack traces, drops in-flight requests on deploy, logs the wrong user, or blocks the event loop.
  • 100nodejs-backend-expert
    Expert Node.js backends (Express/Fastify/Hono): routing, middleware, validation, auth, async, and production hardening. Trigger keywords: Node.js, Express, Fastify, Hono, REST, middleware, JWT, session, zod, async, streams, unhandled rejection, graceful shutdown, backend,…
  • 90nodejs-architecture
    Use this skill when designing Node.js backend architecture — Express, Fastify, Hono. Project structure, middleware pipeline, routing, error handling, validation. This skill enforces: separation of concerns, correct middleware ordering, global error handling, Zod/Joi validation…
  • 90nodejs-fastify
    Use this skill when building Fastify applications — schema validation, plugin system, hooks, serialization. This skill enforces: JSON Schema validation, plugin encapsulation, schema serializers, Fastify lifecycle hooks. Do NOT use for: Express.js apps, database schema, frontend,…
  • 100backend-patterns
    Applies production backend patterns: middleware, error handling, auth, database integration, and API design. Use when working with backend service files or when the user mentions Express, Fastify, NestJS, backend patterns, or service architecture.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.