Skip to content

Healthcare SaaS Module · Pharmacy Inventory & Storefront

Pharmacy Inventory & PharmaStock

I built the pharmacy module of the Simple Green Solutions platform: an append-only stock ledger, per-pharmacy back office, the PharmaStock storefront and oversell-proof checkout inside a MongoDB transaction.

  • Pharmacy dashboard with revenue trend, stock alerts and a live activity feed. Demo data.
  • Append-only stock ledger: every add, removal, sale and count correction is recorded as a movement. Demo data.
  • Inventory with stock-status filters and per-product approval status from platform moderation. Demo data.
  • Order management across the lifecycle, from new order to ready for pickup and completed. Demo data.
  • PharmaStock checkout splits one cart into a separate order for each pharmacy. Demo data.
On this page

My role

This is the pharmacy module of the Simple Green Solutions platform, which I built alone in about ten weeks as a client project at Alphinex Solutions. For the wider platform, including tenancy and booking, read the Simple Green Solutions case study. Here I focus on the part with the most interesting engineering: stock. It is roughly 12,600 lines of TypeScript over 19 pages, on Next.js 16, React 19 and MongoDB.

The problem

An independent pharmacy keeps shelves right, sells to patients and needs doctors to trust it. On a shared platform two things change at once. Staff book in deliveries and write off damaged boxes at the same moment customers are checking out, so the usual "read the quantity, subtract, save" pattern quietly loses updates. And a patient's cart can mix several pharmacies, each of which must see only its own orders. On top of that, regulated products need a gatekeeper before they are visible.

Key decisions and why

No quantity field at all

Everything else follows from one choice: a stock item stores no quantity. Its quantity is the sum of immutable movements, each an initial balance, add, remove, sold or adjustment, with the person, time and an optional note. Two people adjusting the same item cannot overwrite each other because neither one edits a shared number; each appends a row. A correction is another movement, so history stays complete.

The trade-off is an aggregation on every read. Indexes keep it to a single pass, and I accepted the cost because correctness is what a pharmacy is buying.

Derive status, never store it

In stock, low and critical are computed from the ledger sum and the item's own thresholds each time. A stored status could disagree with the number next to it, and a derived one cannot.

Check twice, once inside the transaction

Checkout first checks stock to give a friendly message, for example "Paracetamol only has 3 left in stock". Then it opens a MongoDB transaction and recomputes the ledger sum inside it. The second check is the one that matters, because it covers the window in which a second customer takes the final units after the first check but before the write. I did not use retries to paper over that race.

Snapshots on orders

Each order keeps its own copy of the line items and customer details, so editing a price or profile afterwards leaves past orders untouched. Delivery fields are already stored ahead of the feature, so it can be enabled without reshaping live data.

What I built

  • Back office: a dashboard with a six-month revenue trend, an inventory list with full product records (SKU, dosage, active ingredient, warnings, expiry, thresholds, images), order handling from new to completed, and analytics by category.
  • Bulk stock changes: adjustments across many items at once. The net change per item is worked out across the whole batch before validating, so removing 3 and then 2 from a balance of 4 fails the entire batch, and accepted batches are written in a single transaction.
  • PharmaStock: a public catalog across approved pharmacies with search, category and price filters, an infinite product grid, a profile page per pharmacy and a cart that survives sign-in.
  • Multi-pharmacy checkout: the cart is split by pharmacy, every order carries its own totals, and all of them commit or none do.
  • Approval flow: a new pharmacy waits as pending, moves under review, then approved or rejected. Products start pending too and the operator allows or rejects them with a required reason, one by one or in bulk, with auto-approve for trusted shops.
  • Prescribing link: the doctor's picker uses live approved stock, so a drug sold by five pharmacies appears once.

Order emails are best-effort on purpose, so a mail failure never blocks a status change.

Results

  • The data model itself rules out overselling and lost updates; no retry logic is involved.
  • Any difference between shelf and screen can be traced to a person, a time and a reason.
  • A patient can buy from several pharmacies in one go while each pharmacy sees just its own order.
  • Patients only see what the operator has approved, and every rejection comes with a reason.
  • The module reused the platform's identity and permission model as it was.
All projects

Have a project in mind?

Whether it's an MVP, a dashboard, or a rescue mission on an existing codebase — let's talk about it.

Prefer to talk first? Book a free 30-min call (opens in a new tab)