Tay Za
Tay Za
Back to Garden

MenuGo

2026-08-25
projectdocumentation

MenuGo: Technical & Architectural Documentation

Welcome to the comprehensive technical documentation for MenuGo, a production-ready, multi-tenant, mobile-first QR-code dining and ordering SaaS platform engineered specifically for Myanmar's Food & Beverage (F&B) sector.


๐Ÿ“ 1. System Overview & Architecture (Production Complete)

MenuGo is engineered as a high-performance, modular TypeScript monorepo managed via pnpm workspaces. It provides an end-to-end dining platform supporting zero-friction customer mobile ordering, real-time Kitchen Display System (KDS) with sound alerts, waiter table settlement with POS thermal receipts and consolidated bill hubs, business analytics dashboards with interactive visualizations, multi-tenant platform super-administration, and hardened production operations.

                              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                              โ”‚            Landing / Mark                               โ”‚                   [Port 5172]                   โ”‚
                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                        โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ–ผ                                                                                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       Customer Mobile Web       โ”‚                                                 โ”‚         Staff Web (KDS)         โ”‚
โ”‚  (React 19 + Cart + Bill Hub)   โ”‚                                                 โ”‚  (React 19 + Recharts + Portals)โ”‚
โ”‚           [Port 5173]           โ”‚                                                 โ”‚           [Port 5174]           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                 โ”‚ Scan QR / REST API                                                                โ”‚ JWT / SSE / REST API
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                        โ”‚
                                                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                   Fastify v4 REST API Service (Node v20 LTS)                                โ”‚
โ”‚                                                   [Port 3000]                                               โ”‚
โ”‚                                                                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Public / Customer APIs โ”‚ โ”‚   Staff Dashboard APIs โ”‚ โ”‚  Platform Super Admin  โ”‚ โ”‚ Realtime SSE Streams โ”‚  โ”‚
โ”‚  โ”‚ (Session Auth JWT)     โ”‚ โ”‚   (Staff JWT + RBAC)   โ”‚ โ”‚  (Super Admin JWT)     โ”‚ โ”‚ (/orders/stream)     โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Business Services & Domain Engines Layer                                                              โ”‚  โ”‚
โ”‚  โ”‚ โ”œโ”€ OrderService                 โ”œโ”€ TableSettlementService            โ”œโ”€ AdminAuditService             โ”‚  โ”‚
โ”‚  โ”‚ โ”œโ”€ OrderLifecycleService        โ”œโ”€ OperationalMetricsService         โ”œโ”€ Knayi Zawgyi Converter        โ”‚  โ”‚
โ”‚  โ”‚ โ””โ”€ StorageService               โ””โ”€ HMAC-SHA256 QR Security Engine    โ””โ”€ REST Controllers & SSE Stream โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Production Security & Observability Layer                                                             โ”‚  โ”‚
โ”‚  โ”‚ โ”œโ”€ Correlation IDs (x-correlation-id)           โ”œโ”€ Health & Ready Probes (/healthz, /readyz)          โ”‚  โ”‚
โ”‚  โ”‚ โ”œโ”€ Strict Production Secret Validation          โ””โ”€ Multi-Tenant Row-Level Security (withTenant tx)    โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                       โ”‚ Tenant-isolated Transactions
                                                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                     PostgreSQL 16 Database + Drizzle ORM                                    โ”‚
โ”‚                                                                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ PostgreSQL Native Row-Level Security (RLS) & Tenant Foreign Keys + Admin Audit Logging                โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ 2. Workspaces & Technology Stack

Monorepo Workspace Structure

