← back to writing

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.

the old app: one HTML page with order cards, big buttons and a dough counter with an "error" button

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 fileNew system
Change a priceEdit the code, copy the file to the tabletChange it in the admin, every tablet gets it
A tablet breaks or is wipedThe night's orders and history are goneA new tablet restores everything with a QR code
Several trucksOne file per tablet, no shared viewPer-location overrides, reports across locations
Takings and reportsA sales history stuck in one browserRankings, takings per night, charts, CSV
Busy slotsYou count by hand10 pizzas per slot, the timeline shows what is left
Add a featureRead 1,500 lines and hopeSmall modules, domain rules with tests, CI on every PR
Bad internetTailwind CDN must load firstInstallable 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:

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.

the kitchen board on the tablet: the oven column on the left, the cook column on the right, pizzas ticked as they go in and come out of the oven

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.

the new order screen: menu, the order, the slot timeline with free places per 15 minutes and the cook column 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:

sequence diagram: saving an order writes to IndexedDB and the outbox first, then the outbox is pushed to the Worker and D1 when there is a connection

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 tablet with no connection: work goes 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.

system diagram: the tablet OMS talks to the Worker with a location key, the admin goes through Cloudflare Access, the Worker stores everything 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.

the admin menu editor: products, prices, stock counters and drag to reorder

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.

the admin reports: totals, takings per night split by cash and card, and pizzas per 15-minute slot

Stack

PartTool
UIReact, Vite, TypeScript
Styles and componentsTailwind CSS, shadcn/ui, Radix, Lucide
ExtrasTanStack Router, dnd-kit, Recharts, Sonner
OfflineIndexedDB (idb), Workbox
APICloudflare Workers, Hono, Zod
DatabaseCloudflare D1, Drizzle ORM
AuthCloudflare Access (Zero Trust)
QualityVitest, 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.

delivery flow: checks on every PR, a merge to development deploys staging, a merge to main deploys production

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:

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 roadmap board: 14 slices and their dependencies, 13 done

The ER diagram updates with every database migration so the schema view never drifts from D1.

the ER diagram of the data model, kept in step with every migration

ArtifactUpdated when
HANDOVER.mdany change to state, decisions or next steps
Roadmap + boarda slice changes status
PRD (EN + CA)scope or acceptance criteria change
ER diagrama migration adds a table or column
Prototypethe 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.