Node / Express Guide
Overview
Stack, architecture, and naming conventions for the Node/Express/MongoDB backend.
This guide documents the Express/MongoDB conventions and patterns derived from the Booki platform codebase. It applies to any TypeScript Express backend following the same layered architecture.
Stack
| Layer | Technology |
|---|---|
| HTTP framework | Express v5 |
| Real-time | Socket.IO |
| Database | MongoDB (native driver — no Mongoose) |
| Cache | Redis via ioredis |
| Auth | JWT (jsonwebtoken) — access + refresh tokens |
| Validation | Joi |
| Password hashing | bcrypt |
| File uploads | multer + AWS S3 |
| Emails | Nodemailer + Handlebars templates |
| Logging | Winston |
| Security | helmet, express-rate-limit |
| TypeScript | strict: true throughout |
Architecture Layers
HTTP Request
│
▼
Route (src/routes/) — path + middleware composition
│
▼
Middleware (src/middleware/) — tenant, auth, role guard
│
▼
Controller (src/controllers/) — validate → delegate → respond
│
▼
Service (src/services/) — business logic, orchestration
│
▼
Repository (src/repositories/) — MongoDB read/write + Redis cache
│
▼
MongoDB + Redis
Naming Conventions
| Thing | Convention | Example |
|---|---|---|
| Files | kebab-case.<layer>.ts | auth.controller.ts, user-payment.service.ts |
| Factory functions | use<Domain><Layer>() | useAuthController(), useUserRepo() |
| Interfaces | I prefix | IUser, IBooking |
| Type aliases | T prefix | TUserCreate, TBookingStatus |
| Enums | PascalCase | UserType, BookingStatus |
| Enum values | SCREAMING_SNAKE_CASE | UserType.BRANCH_MANAGER |
| Resource constant | const resource = 'auth.controller' | Used in log calls |
| Collections | CollectionName enum | CollectionName.USERS |