.
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ backend/            # Fastify v4 REST API service (Port 3000)
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ modules/    # API Route modules (public, staff, admin, events, health, auth)
โ”‚   โ”‚       โ”œโ”€โ”€ services/   # Business services (Order, KDS, Settlement, Analytics, Audit, Storage)
โ”‚   โ”‚       โ”œโ”€โ”€ plugins/    # Error handler & Correlation ID middleware
โ”‚   โ”‚       โ””โ”€โ”€ utils/      # Cryptographic HMAC & Security utilities
โ”‚   โ”œโ”€โ”€ customer-web/       # Mobile React 19 customer menu client (Port 5173)
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ components/ # MenuCards, ModifierModal, CartDrawer, OrderTracker, BillHub
โ”‚   โ”‚       โ”œโ”€โ”€ context/    # CartContext, LanguageContext, CustomerSessionContext
โ”‚   โ”‚       โ””โ”€โ”€ pages/      # MenuPage, OrdersHubPage
โ”‚   โ”œโ”€โ”€ landing-web/        # Public showcase & Super Admin portal (Port 5172: / and /admin)
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ components/ # Hero, FeatureGrid, InteractiveDemo, Pricing, Footer
โ”‚   โ”‚       โ””โ”€โ”€ pages/      # HomePage, PricingPage, SimulatorPage, FaqPage, admin/SuperAdminPage
โ”‚   โ””โ”€โ”€ staff-web/          # Staff & Kitchen Dashboard client (Port 5174)
โ”‚       โ””โ”€โ”€ src/
โ”‚           โ”œโ”€โ”€ components/ # KDSQueue, TableSettlementModal, DailyAnalytics (Recharts), QRModal (Portal)
โ”‚           โ”œโ”€โ”€ context/    # StaffAuthContext, LanguageContext, SoundAlertContext
โ”‚           โ””โ”€โ”€ pages/      # OrdersPage, MenuPage, TablesPage, AnalyticsPage, StaffPage, SettingsPage, LoginPage
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ db/                 # PostgreSQL 16 schema (19 tables), Drizzle ORM migrations, seeds, RLS helpers & backup scripts
โ”‚   โ””โ”€โ”€ shared/             # Monorepo TypeScript interfaces, DTOs, Enums, & Contract schemas
โ”œโ”€โ”€ docs/                   # Architecture, API, Authentication, and Database specifications
โ”œโ”€โ”€ PRODUCTION_OPERATIONS.md# Production deployment, backup & operations manual
โ”œโ”€โ”€ documentation.md        # Full master technical documentation (this file)
โ””โ”€โ”€ system usage guide.md   # End-user manual (Customers, Staff, Owners, Super Admins)

Technology Matrix

| Layer | Component | Description | | :-------------------------- | :---------------------------------------- | :--------------------------------------------------------------------------- | | Monorepo Manager | pnpm v9 | Workspace dependency isolation & cross-package pipeline execution | | Runtime Engine | Node.js v20 LTS | Modern ES Module asynchronous runtime | | Backend Framework | Fastify v4 + TypeScript | High-throughput, low-overhead REST API framework | | Frontend Frameworks | React 19 + Vite 5 | Fast, modern reactive single-page client applications | | Styling & Design System | Tailwind CSS v4 | Next-gen CSS styling engine with utility tokens and responsive layouts | | State & Query Layer | TanStack React Query v5 + React Context | Async server state synchronization, optimistic caching, and local cart state | | Database & ORM | PostgreSQL 16 + Drizzle ORM | Type-safe DDL, schema migrations, and high-performance SQL query generation | | Security Layer | PostgreSQL Native RLS + HMAC-SHA256 | Engine-level multi-tenant data isolation & signed QR token verification | | Burmese Text Normalizer | knayi | Server-side automated Zawgyi-to-Unicode font encoding normalizer | | Data Visualizations | recharts v3 | Interactive revenue charts, sales breakdowns, and analytics graphs | | Realtime Engine | Server-Sent Events (SSE) + REST Re-sync | Resilient live order event streaming with automatic cellular catch-up | | Modal Architecture | React Portals (createPortal) | Accessible, viewport-centered dialogs and floating overlays | | Authentication | jsonwebtoken + bcryptjs | Role-Based Access Control (RBAC) JWTs & Customer Table Session JWTs |


๐Ÿ” 3. Security, Multi-Tenancy & Production Hardening

