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

LayerTechnology
HTTP frameworkExpress v5
Real-timeSocket.IO
DatabaseMongoDB (native driver — no Mongoose)
CacheRedis via ioredis
AuthJWT (jsonwebtoken) — access + refresh tokens
ValidationJoi
Password hashingbcrypt (via codi-node-utils)
File uploadsmulter + AWS S3
EmailsNodemailer + Handlebars templates
PDF generationPuppeteer
HTTP clientAxios
Timezone handlingmoment-timezone
LoggingWinston (via codi-node-utils)
Securityhelmet, express-rate-limit
TypeScriptstrict: 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

ThingConventionExample
Fileskebab-case.<layer>.tsauth.controller.ts, user-payment.service.ts
Factory functionsuse<Domain><Layer>()useAuthController(), useUserRepo()
InterfacesI prefixIUser, IBooking
Type aliasesT prefixTUserCreate, TBookingStatus
EnumsPascalCaseUserType, BookingStatus
Enum valuesSCREAMING_SNAKE_CASEUserType.BRANCH_MANAGER
Config exportsSCREAMING_SNAKE_CASEMONGO_URI, ACCESS_TOKEN_SECRET
Resource constantconst resource = 'auth.controller'Used in log calls
CollectionsCollectionName enumCollectionName.USERS