Multi-Tenant ERP for Pakistani SMEs, in English and Urdu

Live at erp.jiddatlabs.com

Outcome

Deployed with one script on one server, the ERP runs every module from the ledger to manufacturing, with 398 backend tests against a real PostgreSQL 18 and the books' 11 invariants checked after every one. Firms are kept apart and their books kept balanced by the database itself, and it holds its speed at one firm's target year of 1M ledger lines: a year's trial balance in 0.18 s, measured on a laptop.

Overview

A multi-tenant ERP for small and mid-sized companies, built for Pakistan first: accounts, banking, sales tax, sales, purchasing and stock, then point of sale, payroll, projects and manufacturing, each firm in its own brand and in English or Urdu, with right-to-left screens and Nastaliq prints. FastAPI, PostgreSQL 18 and React run in Docker Compose on one server, and every invoice, bill and voucher moves through one document engine with gapless numbering.

Firms share tables, so the database enforces isolation: every tenant table runs under forced row-level security with a policy that returns nothing when no firm is named, every foreign key between a firm's rows includes the tenant, and the migration refuses to finish if any table lacks the policy. The books are held the same way: a trigger refuses an entry that does not balance, posted lines cannot change even for the tables' owner, corrections are reversals, and a worker hash-chains each entry. Stock is valued at moving average, and a back-dated receipt revalues every move after it: at 500,000 moves a year, one dated a year back on the busiest item revalues 8,219 documents in 2.0 s on a laptop.

Guardrails are on by default wherever money, stock or tax moves: 25 rules in one registry, from credit limits and sales below cost to duplicate bills and ghost employees, run alike for screens, imports and the API; overriding a block takes the rule's right and a reason, which go to a review queue. FBR Digital Invoicing is switched on per company with its own PRAL token, kept encrypted: a posted invoice is queued in the same transaction and sent by a worker once it commits, so an FBR outage never stops a sale.

Screens & Demos

Home screen of a demo firm: the month's sales, stock, bank, what customers owe and profit, and every new document a click away
Home screen of a demo firm: the month's sales, stock, bank, what customers owe and profit, and every new document a click away
The same home screen in Urdu, laid out right to left
The same home screen in Urdu, laid out right to left
A draft sales invoice: sales tax, due date, FBR digital-invoicing fields and the total in words
A draft sales invoice: sales tax, due date, FBR digital-invoicing fields and the total in words

Architecture & Pipeline

  1. 01

    Firm Set-up

    Admin console · companies · Pakistan SME or IFRS chart

  2. 02

    Sales, Purchasing & Stock

    React · TypeScript · one document engine

    • React
    • TypeScript
  3. 03

    Guardrails & Approvals

    FastAPI · 25 rules · maker-checker

    • FastAPI
  4. 04

    Posting Engine

    PostgreSQL · forced RLS · balanced, append-only

    • PostgreSQL
  5. 05

    FBR Digital Invoicing

    Python worker · PRAL DI API v1.12

    • Python
  6. 06

    Prints & Sharing

    WeasyPrint · English or Urdu · e-mail, WhatsApp

  7. 07

    Nightly Checks & Backups

    11 invariants · hash chains · Barman PITR

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

Key Features

  • Tenant isolation in PostgreSQL itself: forced row-level security on every tenant table with a policy that fails closed, foreign keys that carry the tenant, a migration that stops if any table lacks the policy, and each firm's files in their own SeaweedFS bucket under a key that opens only that bucket
  • A ledger the database guards: a statement trigger refuses an unbalanced entry, posted lines never change, corrections are reversals on the original date, a worker hash-chains posted entries and documents, and 11 invariants, from a zero trial balance to stock accounts that equal the stock ledger, are checked every night
  • 25 guardrails with Solo, Standard and Strict presets, from credit limits and sales below cost to duplicate bills and ghost employees, plus hard maker-checker; planted frauds, such as paying a changed bank account inside its 48-hour hold, are tests that must be blocked or flagged
  • FBR Digital Invoicing built to PRAL's published DI API v1.12 and tested against a stand-in for FBR: a local pre-check of what FBR would refuse, retries from a queue, every request and FBR's answer kept unchanged, cancellation only within FBR's 72 hours, and the sales tax invoice printed only once it carries FBR's number and QR
  • Perpetual stock at moving average per item and warehouse, with batches, expiry and serials, and a till that opens and sells offline from a service worker, posts each queued sale once when the network returns, and closes blind
  • Pakistan payroll with income tax by the tax year's slabs re-spread every month, EOBI and provincial social security, attendance and leave taken off the run, and payslips in English and Urdu, tested against two months of hand-worked figures
  • English or Urdu, one at a time: the layout mirrors right to left, WeasyPrint prints A4 and 80 mm in either language with Urdu in Nastaliq, the build fails on on-screen text left untranslated, and each firm's colour becomes a palette that passes WCAG AA contrast