Doki Doki · 2026 – now · primary developer

Sigma

The manufacturing and supply-chain console a food factory runs on every day.

The manufacturing and supply-chain console a food factory runs on. I am the primary developer, so most of what can go wrong here went wrong for me first.

01The same kilograms, counted twice

Stock lived in two places: an available total, and a quantity on each RFID card attached to a bag. Production debited only the first. Free stock could go negative, and items became impossible to tag.

Firestore makes this harder than it sounds: there are many writers, and a transaction must do all its reads before any write. So every change now goes through one central writer. It refuses negative stock and writes ledger rows with derived ids, which turns a retried request into a no-op. Kiosk issues use a client-generated UUID for the same reason. The invariant is simple to say and test: the total on cards can never exceed what is available.

decided
Draw debits off cards with a pure function, in an order each caller chooses.
instead of
Tying each bag to the batch that used it, which was out of scope for the fix.
the cost
The draw is a heuristic. It can pick a bag that another batch was carrying, and the spec says so.

02Finding the shortage before the scale does

Two batches could book the same stock, and nobody found out until someone stood at the scale with not enough material. Stock only falls at production and only enters once pre-processing is ticked done, so a correct refusal could still block material that is physically in the room.

Reservations are now calculated from open batches at the production date, and expiry-first allocation drains the oldest lots, counting a lot only if it is unexpired on that date. A guard checks this when a batch is created or edited. Because the physical world can be right when the system is wrong, an override exists: it recomputes the shortfall on the server and records who overrode what.

decided
Derive reservations on every read.
instead of
A stored reserved quantity, where every write path must remember to update it and drift is silent, and create-time snapshots, which need a re-snapshot rule.
the cost
Extra reads on every save.

03A kiosk that survives bad Wi-Fi

There was no record of where a batch was, who handled it, or what each room lost. Tablets on the floor have weak Wi-Fi, and the USB RFID readers present themselves as keyboards. So the scanner captures keystrokes globally, ignores focused inputs, buffers until Enter, and validates the result. Out-of-order and double scans are blocked inside a transaction.

When the network drops, the kiosk stays readable from a local cache, but writes stop. An offline write queue was deferred on purpose. My favourite bug lives here: my spec drove the offline banner from the cache flag, and non-leader tabs report that flag as true forever, so perfectly healthy tablets said they were offline. The banner now follows connectivity only.

decided
Tablet-to-room claims are advisory, with integrity guards on the tag.
instead of
Hard locks on a room.
the cost
A wrong claim is possible, but a dead tablet can never strand a room.

04One colour threshold could not express the rule

Goods entered stock unchecked, and the checks differ by item and vendor. I built admin-defined parameters, a two-stage sampling ladder, CIEDE2000 colour difference, and a gate where only the accepted quantity reaches stock.

Then the colour rule broke. A single difference threshold cannot reproduce a procedure with box-shaped tolerances, because the two orderings invert: a sample that passes one can fail the other. Per-axis bands and a HOLD outcome fix that. That work is finished on a branch and not merged yet.

decided
A HOLD outcome on the receipt.
instead of
A quarantine stock bucket, and full AQL tables.
the cost
Fewer sampling schemes than a standard would offer. It covers packaging only.

05Closed by default

A Firebase client config is public, so any signed-in user could try to skip the server. All client writes are denied, and reads need an allow-listed path plus a server-set role claim. Emulator tests cover this, including a token with no claim. Staff writes are default-deny in middleware, and a sweep test checks the allow-list against the real route files, so a route added later stays closed until someone lists it. The cost is a list to maintain.

What this does not cover

  • CI builds and deploys one image per commit with no stored keys, but it does not run the tests. They run by hand.
  • Expiry-first ordering is a calculation and visibility layer. Nothing enforces it at the moment of consumption.
  • There is no offline write queue, and no end-to-end suite.
  • Reservations are still in progress.
next projectText Editor React