Henry Carrasco

Cuadra

A wholesale market stall’s daily ledger, on the phone and on the PC, doing the arithmetic on its own.

Year
2026
My role
Product, design and full development
Team
solo
Sector
Wholesale market trading
  • Dart
  • Flutter
  • SQLite
  • Supabase
  • Android
  • Windows
The TODAY screen with the day’s numbers: what was sold, what was collected, what is owed and the freight for two trucks

The problem

What was wrong

A wholesale stall trader runs the day on a notebook page and closes it with a calculator. Everything they need to know — how much I sold, how much money I actually have, who owes me, how much is left to sell and how much the supplier is owed — is written on that page, but none of the five answers is: each one is a sum done by hand, before dawn, with both hands full. What exists to replace the notebook are inventory systems asking about SKUs, warehouses and stock ledgers, words they do not use.

The constraints

  • No signal. There is no reliable coverage in the market before dawn, so the app has to work entirely offline and sync afterwards, not the other way round.
  • The market day does not start at midnight: goods arrive at eleven at night and sell until noon the next day. Grouping by calendar date puts half the working day on the wrong one.
  • It is used standing up, before dawn, with both hands full: a sale has to fit in under ten seconds and on a single screen.
  • The vocabulary is the stall’s, not an accountant’s. The moment the word “inventory” appears, the trader stops recognising their own notebook.

What I built

The solution

  • A genuinely offline-first architecture: no widget, no provider and no use case ever calls the network. The UI reads and writes only to local SQLite through Drift, and a separate synchroniser uploads to Supabase when there is signal.
  • Every write leaves the row and its sync-queue entry inside the same transaction, with upload ordered by dependencies, upsert by id — resending never duplicates — and conflicts resolved by last writer wins.
  • Money as integer cents and quantities in thousandths: no floating point. An application whose only purpose is to balance cannot afford a one-cent discrepancy.
  • The market working day as a first-class concept: every record stores its business date, computed with a configurable cut-off hour.
  • Nineteen screens in the stall’s vocabulary: TODAY with the five live numbers, multi-brand sales with a custom keypad, WHO OWES ME, the goods and cash reconciliations, suppliers, settlements, deposits and lot adjustments.
  • Fifteen tables with soft deletes and RLS on all of them, UUID v7 identifiers generated on the client — with no network there is nobody to ask — and the same code running on Android and Windows.

Seeing it work

Screenshots

How I did it

My part and my decisions

Separating what I designed from what I implemented does not take anything away: it is what lets you tell whether I can carry a design or only execute one.

01

What was mine

What I designed

The whole product before writing it: the twenty-four closed decisions in the plan, the fifteen-table model, the scope rule that decides what gets in, the working-day concept with its cut-off hour, the model of debt as a sale with an outstanding balance, and the synchronisation scheme with its dependency ordering.

What I implemented

The application and its database: 37 hand-written Dart files and around 13,000 lines — on top of the 16,700 Drift generates — 19 screens, the Postgres schema with its policies, and 1,344 lines of tests across five files.

Who I worked with

A personal project, from end to end. It was born right after MercadoMAX and against it: the same market, the opposite decision. There I modelled the whole chain — dispatch notes, transport, receiving, inventory, finance — and here the work was taking things out. The rule holding it together is a single question for every new idea: do I need this to record a sale, balance the day or settle with the supplier? If the answer is no, it does not get in.

What I learned here

That working offline is architecture and not a feature bolted on at the end: in the first plan it sat in phase nine, and moving it to phase one was the correction that avoided rewriting the whole data layer later. Also that scope is not defended with willpower but with a written criterion that can be applied without arguing.

02

Technical decisions

Debt is not a table

The obvious move was a debts table fed by sales. I ruled it out: a debt is a sale with an outstanding balance, and it is enough to look at it. With the same number living in two places, the day one gets updated and the other does not, the app lies about the one thing it has to get right. This way a payment is a payment against its sale, and “who owes me” is a query rather than a record to maintain by hand.

Reconciliation compares expected against counted, not sold against collected

The obvious screen would have set sold against collected, but “sold = collected + outstanding” is a tautology: it can never fail, so it tells you nothing. The reconciliation that works computes what you should be holding — what came in, minus the freight you paid out and what you already handed to suppliers — and then asks you to count the cash. The difference between those two numbers is the only one that means anything.

What is missing: putting it in front of a trader

Three rules in the plan were marked as pending field validation, and they still are: what time they consider their day to start, whether commission is computed before or after freight, and who really pays the freight. They are implemented according to what I was told, so until someone works a real day with the app they are my assumptions. That is what decides whether this version is useful, and it is not solved by writing more code.

03

What broke, and how I fixed it

The date that put half the working day on the wrong one

The first version grouped by the record’s creation date, which is what anyone would do. With realistic test data the reconciliation started coming out wrong for no apparent reason: what was sold before dawn landed on one day and the goods that had fed it on the previous one. The problem was not a calculation, it was the model: in a wholesale market the working day starts when the truck arrives, not at midnight. I introduced the business date with a configurable cut-off as a first-class domain concept, and it is now stored on every record instead of being derived at query time.

How it holds up

Security, errors, performance and maintainability

What keeps a system standing after it is written. Where I have not measured it, I say so.

Security
RLS active on every table, no exceptions: a user sees and modifies a row only if they belong to a business they are registered in, and that rule lives in Postgres, not in Flutter. The only key shipped in the app is the public one. The local database is not encrypted in this version — personal device, non-sensitive commercial data — and that is written down as pending rather than omitted.
Errors
Integer money and exact decimal quantities remove at the root the class of error that matters most here. Synchronisation never blocks the UI: rejections go to a local log with backing-off retries, and whatever exhausts its attempts is flagged for review instead of disappearing quietly.
Performance
Every read is local against SQLite, so the interface never waits on the network, with or without signal. The app starts and responds the same in a market with no coverage as it does at home.
Maintainability
The golden rule is that no widget or provider ever calls Supabase: if a .NET API of my own were needed tomorrow, only the synchroniser changes. 77 tests cover the pure formulas, a full working day against an in-memory database, the schema migration and a UI smoke test.

Outcome

What changed

Version 1 is implemented and runs from the same code on Android and Windows, with an APK and an installer built. All 77 tests pass, and the sample working day closes on its own: twelve sales, debts spread across five people, freight for two trucks, the goods reconciliation brand by brand and the supplier settlement. What remains open is identified: the sync queue is fully tested locally, but the round trip against a real Supabase project has to be compiled with credentials before it can be called done.