An offline-first order system for pizza food trucks
2026-11-25
A friend runs a pizza business with a few food trucks that move between villages. Customers phone in, pick a time, and collect their pizzas. Until now, all of it ran on a single HTML file open in a tablet browser.
It worked, but it had three problems. The kitchen could not read the text from the oven. The worker could not see whether a time slot was full. And sometimes the last pizza of an order could not be marked as done.
I built a replacement in a few days. Agents wrote all of the code, across more than 90 merged pull requests.
The old app
Someone with no technical background built the old app with the help of AI. It ran real services every night, but the UI was hard to use in a busy kitchen and the app did not scale: a price change meant editing the code, and all the data lived on one tablet.

It was a single HTML file of 1,500 lines. It loaded Tailwind from a CDN at runtime, kept the menu and prices in a hardcoded JavaScript array, and stored every order in localStorage on one tablet. The table compares it with the new system:
| Old HTML file | New system | |
|---|---|---|
| Change a price | Edit the code, copy the file to the tablet | Change it in the admin, every tablet gets it |
| A tablet breaks or is wiped | The night's orders and history are gone | A new tablet restores everything with a QR code |
| Several trucks | One file per tablet, no shared view | Per-location overrides, reports across locations |
| Takings and reports | A sales history stuck in one browser | Rankings, takings per night, charts, CSV |
| Busy slots | You count by hand | 10 pizzas per slot, the timeline shows what is left |
| Add a feature | Read 1,500 lines and hope | Small modules, domain rules with tests, CI on every PR |
| Bad internet | Tailwind CDN must load first | Installable PWA, works offline, syncs later |
Maintenance, evolvability and usability depend on decisions about where the data lives, who writes each record, what happens when the network drops, and how a price change reaches the tablets. I made those decisions, and agents wrote the code.
What it is
The new system has two apps and one server:
- OMS (order management system): the tablet app the workers use during service. It includes the kitchen board, the orders list, a stock summary and a "new order" flow with a slot timeline.
- Admin: a desktop app for the owner. Menu, prices, stock counters, per-location overrides, service settings and reports with charts and CSV export.
- One Cloudflare Worker: it serves both apps and the API.
The business rules are simple. A 15-minute slot takes up to 10 pizzas. When a slot does not have enough space, the app proposes a split: it fills the free places in the requested slot first and puts the rest in the previous slot — never a later one, so the customer still collects at the promised time. The tablet counts the dough balls that are left, and each order is paid in cash or by card. The UI is in Catalan.
Two people use the same tablet at the same time: one makes the pizzas and takes the phone orders, the other runs the oven and hands the orders over. So the kitchen board has one column per role, where pizzas are ticked as they go into and come out of the oven. Each screen shows only what that person needs during a busy night.

When taking a phone order, the worker picks from the menu against the 15-minute slot timeline while keeping the cook column visible on the right.

Offline first
The trucks park in villages with bad coverage, so the tablet must keep working without a connection.
The tablet is the source of truth for the night:
- It keeps the same rows as the server in IndexedDB, one store per table.
- Every action is one local transaction that also writes an outbox entry.
- IDs are UUIDs made on the tablet, so nothing waits for the server.
- A sync loop pushes 2 seconds after a change, when the tablet comes back online, and every 60 seconds, with backoff on errors.
- The server upserts a row only when
incoming.rev > stored.rev. An old retry can never overwrite newer data.
There are no CRDTs. Each truck runs one tablet, and each record type has one writer — the tablet owns its night's orders and stock counts, while the admin owns the menu, prices and settings — so there are no merge conflicts to resolve. When the connection drops, work carries on and the header counts the changes waiting to sync.

The Worker sits behind both apps: tablets authenticate with a per-location key, the admin goes through Cloudflare Access, and all synced data lives in D1.
The app is an installable PWA (vite-plugin-pwa + Workbox). A new version never reloads in the middle of a service. It waits until the service is closed, or until the worker taps "Update". A new tablet restores everything from the server with one call, and a round-trip test runs a full night on one tablet, restores it on a second one and compares every row.
Admin
The owner manages products, prices, stock counters and display order from the admin app, and changes sync down to the tablets.

When the tablets sync back, the admin shows the pizzas sold, takings by cash and card, VAT, the average ticket, takings per night, week or month, the peak hour and the best sellers. The charts below use demo data.

Stack
| Part | Tool |
|---|---|
| UI | React, Vite, TypeScript |
| Styles and components | Tailwind CSS, shadcn/ui, Radix, Lucide |
| Extras | TanStack Router, dnd-kit, Recharts, Sonner |
| Offline | IndexedDB (idb), Workbox |
| API | Cloudflare Workers, Hono, Zod |
| Database | Cloudflare D1, Drizzle ORM |
| Auth | Cloudflare Access (Zero Trust) |
| Quality | Vitest, Biome, GitHub Actions |
Every PR runs typecheck, Biome and Vitest. A merge to development applies the D1 migrations and deploys to staging, and a merge to main does the same for production. A change goes to production only after it works on staging. Migrations only add tables or columns, so if a step fails, the running version keeps working.
Cloudflare free tiers. The Worker, the D1 database (with point-in-time restore) and Zero Trust in front of the admin all run on free plans, so hosting costs nothing for a small business with a few tablets. With Zero Trust, the admin has no login screen and no password table. Cloudflare Access checks the owner's email before the request reaches my code. The tablets use a per-location key that you set up by scanning a QR code.
Open source. Tailwind and shadcn/ui give a consistent UI with components I own and can edit. Hono, Drizzle, Zod, Vitest, Biome, Workbox and Recharts do most of the rest. Thanks to the people who maintain them.
Live docs
The docs live in the repository and change in the same commit as the code, because the agents follow a short AGENTS.md:
- Read
HANDOVER.mdfirst. It holds the current state, the decisions and the next steps. Replace old content, never append a log. - Keep the PRD in English and Catalan in step, in the same commit.
- Work in the slice order of the roadmap. A slice is done when its acceptance criteria pass and its demo works.
- When a slice changes status, update the roadmap and the visual roadmap board.
- When the data model changes, update the ER diagram.
Alongside the markdown docs, the repository holds standalone HTML pages: a roadmap board with every slice and its dependencies, an ER diagram of the 18 tables, a clickable prototype of the tablet app, and a user guide in Catalan for the workers and the owner. Updating them is part of the definition of done, so they always match the code.
The ER diagram updates with every database migration so the schema view never drifts from D1.
| Artifact | Updated when |
|---|---|
HANDOVER.md | any change to state, decisions or next steps |
| Roadmap + board | a slice changes status |
| PRD (EN + CA) | scope or acceptance criteria change |
| ER diagram | a migration adds a table or column |
| Prototype | the tablet flow changes (with a smoke test) |
In production
The system has been running live services in production for a few weeks now, replacing the old HTML file. Small tweaks from real nights — layout density on the tablet, order totals on the oven cards, the slot-splitting behavior — went through the same staging-then-production loop and shipped without interrupting service.




