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)
- Native PostgreSQL RLS: Every tenant-scoped table enables native RLS (
ENABLE ROW LEVEL SECURITYandFORCE ROW LEVEL SECURITY). - 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(...); }); - Cross-Tenant Guard Rails: Pre-handler route guards execute
verifyResourceTenantOwnershipto reject any cross-tenant tampering attempts with403 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
tokenVersionand generates a new secret, immediately revoking all previously printed physical QR codes. - Timing-Safe Verification: Validation uses
crypto.timingSafeEqualto prevent side-channel timing attacks.
Production Hardening & Observability
- Strict Environment Validation: In
NODE_ENV=production, the server halts immediately ifJWT_SECRETorAPP_SECRETuse default dev keys or are shorter than 32 characters. - Diagnostic Correlation IDs: Every inbound request receives a unique
x-correlation-idheader 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-Keyheaders 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_historywith the changing user ID and timestamp. - Automatic Session Invalidation: Inactivates
table_sessionswhen all active orders for a table reachCLOSEDorCANCELLED.
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, andOTHER, transitioning payment status fromUNPAIDtoPAID. - Offline Payment Record-Keeping (Important): MenuGo does not integrate payment gateways.
KBZ_PAY/WAVE_PAY/OTHERare 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
