Express

Quick Navigation

FilePurpose
middleware-patterns.mdMiddleware execution order, error handling, factory pattern, auth chain, and Zod validation
project-structure.mdFeature-based folder layout, router mounting, graceful shutdown, and constructor DI

Reading Strategy

Start with the SKILL.md for the core Express patterns (router modularization, async error wrapper, centralized error middleware, input validation). Then use the reference files for deeper implementation guidance:

  • Building middleware or securing routes: read middleware-patterns.md — it covers the full middleware execution stack, the 4-argument error handler signature, factory patterns for configurable middleware, JWT auth chains, and Zod-based validation middleware.
  • Structuring a new or existing Express project: read project-structure.md — it covers the feature-based folder layout, how to mount routers with dependency injection, graceful SIGTERM shutdown, and constructor injection without a DI framework.

The two files are complementary. A complete Express application uses patterns from both.


File Descriptions

middleware-patterns.md — Deep coverage of Express middleware: correct registration order (security → body → logging → rate-limit → auth → routes → 404 → error), the 4-argument ErrorRequestHandler signature, custom AppError class with status codes, middleware factory pattern for configurable and reusable middleware, JWT verification + user-load auth chain with typed req.user, and a generic Zod validate() factory for body/params/query validation.

project-structure.md — Project architecture patterns: feature-based folder layout with strict import layer rules, createApp() factory function for testable app creation, feature router factory that accepts injected dependencies, graceful shutdown with SIGTERM/SIGINT handlers, connection draining with a force-exit timeout, and constructor injection with interface types for fully mockable services, repositories, and controllers.


Cross-Reference Map

ConceptWhere it appears
Middleware registration ordermiddleware-patterns.md: Execution Order section
4-argument error handlermiddleware-patterns.md: Error-Handling Middleware, SKILL.md: Centralized Error Middleware
AppError with statusCodemiddleware-patterns.md: Error-Handling Middleware
Middleware factory patternmiddleware-patterns.md: Custom Middleware Factory
JWT verification + user load chainmiddleware-patterns.md: Authentication Chain
Zod validate() factorymiddleware-patterns.md: Request Validation, SKILL.md: Input Validation Middleware
Feature-based folder structureproject-structure.md: Feature-Based Folder Structure
Layer import rulesproject-structure.md: Feature-Based Folder Structure
Router mounting with DIproject-structure.md: Router Mounting Strategy
Graceful shutdown (SIGTERM)project-structure.md: Graceful Shutdown Pattern
Constructor injection patternproject-structure.md: Dependency Injection Without Frameworks
Async handler wrapperSKILL.md: Async Error Wrapper