Multi-Tenant Isolation via PostgreSQL Row-Level Security (RLS)

  1. Native PostgreSQL RLS: Every tenant-scoped table enables native RLS (ENABLE ROW LEVEL SECURITY and FORCE ROW LEVEL SECURITY).
  2. Transaction-Scoped Tenant Context (withTenant): All database operations execute inside transaction wrappers injecting the session context:
    await withTenant(tenantId, async (tx) => {
      // Queries executed here are strictly constrained by PostgreSQL RLS
      return await tx.select().from(orders).where(...);
    });
    
  3. Cross-Tenant Guard Rails: Pre-handler route guards execute verifyResourceTenantOwnership to reject any cross-tenant tampering attempts with 403 CROSS_TENANT_FORBIDDEN.

HMAC-SHA256 QR Token Cryptographic Architecture

  • Tamper-Proof Signature: QR codes contain no plain IDs or raw credentials. They carry a cryptographic signature: Signature = HMAC-SHA256(tenantId + ":" + tableId + ":" + tokenVersion + ":" + secretToken, APP_SECRET)
  • One-Click Instant Revocation: Tenant Admins can regenerate table QR tokens at any time. This atomically increments tokenVersion and generates a new secret, immediately revoking all previously printed physical QR codes.
  • Timing-Safe Verification: Validation uses crypto.timingSafeEqual to prevent side-channel timing attacks.

Production Hardening & Observability

  • Strict Environment Validation: In NODE_ENV=production, the server halts immediately if JWT_SECRET or APP_SECRET use default dev keys or are shorter than 32 characters.
  • Diagnostic Correlation IDs: Every inbound request receives a unique x-correlation-id header attached to both success and error responses for distributed tracing.
  • Health & Readiness Endpoints:
    • GET /healthz: Liveness probe verifying process uptime and memory health.
    • GET /readyz: Readiness probe testing active PostgreSQL database connectivity (SELECT 1).
  • Comprehensive Rate Limiting: Built-in IP rate limiting protects verification endpoints (max 20 req/min) and order placement endpoints (max 15 req/min per session).

๐Ÿงฉ 4. Business Services & Domain Engines

MenuGo decouples core domain logic into robust business services in apps/backend/src/services/:

1. OrderService (order.service.ts)

  • Idempotency Safeguard: Accepts X-Idempotency-Key headers to eliminate duplicate charges on flaky cellular mobile connections.
  • Financial Calculation Engine: Computes exact item subtotals, modifier prices (+MMK), tax amounts, discounts, and net totals.
  • Stock Availability Verification: Revalidates stock availability (is_available = true) and active category status in real time before accepting orders.

2. OrderLifecycleService (order-lifecycle.service.ts)

  • KDS State Machine: Governs strict state transitions: PENDING โ†’ ACCEPTED โ†’ PREPARING โ†’ READY โ†’ DELIVERED โ†’ CLOSED / CANCELLED
  • Immutable Audit History: Writes every fulfillment and payment status change to order_status_history with the changing user ID and timestamp.
  • Automatic Session Invalidation: Inactivates table_sessions when all active orders for a table reach CLOSED or CANCELLED.

3. TableSettlementService (table-settlement.service.ts)

  • Consolidated Bill Hub: Aggregates all open, unclosed orders for a table into a unified bill statement.
  • Multi-Method Payment Settlement: Supports recording of CASH, KBZ_PAY, WAVE_PAY, and OTHER, transitioning payment status from UNPAID to PAID.
  • Offline Payment Record-Keeping (Important): MenuGo does not integrate payment gateways. KBZ_PAY / WAVE_PAY / OTHER are record-keeping labels only โ€” the customer pays the waiter directly (cash transfer or in-app wallet transfer), and staff record which channel was used on the settlement receipt. No funds flow through MenuGo.
  • Change Calculation & Thermal Printing: Computes cash change and generates formatted ESC/POS-compatible thermal receipt payloads for 80mm/58mm POS receipt printers.

4. OperationalMetricsService (operational-metrics.service.ts)

  • Analytics & Reporting: Aggregates daily net revenue (MMK), total order volume, average fulfillment duration, hourly sales distributions, and top-selling menu items.

