POS & sales
modules/pos · modules/sales
Cart state in Zustand (the only place it lives), POST /sales with the DUR gate in front of it, and a payment panel that reflects server truth.
Client workBuilt for an external organization under a paid engagement.
Architecture, system rules, decisions & documented evidence.
PHARMACY WEB / صيدليتي
A pharmacy counter runs on a till that cannot be wrong: dispense, check interactions, take payment, and keep the books straight — in Arabic, with the money stored as text.
15
Bounded-context modules
19,4
Money precision
03
Enforced boundary rules
00
Domain data in localStorage
Data path
POS cart → API + contract → Server total
Module count is the src/modules directory; the 19,4 is the NUMERIC precision the contract specifies for money.
Tell me what you need and we can define deliverables, timing and cost. A finished brief is optional.

01 / The challenge
Retail software fails in a specific way: not by crashing, but by being slightly wrong. A total rounded on the client, a payment posted twice after a flaky connection, a credit balance written by a screen that should only read it.
Pharmacy adds a second layer. Dispensing has rules the software must respect — an interaction block is not a warning toast, it is a stop that a pharmacist has to consciously override, and the override itself has to be recorded.
This is the web frontend for a pharmacy SaaS platform, written against a CTO architecture decision document and an API contract specification. The interesting work is not the screens — it is making the rules impossible to bypass.
Core decision: the server owns every number. The client may preview a total, but it never posts one — and it never posts twice, because every financial call carries an idempotency key.
02 / Architecture
The boundary rules are not a convention in a wiki — `npm run boundaries` fails the build when one is crossed.
modules/pos · modules/sales
Cart state in Zustand (the only place it lives), POST /sales with the DUR gate in front of it, and a payment panel that reflects server truth.
modules/inventory · …/grn
Stock, batches and GRN posting — with first-expiry-first-out allocation, which is a clinical requirement before it is an accounting one.
modules/finance · modules/customers
Customer statements and payments. The balance is read-only in the UI: it renders from the statement endpoint and there is no path that writes it.
modules/identity · lib/auth
Tenant identity lives in the JWT. pharmacy_id is never sent from the client, so a manipulated payload cannot address another pharmacy.
POS cart
Zustand — UI only
API + contract
Idempotency-Key, uuidv7
Server total
The only authoritative number
Every financial or inventory POST is idempotent: a retried request after a dropped connection cannot double-charge or double-receive.
03 / Product decisions
NUMERIC(19,4) survives the wire as a string. Client arithmetic exists for preview only; the server total is the one a receipt may print.
A uuidv7 Idempotency-Key rides on /sales, /finance/payments and /inventory/grn. The flaky-connection double-post — the classic retail bug — is designed out rather than tested for.
Three rules, enforced by dependency-cruiser: cross-module imports only via index.ts, components/ui never imports modules, and pages hold no logic. Architecture debt cannot be merged quietly.
Error codes drive the interface. DUR_BLOCK opens a pharmacist PIN-elevation modal and only then retries the request with an explicit override — so the override is an auditable act.
pharmacy_id arrives inside the JWT and nowhere else. There is no request shape a malicious client can edit to reach another tenant's data.
The session token lives in sessionStorage and domain data is never put in localStorage. A shared pharmacy terminal is a shared machine, and the browser should not remember a previous patient.
04 / Routes
Login and the PIN-elevation path used when a dispense trips the DUR gate.
The guarded shell — sidebar per the design system, with revenue/inventory signals where a pharmacist actually looks.
Search via the catalog facade, cart, payment panel, receipt printing.
Stock levels, FEFO batches and GRN posting for received shipments.
CRM list, a per-customer page and a ledger statement that is read-only by construction.
05 / Evidence
15
Modules under boundary rules
from repo
03
Rules enforced in CI, not prose
from repo
41
Runtime dependencies
from repo
STRICT
TypeScript mode
from repo
Module count and boundary rules come from src/modules and the README's own boundary section; dependency count is package.json's runtime list.
Contract tests (tests/contract) and an e2e smoke spec ship in the repo. They are not re-run here, and this file makes no claim about their current pass rate.
No pharmacy count, patient count or revenue figure is claimed — the frontend repository contains no production data.
06 / Technology stack
Twenty runtime dependencies, chosen for state, forms, dialogs and validation — nothing exotic, because a till has to be predictable.
HAND-OFF / 010
Next: offline-first dispense queue for a dropped connection, with the same idempotency key replayed on reconnect rather than a new one.
Want the practical business breakdown—what this project does, how it runs, and its core advantages?
Tell me what you need and we can define deliverables, timing and cost. A finished brief is optional.
NEXT CASE ↳ FROM THE FILES