A maintainable backend separates responsibilities without creating unnecessary complexity.
Common structure
- routes: HTTP endpoints
- controllers: request/response coordination
- services: business rules
- db: persistence
- middleware: reusable request processing
- tests: automated verification
Deep dive
app.js vs server.js
A useful pattern is to configure the Express application in one module and start listening on a network port in another. This makes automated testing easier because tests can import the application without starting a real server.