ERP System — Multi-Tenant Business Management SaaS
Overview
A multi-tenant SaaS ERP built from the ground up for small/medium businesses: sales invoicing, warehouse and inventory management, expense tracking, customer and supplier management, multi-branch operations, a role-based team system, and dashboard analytics. Every admin's own account ID is their workspace key, with staff belonging to that workspace and every data document tagged to it — read and write access is scoped by branch through a small set of shared helpers rather than ad-hoc per-controller checks, so the same code path is correct for admins and staff alike.
My Role
Solo full-stack build across both apps: the multi-tenant/multi-branch data model and its shared scoping helpers, the 24-key RBAC system with cascading role updates, the invoicing engine (dynamic line items, auto totals, branch-coded sequential numbering, auto stock decrement), the warehouse and expense modules with their auto-generated read-only invoice documents, PDF/Excel export pipelines, and the admin dashboard.
Modules & Features
Multi-Tenancy & Branch Architecture
Every admin owns an independent workspace keyed by their own user ID; staff attach to it via workspaceId. Three shared helpers (getBranchFilter, getWorkspaceQuery, resolveBranchId) drive every read and write so branch-scoping logic lives in one place instead of being duplicated per controller. Each branch carries three independent atomic invoice counters (sales, warehouse, expense), formatted as sequential branch-coded numbers like CAI-0001.
Permission System
24 permission keys across 8 groups (reports, invoices, customers, products, warehouse, expenses, suppliers, team). Admins bypass every check; staff need the exact key. Role edits cascade immediately to every staff member assigned to that role via a single bulk update, and unassigning a role clears its permissions in the same write so the two never drift apart.
Sales Invoicing
Dynamic line items with automatic subtotal/total/remaining calculation and paid/partial/unpaid status detection. Creating an invoice auto-decrements matching product stock and logs a stock movement, auto-links or creates the customer record, and supports single PDF or bulk Excel export.
Products & Warehouse
Product catalog with auto-generated SKUs, cost/selling price, stock levels, and low-stock thresholds. Every stock change — purchase, sale, manual adjustment, or return — is logged as a stock movement and automatically produces a read-only warehouse invoice document; nothing on this side is created directly from the frontend.
Expenses & Expense Invoices
A deliberately create-only expense form with no list view of its own — every expense automatically generates and keeps in sync a linked, read-only expense invoice, which is the only place expenses are browsed, filtered, and exported from.
Customers & Suppliers
A workspace-scoped customer directory (so the same customer can appear across branches) with lifetime billing stats, and a per-branch supplier directory with its own financial dashboard and full purchase history. Deleting either unlinks it from related records rather than blocking the deletion.
Dashboard, Team & Settings
An admin-only dashboard with P&L, cash flow, and analytics tabs that respect the active branch filter; staff/role management scoped by a branchIds array (cross-branch manager, single-branch, or switchable multi-branch); and workspace-level VAT configuration with an optional per-branch override.
