Mandi Management System: Bilingual Grain Market ERP

Live at mandi.jiddatlabs.com

Outcome

Runs in production behind HTTPS as five Docker containers on one server (database, document store, API, web server and backups), deployed and upgraded by one script that backs the database up before each upgrade. Built for a grain-trading client, it keeps a firm's weighbridge entries, stock, heaps, ledgers and month-end closes in one bilingual record, where nothing counts until it is approved and nothing a firm deletes is lost.

Overview

Stock and accounts software in English and Urdu for Pakistan's grain markets (ghalla mandis), built for commission agents (arhtis), grain traders and stockists. Purchases and sales are weighed loaded and empty at the weighbridge: the trade is priced on the net weight left after bag weight, moisture and other deductions, at a rate per 40 kg maund, while stock is counted and costed on the first weight, loaded minus empty. No entry counts in stock, ledgers or profit and loss until the owner or a colleague holding the approve right approves it in the Approval Centre. Dhadas, heaps of loose grain poured together from several purchases, take each purchase in at its own cost.

Every formula runs on the server, pinned by golden-value tests to the paisa, and a stock cut-off date stops a closed month's entries being counted twice once its balances roll forward. Each firm has its own PostgreSQL schema, every transaction runs as that firm's own database role, and its documents sit in its own SeaweedFS bucket under its own key, so a faulty query meets "permission denied", never another firm's data.

Speed was measured on a test firm with 30,000 approved entries, about three busy years. A statement-level trigger on every firm table moves a per-firm sequence on each write, so the API reuses the stock summary behind every screen until the data changes: 6 ms instead of 2.1 s. A sale's stock-source check fell from 1.7 s to 28 ms, and daily backups stream at an 11 MB memory peak instead of building 64 MB of JSON.

Screens & Demos

Stock screen, demo data: bags, net weight, average cost per 40 kg and value for each grain, in English and Urdu
Stock screen, demo data: bags, net weight, average cost per 40 kg and value for each grain, in English and Urdu

Architecture & Pipeline

  1. 01

    Weighbridge Entry

    React · TypeScript · phone, tablet or PC

    • React
    • TypeScript
  2. 02

    Server-Side Costing

    Python · FastAPI · formulas tested to the paisa

    • FastAPI
    • Python
  3. 03

    Approval Centre

    One approval · staff never self-approve

  4. 04

    Stock & Dhadas

    PostgreSQL · a schema and role per firm

    • PostgreSQL
  5. 05

    Slips & Documents

    A4 · 80 mm thermal · WhatsApp · SeaweedFS

  6. 06

    Ledgers & Month Closing

    P&L · General Ledger · roll-forward

  7. 07

    Backups

    Docker · pg_dump + rclone every 3 h

    • Docker

End-to-end flow, in order. Scroll sideways on a narrow screen.

Key Features

  • First-weight costing: 14,000 kg loaded less 4,000 kg empty is a first weight of 10,000 kg; 150 kg of bag weight and moisture leave 9,850 kg, paid at Rs 3,900 per 40 kg (Rs 960,375), so the purchase goes into stock at Rs 3,841.50 per 40 kg of first weight
  • Approval Centre: the Pending entries of every month and every change awaiting a decision, approved one by one or in bulk; nobody but the owner approves their own work, and a change to an approved or previous-day entry waits for approval unless the owner makes it
  • Dhadas (heaps): each line takes weight from one purchase at that purchase's own cost per 40 kg, the heap carries the weighted average, sales can name the purchase or heap they draw from, and closing a heap with its last sale books any shortage or gain in weight; Stock Valuation lists every purchase still in bags at its own cost and every open heap at its average rate
  • Profit and loss in a QuickBooks-style list or a two-sided BUSY trading account, a General Ledger fed by purchases, sales and bank, cash and journal vouchers, and month or period closing that snapshots the period, carries its balances forward as openings and locks its dates until it is reopened with a reason
  • English and Urdu on every screen, switchable between both, Urdu only and English only, with the Nastaliq Urdu font bundled so screens render without internet on a LAN; slips, WhatsApp messages and Excel files stay bilingual, and amounts are written out in words in both languages, in lakh and crore
  • Slips in three designs (A4 Standard, A4 Modern, 80 mm thermal), each with a scannable QR code and the amount in words; WhatsApp slips in Urdu with gross, tare, deductions, net weight, rate and total; phone photos and PDFs of weight slips and bills joined in the browser into one PDF per bill with pdf-lib
  • Many firms on one installation, each added from an admin dashboard with its owner, staff limits and subscription, and kept apart three times over: membership checks in the API, a PostgreSQL schema and role per firm, and a SeaweedFS bucket and key per firm, with tests showing PostgreSQL and SeaweedFS refuse each firm the other firms' data
  • Nothing a firm deletes is lost: entries, masters and documents are only hidden for the admin to restore, every change keeps who, when, from which device and each value old → new, and the database and every document are backed up every 3 hours in tiers, plus a daily file per firm kept 14 days