Appendix — Data Flows
CEO Summary
Data flows trace user actions from UI to database and back. Top-to-bottom: User clicks → API → service → DB. Bottom-to-top: DB row → service → API → component → user. Essential for debugging and onboarding.
POS Sale — Top-to-Bottom (User Clicks Pay)
- User — Clicks Finalize in ModernPOS
- Component — ModernPOS.jsx → finalize handler
- API —
posApi.finalize/client.post('/api/pos/carts/123/finalize')withIdempotency-Key+ PPO headers when usingposApi - Middleware — tenantResolver → requireSessionAuth → posRouter
- Route — POST /api/pos/carts/:id/finalize handler
- Service — CoreInvoicingService.createPOSSaleInvoice
- DB — INSERT Invoices, InvoiceLineItems; UPDATE pos_carts status=paid
POS Sale — Bottom-to-Top (DB Row to User)
- Bottom: pos_carts row updated with items, payments, status: paid
- Service: CoreInvoicingService.createPOSSaleInvoice inserts Invoices, InvoiceLineItems
- Route: POST /api/pos/carts/:id/finalize handler
- Middleware: tenantResolver → requireSessionAuth → posRouter
- API: Frontend client.post('/api/pos/carts/123/finalize')
- Component: ModernPOS.jsx → finalize handler
- Top: User sees receipt, cart cleared
Login — Top-to-Bottom
- User — Submits email + password
- Component — LoginForm / RegisterLoginScreen
- API — POST /api/auth/login
- Route — auth.routes.js
- DB — Master Users, tenant Employees
- Session — createUserSession(req, { user, tenant })
- Response — { success, user, tenant } → redirect
Kitchen tickets — POS finalize / send-to-kitchen → KDS poll
Chapter: 09 — KDS & Kitchen. Admin configures category-to-station rules at /admin/kitchen-displays (GET/PATCH /api/admin/kds/*).
Signage — Admin save → bridge → local refresh (optional)
Chapter: 26 — Signage & Displays. If the bridge is offline, the push is skipped; cloud data is still consistent.
Signup — Top-to-Bottom
Operations note: Set DISABLE_PUBLIC_SIGNUP to block new signups and provisioning (403 on POST /api/public/signup; SPAs read GET /api/public/signup-status). See 01 — Infrastructure.
- User — Fills signup form (company, email, plan)
- Component — Dashboard or public-site
/signup(or HTML fallbackGET /api/public/signup-form) - API —
POST /api/public/signup(JSON); optional?redirect=1for form POST redirect flow - Route —
public.signup.routes.js - Service —
provisionTenant(create tenant main, analytics, HR DBs; owner user; routing) - DB — Master Tenants, Organizations, Users; new tenant databases from templates
- Response — JSON 201 or redirect to
/signup/success
Modern POS — device settings and vertical modules
After register login, Modern POS loads device context so optional modules (e.g. fuel) can render. Module IDs and forecourt JSON are read from the device row via GET /api/pos/settings (not invented client-side).
Admin configuration: 13 — Bridge & Devices (device registry, metadata). Chapter: 06 — POS & Invoicing.
Modern POS — register status, PIN session, and sale gate
After platform login, Modern POS loads GET /api/pos/register/status with device_key and (from PIN session) staff_id. The UI sets canTransactOnRegister when the open shift is owned by the session user or the PIN staff matches shift.staffMemberId / shift.staff.id. blockIfRegisterNotReadyForSale uses that flag. If a saved cart exists but the first status response looks closed, the client may retry status briefly before prompting opening float. PIN + cart ids persist in localStorage (pos_pin_session_v1:*, pos_active_cart_v1:*) via posLocalPersistence.js.
Markdown: Appendix B — Register and shift before cart.
POS mutation — online vs queued (same idempotency)
Applies to cart item/tender/customer/finalize and similar POST/DELETE under /api/pos/carts/... when using posApi or tryOnlineThenQueue.
Key Files for Tracing
- POS: ModernPOS.jsx, lib/posLocalPersistence.js, pos-register.routes.js, pos/modules/PosModuleHost.jsx, FuelModulePanel.jsx, admin/devices/FuelSiteFormSection.jsx, DeviceManager.jsx, StandardPOS.jsx, Kiosk.jsx, Storefront.jsx, pos/api.js, lib/offline/*, backend/middleware/idempotency.js, pos.routes.js (
GET /settings, carts), backend/utils/posModules.js, backend/utils/fuelSite.js, coreInvoicing.service.js - KDS: 09 —
KitchenDisplay.jsx,kds.routes.js,admin.kds.routes.js,kdsOps.service.js,kdsKitchenRouting.js - Auth: frontend AuthProvider, backend/routes/auth.routes.js, backend/middleware/sessionAuth.js, backend/middleware/tenantResolver.js
- Signup: public-site signup, backend/routes/public.signup.routes.js, tenant provisioning
- Signage: 26 — frontend
SignageAdsCatalog.jsx,SignagePlayer.jsx; backendsignage.routes.js,bridge.routes.js(notify-signage)