5. AdminAuditService (admin-audit.service.ts)

  • Security Audit Logging: Captures all platform administrative operations (tenant creation, user suspension, role changes) into admin_audit_logs.

6. StorageService (storage.service.ts)

  • Isolated Asset Management: Handles tenant-isolated image uploads (/uploads/:tenantId/) with strict MIME type and file size validation (max 5 MB).

๐Ÿ—„๏ธ 5. Database Schema & Data Models

Entity Relationship Matrix (PostgreSQL 16 โ€” 19 Production Tables)

| Table Name | Primary Key | Description | | :---------------------- | :------------------ | :---------------------------------------------------------------------------------------------- | | organizations | id (UUID) | Tenant organization records (English/Burmese names, unique slug, active status). | | users | id (UUID) | User accounts with bcrypt hashed passwords and is_super_admin flag. | | roles | id (VARCHAR) | Role-Based Access Control IDs (ADMIN, KITCHEN, WAITER). | | memberships | id (UUID) | Maps users to tenant organizations with assigned roles. | | restaurant_settings | tenant_id (UUID) | Currency configs (MMK), logos, banners, opening notes, sound alert configs. | | tables | id (UUID) | Dining tables with seating capacity, active flags, and soft deletion (deleted_at). | | qr_tokens | id (UUID) | Secret HMAC tokens & tokenVersion counter for tamper-proof QR verification. | | table_sessions | id (UUID) | Active dining sessions per table with 60-minute expiration timestamps. | | menu_categories | id (UUID) | Menu categories with display order indices and bilingual names (EN/MM). | | menu_items | id (UUID) | Menu items with prices in MMK, 86 availability toggles, display orders, and photos. | | item_option_groups | id (UUID) | Modifier groups with min/max selection bounds (e.g., Sugar Level, Choice of Meat). | | item_options | id (UUID) | Modifiers within a group with incremental price modifiers (+MMK). | | orders | id (UUID) | Dine-in orders with daily numbers, fulfillment/payment statuses, and idempotency keys. | | order_items | id (UUID) | Snapshot line items with unit price in MMK, quantity, and selected options JSON. | | order_status_history | id (UUID) | Immutable audit log capturing all lifecycle status transitions and user attribution. | | daily_order_counters | id (UUID) | Atomic daily sequence counters per tenant and calendar date to prevent order number collisions. | | admin_audit_logs | id (UUID) | Platform-wide audit logs tracking Super Admin actions and security events. | | table_settlements | id (UUID) | Receipt history, reconciled order counts, change due, and payment records. | | demo_bookings | id (UUID) | Inbound sales and onboarding lead bookings from the public landing website. |


๐Ÿ“ก 6. Complete API Specifications

Public / Customer Endpoints (/api/v1/pub/...)

| Method | Endpoint | Authentication | Description | | :----- | :--------------------------------- | :------------- | :------------------------------------------------------------------------- | | GET | /api/v1/pub/r/:slug/verify-table | HMAC Signature | Verifies table ID & HMAC token signature; issues 60-min tableSessionToken.| | GET | /api/v1/pub/r/:slug/menu | Public | Retrieves active categories, available menu items, and modifier options. | | POST | /api/v1/pub/r/:slug/orders | Table Session | Submits new dine-in order. Supports X-Idempotency-Key & Zawgyi notes. | | GET | /api/v1/pub/r/:slug/orders/:id | Table Session | Queries real-time fulfillment and payment status for an individual order. | | GET | /api/v1/pub/r/:slug/table/orders | Table Session | Retrieves active order history and consolidated bill summary for the table.|

Staff & Operations Endpoints (/api/v1/staff/...)

