03Case study
Mobile ordering system
From QR ordering to the kitchen pass to admin reports: the full flow for a restaurant.
- 3role-specific interfaces
- 11Prisma data models
- 16API routes
- 4Vitest test suites
The problem
Ordering in a small restaurant involves three groups at once: customers want to order from their table and see progress, the kitchen needs new orders immediately, and the owner manages menus, tables and staff permissions while watching the numbers. All three look at the same data, so totals and statuses must agree and no side should be able to tamper with them.
Features
Customers
Scan the table's QR code (or type the table number if the camera is unavailable), browse the menu, pick options, check out, and watch "My orders" update on its own.
Kitchen
A live board that polls every 5 seconds, lists orders by status and moves them along.
Admin
Categories, products, option groups, tables and users, plus an operations dashboard and report charts.
Architecture
Key design decisions
Only the server sets prices
Orders are priced from product and option prices read from the database at creation time; totals sent by the client are ignored, and products must belong to the store and be on sale.
Option rules enforced on the back end
Each option group has min/max selections and a required flag; violations return structured errors with codes such as OPTION_RULE_VIOLATION.
An order state machine
NEW → PREPARING → COMPLETED, cancellable before completion; COMPLETED and CANCELLED are terminal and illegal transitions are rejected.
RBAC
7 permissions and 3 preset roles: ADMIN has everything; MANAGER runs menu, tables, orders and reports; STAFF handles orders only.
A reproducible environment
Docker Compose waits for a healthy database, then runs generate → migrate deploy → seed → start; the seed rebuilds demo data and is safe to re-run.
Tested on real phones
An Nginx reverse proxy lets phones on the same Wi-Fi connect directly and walk through the QR ordering flow.
Quality
TypeScript type checks, ESLint, and four Vitest + Testing Library suites covering the auth guard, order service, orders API and report service.