The problem
Distributors in Pakistan run stock across two to ten branches on spreadsheets and paper. Quantities drift. Expired lots ship. Fiscal invoicing needs a reliable queue.
I am building IMS to replace that. It is a multi-tenant inventory and digital-invoicing system for pharma and FMCG distributors. It is in progress. Live fiscal submission, counter sale and platform admin are still being finished, and I say so rather than round up.
The constraint
Many businesses share one deployment. A mistake in an action must not expose another business. Stock numbers also have to be explainable, so every quantity on screen links to an Explain view that traces the documents behind it.
My rule for each choice below is to write down the requirement it serves and what it costs. I revisit a choice when measured requirements change, not because another stack is fashionable.
Decisions
One Postgres database and a modular monolith
Stock, reservations and documents must commit atomically. One database gives me that. The cost is discipline: module boundaries need care, and database contention has to be measured instead of assumed away.
Authorization plus forced row-level security and composite tenant keys
Every tenant table has forced row-level security, and foreign keys carry the tenant. An action mistake then meets a wall in the database. The cost is that context, grants and migrations need integration tests that use real roles.
An append-only ledger with one stock engine
Receipts, transfers, counts, shipments and returns all post through one stock engine, inside the caller's transaction. Balance changes, cost layers and ledger entries commit together. I store more rows this way. A correction is a new document, and it must check what depends on the thing it corrects.
Decimal strings and centralised rounding
Quantities and money are decimal strings, and rounding lives in one place. That preserves physical quantity and monetary precision. The cost is that charts and inputs must convert carefully, and a display number is not a posting value.
Atomic reservations, earliest expiry first
Reservations are atomic and conditional, and stock is allocated by earliest expiry first. That prevents overselling. The cost is that backorders and the reservation lifecycle become explicit domain work. Locks are taken in a deterministic order, and that ordering needs adversarial tests.
A queue in Postgres, with pg-boss
I chose pg-boss so jobs are durable and tied to the business transaction, without Redis. The database carries the queue load, and a worker and its schedules have to be running.
A fiscal queue that starts in a sandbox and fails closed
The tax integration runs against a sandbox provider first, and a provider the system does not support is refused. That lets me exercise tax, queue, documents and screens before live credentials exist. The cost: the real provider mapping is unfinished, and credentials alone will not finish it.
A scan PWA with a scoped offline queue
A queue of scan intents lets warehouse work continue through Wi-Fi interruptions. It is not a general offline database. Ownership, expiry and replay failures need to be visible to the user.
Result
The repository stands at 937 commits, 329 SQL migrations, 1,865 source files, 179 pages and endpoints, and 15 modules. Behind it sit 40 specs and 50 plans.
In source, the stock engine, Explain, receiving, transfers, counts, sales orders, reservations, payments and the scan PWA are built. Invoicing and the fiscal queue are built against a sandbox mock only.
The stack is Next.js 16, Postgres 18 and Drizzle, with argon2id, TOTP, OIDC and Turnstile on the auth side.
What is not done: live fiscal submission, counter sale and platform admin. Built in source is not the same as accepted in production, and I make no production claim.
What I would change
This section is opinion. If I rebuilt it, I would write the row-level security integration tests before the first tenant table, not alongside it.
I would also start the live fiscal work earlier. A sandbox proves the queue. It cannot settle the real provider's mapping, and that is the biggest open item.
I would also check specs against source on a schedule, so the documents cannot drift from the code.