| Method | Endpoint | Permission | Description | | :-------------------- | :--------------------------------------------- | :------------------ | :--------------------------------------------------------------------------------------- | | POST | /api/v1/staff/auth/login | Public | Authenticates staff user and issues Bearer JWT token. | | GET | /api/v1/staff/orders | VIEW_ORDERS | Live KDS queue for kitchen cooks and waiters with filtering. | | PATCH | /api/v1/staff/orders/:id/status | UPDATE_ORDERS | Updates order fulfillment status (PENDING โž” READY โž” CLOSED). | | GET | /api/v1/staff/tables/:id/bill | VIEW_BILL | Aggregates active table bill total across unclosed orders. | | POST | /api/v1/staff/tables/:id/settle | UPDATE_ORDERS | Settles table bill, records payment method, returns POS receipt, & frees table session. | | GET | /api/v1/staff/analytics/daily | ADMIN | Fetches daily revenue, order counts, hourly distribution, & top dishes. | | PATCH | /api/v1/staff/menu-items/:id/availability | UPDATE_ITEM_STOCK | Instant 86/stock availability toggle for a menu item. | | GET | /api/v1/staff/tables | VIEW_TABLES | Lists all tables, active session statuses, and QR token versions. | | POST | /api/v1/staff/admin/tables | MANAGE_TABLES | Admin creates a new table and issues a fresh HMAC QR token. | | GET | /api/v1/staff/admin/tables/:id/qr | MANAGE_TABLES | Admin retrieves table QR token details and shareable link. | | POST | /api/v1/staff/admin/tables/:id/regenerate-qr | MANAGE_TABLES | Admin revokes and regenerates table QR code (increments tokenVersion). | | PATCH | /api/v1/staff/admin/tables/:id/status | MANAGE_TABLES | Activates or deactivates a table. | | GET/POST/PUT/DELETE | /api/v1/staff/categories | MANAGE_MENU | Category CRUD and display order management. | | GET/POST/PUT/DELETE | /api/v1/staff/menu-items | MANAGE_MENU | Menu item CRUD, modifier option groups, and photo uploads. | | GET/POST/DELETE | /api/v1/staff/admin/users | ADMIN | Staff account management and RBAC role assignment. |

Platform Super Admin Endpoints (/api/v1/admin/...)

| Method | Endpoint | Role | Description | | :------- | :----------------------------------- | :------------ | :------------------------------------------------------------------------ | | POST | /api/v1/admin/auth/login | Super Admin | Super Admin login endpoint. | | GET | /api/v1/admin/organizations | Super Admin | Lists all tenant organizations and active subscription states. | | POST | /api/v1/admin/organizations | Super Admin | Provisions a new restaurant tenant organization. | | PATCH | /api/v1/admin/organizations/:id | Super Admin | Updates tenant configuration or toggles active status. | | GET | /api/v1/admin/audit-logs | Super Admin | Inspects platform security audit logs. | | GET | /api/v1/admin/metrics | Super Admin | Aggregates platform-wide GMV, total tenant count, and order volumes. |


๐Ÿงช 7. Automated Testing & Verification Suite

MenuGo maintains automated test suites covering tenant isolation, dual-session authentication, QR security, menu stock toggling, KDS state machines, settlement calculations, platform admin operations, SSE streaming, and pilot E2E dining workflows. All tests feature automatic database artifact cleanup in afterAll hooks to prevent database pollution.

# Run full automated test suite across monorepo
pnpm test

# Run individual targeted test suites
pnpm test:auth        # Dual-session JWT & RBAC permission tests
pnpm test:qr          # Cryptographic HMAC QR signature & revocation tests
pnpm test:menu        # Menu CRUD, modifier options, & 86 stock toggle tests
pnpm test:order       # Order submission, idempotency, & financial calculation tests
pnpm test:kds         # Kitchen Display System queue & state machine tests
pnpm test:settlement  # Multi-order table bill aggregation & payment settlement tests
pnpm test:staff       # Staff management & access control tests
pnpm test:admin       # Platform Super Admin & audit logging tests
pnpm test:sse         # Realtime SSE event streaming tests
pnpm test:e2e         # End-to-end dining pilot simulation test

โšก 8. Monorepo Quality & Verification Commands

# Verify TypeScript strict type-checking across all 5 apps and 2 packages
pnpm typecheck

# Check code linting and style rules
pnpm lint

# Check code formatting compliance (Prettier)
pnpm format:check

# Build all production bundles
pnpm build