Express REST API Architecture: Controller, Service, Repository
A reference layout for Node.js and Express services: Controller, Service and Repository layers, a config module and shared middleware.
graph TD
Request[HTTP Request] --> Router[API Router Layer]
Router --> Middleware[Auth, Logging & Error Middleware]
Middleware --> Controller[Controller Layer: HTTP Ingress]
Controller --> Config[Environment Config Module]
Controller --> Service[Business Service Layer]
Service --> Storage[(Data Access Layer)]Architectural Layers
src/config.js: Environment variable validation and application runtime configuration.src/middleware/: Request correlation ID tracking, error handling, and security headers.src/routes/: Route definitions mapping REST endpoints to dedicated controllers.src/controllers/: HTTP request unwrapping, status code assignment, and response formatting.
Technology Stack
- Runtime: Node.js
- Framework: Express.js
- Pattern: Layered MVC / Clean Architecture
Running Locally
npm install
npm start