# Reflex — delivery coordination for Kenyan retailers
Real-time delivery coordination that replaces the WhatsApp/phone-call chaos: a retailer logs a
delivery, a dispatcher assigns a rider, the rider updates status and confirms handover by
**scanning a QR code** (with manual code fallback), and every screen in the loop updates the
second it happens. Every status change is written to an append-only `status_events` audit trail.
## Stack
| Layer | Tech |
|----------|------|
| Backend | Node.js + Express (REST) |
| Database | PostgreSQL |
| Realtime | Socket.io (WebSockets) |
| Frontend | Plain HTML/JS — hand-rolled DOM, `fetch` + Socket.io client, **no frontend framework**¹ |
| QR | `qrcode` (render) + `jsqr` (camera decode) |
¹ The sandbox preview build requires a Vite/React entry file, so `src/App.tsx` exists as a
12-line mount shim that immediately hands over to the vanilla app in `src/fe/`. All UI logic is
framework-free DOM code. When you run the real stack locally, Express serves the built frontend
and the exact same vanilla code talks to the real API.
## Two ways to run it
### A. Instant demo (no Postgres needed)
Open the built site (or `npm run dev`). The frontend probes `GET /api/health`; when no server is
present it switches to a faithful **in-browser emulation** (`src/fe/mock.ts`) of the identical
REST + event contract — localStorage as the shared database, BroadcastChannel as the realtime
bus. Open **three browser tabs**, sign in with the three demo accounts, and run the full flow
live: request → assign → picked up → QR confirm (use manual entry across tabs) → every view
updates in real time, history queryable per request.
### B. Full local stack (Express + PostgreSQL + Socket.io)
```bash
# 1. database
createdb reflex
psql reflex -f server/migrations/001_init.sql
# 2. backend
cd server
cp .env.example .env # adjust DATABASE_URL / TOKEN_SECRET
npm install
npm run seed # demo users (PIN 1234) + sample deliveries
np …