From the counter to the kitchen, without shouting.
The bar sends, the tablet chimes, one tap and it's served. On Cloudflare, within the free plan.
In a bar that serves food, orders travel from the counter to the kitchen by shouting over the coffee machine. ChefLink replaces the shouting: the server builds the order, the kitchen gets it in real time with a chime, and clears the card with one tap when it's ready.
Two modes on the same account β and the mode belongs to the device, not the person. The counter station stays in bar mode, the kitchen tablet in kitchen mode, and either can switch with one click.
The interface comes in French, English, Spanish and Portuguese, French by default because that is the language of the team using it. Everything below β and every comment in the code β explains the decisions, not just the mechanics.
- π Real time, with a chime β the order lands in the kitchen without a reload, and the tablet rings
- π One tap means ready β the whole card is the button, and the update is optimistic
- π’ Orders are numbered, not seated β the counter sends, the kitchen calls out "#14". The counter restarts every service, which turns at five in the morning rather than at midnight
- π¨ A colour per dish β chosen on the dishes page from sixteen house colours or picked freely with the browser's own colour picker, shown down the side of the dish on the counter screen and as a dot on every line of the kitchen card, so two dishes of the same section are told apart on sight
- π Menu editable mid-service β create, edit, delete a dish or a category, or mark a dish unavailable without removing it
- π Order history as a table β a 24 h / 7 day / 30 day window, filterable by status, searchable by number or dish, sortable on when it was sent, when it closed and how long the kitchen took
- β©οΈ Cancel an order β the table left, or it was never meant to be sent: the bar takes it back and the kitchen card disappears at once
- π Free-form note per order β "no onions, allergy", highlighted in the kitchen
- β±οΈ Waiting badge β the card changes colour at 8 then 15 minutes
- π Session authentication β PBKDF2 through WebCrypto,
httpOnlycookie - π± Built for a tablet β large targets, single column in portrait
- π Light or dark, remembered per device, applied before the first paint
- π Four languages β French, English, Spanish and Portuguese, chosen per device and resolved server-side, so the first HTML is already in the right language
- βοΈ Cloudflare end to end β Workers, D1, a Durable Object, free plan
- β 53 tests on the business rules, the colour palette, what it renders as and the message catalogues, with no database and no browser
![]() |
![]() |
| Order taking β menu, basket, note | History β windows, search, sorting |
![]() |
![]() |
| Dishes β the menu, editable mid-service | Editing β name, category, availability |
The screenshots were taken before orders stopped carrying a table label: where they show a "Table" field, the application now shows the order's number. Nothing else about the layout has moved.
![]() |
![]() |
| Dark β the default | Light β one tap away |
Same screen, one tap apart. The note carries the allergy, so it gets a tone of its own in each theme rather than one amber that only works against a dark background.
French, English, Spanish and Portuguese, through Paraglide JS β the library TanStack Router's own i18n guide builds its examples on. TanStack ships no i18n package of its own.
The copy lives in one file per language β messages/fr.json, en.json,
es.json and pt.json β and is compiled into src/paraglide: each
message becomes a function, so a page only ships the messages it uses, and a
typo in a message name is a type error rather than a blank on a screen.
![]() |
![]() |
| English | French |
The same screen, one choice apart β the language menu in the header, which shows the current language and lists every other one in its own words. The order note is not translated and should not be: it is what the server typed.
Three decisions worth the words:
The language is a cookie, not localStorage. The theme and the bar/kitchen
mode live in localStorage and are corrected after the server has rendered β
for a colour that costs nothing, and an inline script hides it. Text cannot be
corrected that way: the page would arrive in French and visibly switch. A cookie
is readable by the server, so the first HTML is already in the right language.
The locale never appears in the URL. The screens sit behind a login on fixed
tablets: there is nothing to index and nothing to share, so /fr/cuisine would
only add another thing to keep in sync β starting with /api/ws, which must not
be localized. Resolution order is cookie β Accept-Language β French.
Some French stays in the code, on purpose. en_attente, terminee and
annulee are in D1; clair and sombre are in the browsers of devices already in service.
Renaming them would need a migration for the first and would silently reset
everyone's choice for the second. They are stored values, not copy β the labels
on top of them are translated.
messages/*.json |
the copy, one file per language |
i18n.config.ts |
compiler options, shared by Vite and npm run typecheck |
src/server.ts |
resolves the locale for the request, before anything renders |
src/lib/locale.ts |
language names and the date formats that follow them |
Plurals go through CLDR rather than a parenthesised (s): French counts 0 as
singular ("0 commande"), English does not ("0 orders"). Dates follow suit β
English here means British English, because 05/10 should not mean October in one
language and May in the other on the same screen, and Spanish and Portuguese
are tagged es-ES and pt-PT for the same reason: day first, everywhere.
npm install
npm run build # builds the Worker
npm run db:migrate # migrations against the local D1
npm run db:seed # one account and a menu of six dishes
npm run preview # wrangler dev: the real Cloudflare runtime, locallyβ http://localhost:3000 Β· bar@exemple.fr / motdepasse
Change those credentials with SEED_EMAIL and SEED_PASSWORD before running
db:seed.
npm run dev |
npm run preview |
|
|---|---|---|
| Hot reload | β | β |
| D1 | β | β |
| Real time | β | β |
Nitro does not publish exports.cloudflare.ts in its dev server, so the Durable
Object does not exist under vite dev. The app keeps working β screens catch up
on the safety-net refetch β and the server says so in the console rather than
going quietly silent. To work on anything real-time, use preview.
Every push to main deploys itself β see
.github/workflows/deploy.yml. The workflow
type-checks, tests and builds, then applies the D1 migrations and ships the
Worker. A pull request runs the same checks and stops there, so nothing reaches
production without clearing the same bar.
Migrations run before the Worker goes live: new code may need a column the old code ignored, whereas old code survives an extra column just fine. The corollary is worth remembering β a destructive migration (a dropped or renamed column) would break the version still serving traffic for a few seconds, so that kind of change takes two deploys, not one.
Two repository secrets are needed before the first push β Settings > Secrets and variables > Actions:
| Repository secret | What it is |
|---|---|
CLOUDFLARE_API_TOKEN |
a token with "Edit Workers" and "D1 Edit" |
CLOUDFLARE_ACCOUNT_ID |
your Cloudflare account id |
Without them the verify job still passes and deploy fails on the migration
step, which is the right way round: nothing ends up half-deployed.
Starting from a fresh account instead? Create the database, point
database_id in wrangler.jsonc at it, and lay down the starting data once β
the workflow deliberately never seeds production:
wrangler d1 create cheflink
npm run db:migrate:remote
npm run db:seed:remoteTo deploy from your machine instead: npm run deploy.
wrangler.jsonc declares the two bindings: DB (D1) and REALTIME (the
Realtime Durable Object, registered under new_sqlite_classes β the only
storage backend available on the free plan). Nitro merges that file with its
build output into .output/server/wrangler.json, which is what wrangler ships.
src/
lib/orders.ts pure rules: statuses, line merging, urgency
lib/locale.ts language names, and the date formats that follow them
db/ Drizzle schema and access to the request's D1
paraglide/ generated from messages/ - not committed
server.ts Worker entry: resolves the request's language
server/
cloudflare.ts the current request's bindings (D1, Durable Object)
password.ts PBKDF2 via WebCrypto, shared with the seed script
auth.ts sessions and the requireUser guard
realtime.ts the Durable Object: WebSocket and broadcast
events.ts publish to the hub, attach a screen to it
functions/ server functions: auth, dishes, orders
hooks/ WebSocket subscription and reconnect, Web Audio chime
routes/
connexion.tsx public
_app.tsx shell and access guard: everything below it is protected
_app.bar.* bar mode
_app.cuisine.tsx kitchen mode
api.ws.ts the real-time entry point
messages/ every line of copy, one file per language
public/ the tab's icon: svg, the .ico and the touch png
project.inlang/ the inlang project: languages and message format
i18n.config.ts Paraglide options, shared by Vite and the CLI
drizzle/ SQL migrations applied by wrangler
scripts/seed.ts generates the demo data as SQL
scripts/i18n-compile.ts compiles the messages outside Vite, for tsc
exports.cloudflare.ts exposes the Realtime class to the Worker
wrangler.jsonc D1 and Durable Object bindings
The server publishes three events β order.created, order.completed,
dishes.changed β over a WebSocket (/api/ws).
Why a Durable Object. A Worker is stateless and replicated: the bar station and the kitchen tablet can land on two different isolates, or two different continents. An in-memory bus cannot connect them. A Durable Object is the opposite β exactly one instance for a given id, anywhere in the world. It is the one place in this infrastructure where "everyone is looking at the same object" means something, so that is where the connections live.
It uses hibernation (acceptWebSocket): the object can be evicted from
memory between orders while the connections stay open. A tablet plugged in for a
whole shift therefore doesn't bill continuous execution time.
The trade-off we accepted: EventSource reconnected on its own, WebSocket
doesn't. useAppEvents does that work, with exponential backoff so it doesn't
hammer a server that is already down β and it treats every open as a
synchronisation point. Without that, an order sent while the tablet is
hydrating, or during a wifi drop, would be lost for good, and the screen would
show "nothing to prepare" with an order sitting in the database. That happened
during testing; it's fixed.
Synthesised with the Web Audio API: two notes, no file, no licensing question.
Browsers refuse to play sound before a user interaction. A tablet opened in the morning and never touched again would stay silent all day β silently, with nothing to indicate it. Hence the "Activer le son" button at the top of the kitchen screen: while it is there, the sound does not work. A button to tap at the start of service beats a chime you discover at 8pm has never worked.
- No notion of price. The app carries orders to the kitchen, it doesn't take payment: the bill is settled at the till.
- Order lines copy the dish name at send time. Renaming or deleting a dish therefore never rewrites history. The dish's colour is the opposite choice β read at display time, never copied β because it is a cue for the cook looking at a card right now, and recolouring a dish has to recolour the card on the screen, not only the next order.
- The order's number is chosen by the
INSERTitself.insert ... select max(number) + 1 where service_day = ?is one statement, so two orders sent in the same breath come out 14 and 15. Reading the maximum first and inserting after β the obvious version β hands both of them 14, and the kitchen gets two cards with the same name on the night it matters. A unique index on(service_day, number)is the second half of the argument: if that ever stops being one statement, it fails loudly instead of quietly. - A service is not a calendar day. The counter turns over at five in the morning, Paris time: a bar closing at two is still in the same service at one, and a counter resetting at midnight would send the kitchen a second "#1" mid-rush. Paris rather than the server's clock, because a Worker runs wherever Cloudflare put it and UTC would turn the day at two or three in the morning local time depending on the season.
- A category is a row; the colour is on the dish. Free text on the dish
made "Desserts" and "desserts" two sections of the same card, so a category
became a row and the form a list. The colour sits one level down, on the
dish itself: a section tells you where to look, a colour tells the burger
from the cheeseburger. The sixteen house colours are stored as
ambre, not as#f59e0bβ a hex is a fact about one theme, and this application has two, each picking its own shade for the token. - The picker is the way out of the palette, not the way in. A house that
wants its own colour gets
<input type="color">and a#rrggbbin the column, which is one shade for both themes β exactly the compromise the tokens avoid. So the palette comes first, sixteen swatches wide, and the seventeenth opens the browser's own picker: already familiar under a thumb, already translated, already reachable by keyboard. A custom colour is drawn as an inline style rather than a class, because Tailwind only generates the classes it can read in the source, and it carries a thin ring so a near-white chosen by hand does not vanish on a white card. - The column the colour replaced is still there, on purpose. Dropping
categories.colorin the same migration that addsdishes.colorwould break the Worker still serving traffic, which reads it, for as long as the deployment takes. Expand now, contract in a later release: it costs one extra migration and no downtime. - The name shown in the kitchen is read from the database server-side, never taken from the browser. The client only sends ids and quantities.
- Completing an order is idempotent. The
WHEREclause is onstatus = 'en_attente': if two people tap the same card a second apart, the second one changes nothing and sees no error. In service, that is not an incident. - An order leaves
en_attenteonce, in one of two directions, and never comes back. Cancelling guards on the sameWHERE, so the bar cancelling at the moment the kitchen taps ready is a race one of them simply wins β the other changes nothing and sees the order as it now is. A finished order cannot be cancelled: by then there is a plate, and hiding it would leave somebody with it. - The history window is a
WHERE, not a slice. Thirty days of a busy service is thousands of rows, and the one thing a tablet on bar wifi must not do is download them to show twelve. The window is rolling rather than calendar β "24 h" means the last twenty-four hours, because a bar closing at two in the morning is still in the same service at one, and a history that emptied itself at midnight would be useless at exactly the hour somebody checks it. The server returns at most 500 orders and says so when it had to stop, because a list that silently ends reads as orders that were never taken. - A column the table can sort or search is a column with an accessor. In
TanStack Table v9 both
getCanSort()and the global filter are gated oncolumn.accessorFn: a display column renders fine, sorts never, and is invisible to the search box. The dishes column has an accessor it does not render for exactly that reason β without it, a search box offering to find a dish would find none. - Cancelling is the one gesture that asks first. Everything else here is undone by doing it again; this one stops a kitchen that may already be cooking, from a list of near-identical rows where the wrong one is a thumb away.
- The kitchen update is optimistic: the card disappears under the finger, without waiting for the server, and comes back if the write fails.
- Grouped writes go through
db.batch(), not a transaction: D1 exposes noBEGIN/COMMIT, but guarantees a batch applies entirely or not at all. - PBKDF2-SHA256, 210,000 iterations, rather than scrypt: the Workers runtime
offers neither
node:crypto.scryptnor a WebCrypto equivalent. The iteration count is stored with the hash, so raising it later won't break existing accounts. - A hub failure never cancels the write. An order that is saved but not broadcast is recoverable; an order that is lost is not.
- The theme belongs to the device, like the bar/kitchen mode: the counter
station and the kitchen tablet aren't under the same light. Dark is the
default β a kitchen is often a dim corner β and an inline script in the
<head>applies the stored choice before the first paint, so a device set to light never flashes the server-rendered dark page first.
npm test # business rules (Vitest)
npm run typecheckThe order rules live in src/lib/orders.ts with no database and no React
imports: the state machine, line merging, urgency thresholds. Which is why these
tests run in milliseconds.
src/lib/i18n.test.ts guards the message catalogues instead, because nothing
else does: Paraglide is silent about a message that exists in one language and
not in another β it serves the base language and compiles fine. The tests check
that every file carries the same keys, that a translation has not dropped a
{placeholder}, and that no message has outlived the code that called it.
- No roles. Any signed-in account can switch to kitchen mode, complete an order and edit the menu. That was the choice; separate roles would take one column and one guard per screen, nothing more.
- A single venue. The Durable Object id is the
HUBconstant insrc/server/events.ts; serving several bars would mean turning it into the venue's id β and nothing else would move. - No real time under
npm run dev(see above). - No ticket printing, and no link to a point-of-sale system.
MIT.









