API & Data Model

One Service, Nine Domains, Four Clients

Section 3 of 4

All four front ends talk to a single Express service over MongoDB. It is deliberately small relative to what sits on top of it — under two thousand lines — because almost all of the complexity in this platform lives in the operational screens rather than in the transport between them.

What it does well is consistency. Every domain follows the same shape, so adding one is mechanical rather than a design exercise. What it does poorly is authorization, and this section describes the model as built; the Retrospective takes it apart properly.

9

domain routers under one mount point

2

files per domain — routes and handlers

1

tenant key, carried in the URL

~1.9K

lines of API code

Request Path

Every request descends the same four layers. The split between a router that only declares paths and a handler module that holds the logic is applied without exception across all nine domains.

Clientcustomer PWA, waiter terminal, back-office or operator consoleSingle versioned mount pointone service, one prefix, CORS-restricted originDomain Routerpaths only — no logic, typically under ten linesHandler Modulerequest parsing, business logic, response shapingMongoose Model → MongoDBschema definition and persistenceTenant scopingthe owning account emailtravels in the URL path andis matched directly in thequery filtersee Retrospective

Design Decisions

Each of the nine domains — authentication, users, customers, menu, categories, banners, coupons, orders and QR codes — is implemented as exactly two files. A router file that declares its paths and maps each to a named handler, and a handler module that exports those handlers.

The router files are tiny, often under ten lines, and that is the point. Opening one tells you the entire surface area of that domain at a glance: four operations on QR codes, four on orders, and so on. The logic lives next door where it cannot obscure the shape of the API.

Applied consistently across nine domains, this is what keeps a codebase this broad navigable. Knowing where a given behaviour lives requires no search — the domain name gives you the directory and the convention gives you the file.