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

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

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
Resource constantconst resource = 'auth.controller'Used in log calls
CollectionsCollectionName enumCollectionName.USERS