Skip to content
Rachad Ghanem
All work
Rolling outCore modules in daily use

Supermarket ERP

An ERP for a multi-branch, multi-floor supermarket chain.

  • .NET 10
  • Next.js 16
  • PostgreSQL
  • EF Core
  • React 19
  • TanStack Query
  • IndexedDB
  • Docker Compose

Closed source · case study

01

The problem

A supermarket chain needs one system for stock, purchasing, the tills, outside orders, its public shop and in-store advertising, across several branches, each with its own catalogue and stock.

Two things can't go wrong: a till that stops selling when the network drops, and a stock number nobody can explain.

02

My role

I built 9 modules, front to back:

  • Inventory & warehouses
  • Purchasing
  • Point of sale
  • External orders
  • Public website
  • Marketing & in-store advertising
  • User management
  • Shared tools
  • Settings
03

Architecture

.NET 10 API10 MODULES · ALL FOUR LAYERSHTTPwebhookscalls + callbacksAdmin portalNext.jsPublic shopNext.jsPresentationAdminPortalBusinessApplicationDataDataLayer · EF entitiesDomainDTOsenumsconstantsPostgreSQLEF CoreWhatsAppMeta Cloud APIPython agentnegotiationagent:8001Reportsowner · inventoryInventoryPurchasingPoint of saleExternal ordersMarketing & adsUser managementTools · price checkSettingsAccountingHR
Two Next.js frontends, one layered .NET API, one PostgreSQL database, and a Python agent that negotiates purchase orders with suppliers over WhatsApp. Each of the ten modules runs through the four layers.

ALSO IN THE SYSTEM

  • Catalogue changes reach every till within seconds, pushed over Server-Sent Events
  • Two currencies: prices are dated, and exchange rates are frozen on every movement and order
  • The low-stock screen suggests order quantities from reorder points per product variant and stock zone
  • Tools include a price checker and price labels
04

Key decisions

DECISION 01

The till never waits for the network

CHOSE
Every sale is written to the browser's IndexedDB first, then flushed in order: customers, then sales, then returns. Tills number their own receipts offline from a two-digit register code.
REJECTED
Online-only tills that call the API on every sale.
WHY
A supermarket can't stop selling when the connection drops. The server's two-part idempotency means a sale retried after a timeout is never booked twice.
DECISION 02

Stock is a ledger, not a number

CHOSE
An append-only stock movement ledger, enforced by a database trigger, with corrections as reversal rows and balances per variant per zone.
REJECTED
Editing stock quantities in place.
WHY
Every number on screen can be explained by the movements behind it. Negative stock is flagged, never blocked, so the shelf and the system get reconciled instead of the till refusing a sale.
DECISION 03

Transfers lock in a fixed order

CHOSE
Take advisory locks in a fixed order before posting any movement that touches several variants.
REJECTED
Relying on the database's row locks alone.
WHY
Two opposite transfers deadlocked, reproduced three times out of three. Ordering the locks removes the cycle instead of retrying around it.
DECISION 04

Prices are dated, not overwritten

CHOSE
A price change adds a dated line. The exchange rate is frozen on every movement and order, and the rate history is append-only.
REJECTED
Updating the price in place.
WHY
A sale made last week is still explained by the price that applied then, and in a two-currency market a till's hours-old rate can be checked against the history.
05

Results

9

modules I built

4

branches in the rollout

Offline

tills keep selling, and sync when the network returns

Daily

core modules in use every day

06

What I'd do next

  1. 01

    Build the nightly balance check the ledger was designed for: recompute every balance from its movements and flag any drift.

  2. 02

    Derive reorder points from sales velocity instead of typing them by hand.

  3. 03

    Value stock in one base currency, so reports across dollar and local-currency costs add up.