Stock Loja
TypeScript project · featured · web app, Postgres, TypeScript
A stock app for PTDF's branded stores at Lisbon Airport: every size on the shop floor and in two stockrooms, sales by barcode, and six stores in one database that never see each other's data.





- 6stores in one database
- 200+unit and SQL tests
- 28end-to-end checks across devices
- 0sales recorded twice under load
The problem
Stock in the airport stores lived on paper and in Excel. Nobody knew how many of a size were on the shop floor or in the stockroom without going to count, so a size could sell out on the floor while boxes of it sat downstairs. I built an app the staff can use on the shop's iPad and on their phones, for every brand PTDF runs at Lisbon Airport, with nothing to install from a store.
What I built
- Stock per size and colour in three places: the shop floor, the shop's stockroom and the warehouse downstairs. Deliveries go to either stockroom, moves go between any two, and the restock list brings what the floor is missing from the nearest one first.
- Barcode scanning with the camera (EAN, UPC and the GS1 codes on the labels) or by typing the SKU; a complete code is taken without pressing OK. Labels print from the app.
- Sales with exchanges and discounts per item or on the whole sale; every sale keeps the price actually charged, so reports show real money. Returns need a manager's PIN, and five wrong PINs lock it for a minute.
- Six stores in one Supabase (Postgres) database. An account belongs to one store and row-level security only ever returns that store's rows; each store gets its brand's colours and type. A management account sees all six side by side, read only, computed on the server.
- A team chat for questions and shift handovers (with photos), daily summaries, sales per person, stock counts, a history of every movement with undo, and backups.
- An installable web app that keeps working offline for reading: a local copy in IndexedDB, synced incrementally and in real time between devices.
- Database changes ship themselves: each production deploy applies the missing migrations in order, each in a transaction, and the app warns when the database is behind.
The hard part
Never selling the last unit twice. With several devices in one store and airport Wi-Fi that drops answers, two things went wrong in testing: two tills sold the same last unit at once, and a sale was recorded twice when its answer got lost and the device tried again. Every stock change now runs in a Postgres function that locks the size's row, checks the quantity and writes the movement in one transaction, so one of two simultaneous sales is refused; batches lock their sizes in a fixed order, so they can never wait on each other. Each operation also carries a request id the server remembers, so a repeat returns the first result instead of selling again. A load test runs 12 devices for 30 s on the same 16 sizes, sending 15% of requests twice, and checks that every size's history is one unbroken chain.
What it looks like
$ npm run e2e:load 12 devices × 30 s on 16 sizes operations: 22648 (754.9/s), recorded 15996, refused for lack of stock 6652 latency: median 11 ms, p95 44 ms ✓ every operation recorded exactly once, repeats included (43286 = 43286) ✓ each size's history is one unbroken chain (0 breaks) ✓ final stock = opening + all movements, never negative ✓ no deadlocks, timeouts or other errors
Built with
- TypeScript
- React
- Vite + Tailwind CSS
- IndexedDB (Dexie)
- Supabase: Postgres, row-level security, realtime
- Vercel
- Vitest + PGlite
- Playwright
- GitHub Actions
More projects
- metro · Lisbon metro sim in pixel art: watch the four lines run, step into any station, board a train and ride it.
- pac-man · Pac-Man in Python, built as a duo with sylvzzz: a new maze every level and four ghosts that each hunt you differently.
- call_me_maybe · Turns a sentence into a JSON function call with a 0.6B model using constrained decoding — parseable by construction, not by luck.
- RAG against the machine · Answers questions about the vLLM codebase: its own BM25 finds the right chunks among 11,582, then a 0.6B model answers from only those sources.
- codexion · Multithreaded twist on the Dining Philosophers: coders compete for shared dongles, with FIFO/EDF scheduling.
- dbaltaza.pt · A game-console portfolio where every project is a pre-rendered disc: Vite + TypeScript, no framework, and a paint budget the tests measure.
- fly-in · Drone fleet routing: Dijkstra pathfinding, turn-based scheduling and a pygame replay.
- a-maze-ing · Maze generator with multiple algorithms, pathfinding solvers and terminal visualization.
- push_swap · Highly optimized sorting with two stacks and a tiny set of allowed operations.
- ft_printf · printf rebuilt from scratch: chars, strings, pointers, decimals, unsigned and hex.
- get_next_line · Reads a file descriptor one line at a time with careful dynamic memory handling.
- Libft · My own C standard library — the foundation every later 42 project is built on.