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.
TL;DR — Factory functions everywhere (no classes for layers), MongoDB native driver (no Mongoose), Redis caching via
codi-node-utils, Joi validation, JWT auth with jti-based revocation.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 (via codi-node-utils) |
| File uploads | multer + AWS S3 |
| Emails | Nodemailer + Handlebars templates |
| PDF generation | Puppeteer |
| HTTP client | Axios |
| Timezone handling | moment-timezone |
| Logging | Winston (via codi-node-utils) |
| Security | helmet, express-rate-limit |
| TypeScript | strict: true throughout |
Architecture Layers
HTTP Request
│
▼
Global Middleware (app.ts) — cors, json, helmet, rate-limit
│
▼
Tenant Middleware (global) — resolves organizationId from slug/query/user
│
▼
Load Organization (global) — attaches full org object to request
│
▼
Route (src/routes/) — path + per-route middleware (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 |
| Config exports | SCREAMING_SNAKE_CASE | MONGO_URI, ACCESS_TOKEN_SECRET |
| Resource constant | const resource = 'auth.controller' | Used in log calls |
| Collections | CollectionName enum | CollectionName.USERS |
