Express.js Coding Guidelines
Requirements
- Express ≥ 5, TypeScript ≥ 5.8, Helmet/CORS/Morgan, Zod.
Essentials
- Project structure - Routes, controllers, middleware as separate modules, see reference/project-structure.md
- Input validation - Validate params/body/query with Zod at route edges, see reference/validation.md
- Error handling - Central error handler, never leak stack traces in prod, see reference/error-handling.md
- Authentication - JWT auth with role/permission middleware, see reference/authentication.md
- Response format - Consistent JSON shape and status codes, see reference/responses.md
- Testing - Unit-test controllers/middleware, integration-test routes, see reference/testing.md
Progressive disclosure
- Read reference/project-structure.md - When organizing a new Express project
- Read reference/routes.md - When defining REST endpoints or route patterns
- Read reference/controllers.md - When implementing request handlers
- Read reference/validation.md - When adding input validation to routes
- Read reference/authentication.md - When implementing JWT auth or session management
- Read reference/error-handling.md - When centralizing error responses
- Read reference/responses.md - When standardizing API response formats
- Read reference/app-setup.md - When configuring Express app initialization
- Read reference/testing.md - When writing unit or integration tests