Engineering Ackura ERP: Architecting a Multi-Tenant SaaS Platform with Next.js and NestJS
How we architected and engineered Ackura ERP (owned by Montalaq) — a production-scale multi-tenant SaaS platform covering Accounting, HR, Inventory, POS, and Assets with Next.js 15, NestJS 11, and PostgreSQL.
The Architectural Challenge of Modern ERP Systems
Enterprise Resource Planning (ERP) systems represent one of the most demanding software engineering challenges. Unlike typical SaaS products with homogeneous workflows, an ERP must coordinate financial accuracy, supply-chain logistics, human resources, and compliance requirements across thousands of concurrent operations — all while providing zero margin for data inconsistency.
At Montalaq, we engineered Ackura ERP as a production-grade multi-tenant SaaS platform built from the ground up to solve these constraints. As Partner at Montalaq and Senior Software Engineer leading architecture, here is the technical breakdown of how we structured the system, the tradeoffs we made, and how each subsystem operates in production. You can also explore the project summary in the Ackura ERP case study.
1. System Architecture: The Modular Monolith
Rather than starting with distributed microservices — which introduces network latency, distributed transactions, and immense DevOps complexity — we built Ackura ERP as a NestJS 11 modular monolith. The system is partitioned into strictly encapsulated domain modules:
- Accounting & Finance: General ledger, double-entry journal entries, chart of accounts, and financial statement generation.
- Inventory Management: Real-time stock valuation (FIFO/weighted average), multi-warehouse tracking, and stock movement logs.
- Point of Sale (POS) & Invoicing: Rapid checkout, barcode scanning, offline-resilient sync, and ZATCA Phase 2 compliance.
- HR & Payroll: Employee contracts, attendance tracking, automated payroll calculation, and leave management.
- Assets & Logistics: Asset depreciation tracking, lifecycle auditing, and shipment fulfillment workflows.
Each module maintains its own services, entities, and data access repositories. Communication between modules occurs through well-defined internal interfaces, preventing uncontrolled coupling across domains.
2. Multi-Tenant Isolation Strategy
In multi-tenant SaaS, tenant isolation is non-negotiable. In Ackura ERP, we implemented a hybrid isolation model:
- Subdomain-based Routing: Each tenant accesses the platform via their custom subdomain (e.g.
client.ackura.net). Next.js middleware resolves the hostname, verifies the tenant status, and injects a cryptographicx-tenant-idheader into downstream requests. - PostgreSQL Schema & Database Isolation: Critical financial and operational data is partitioned at the PostgreSQL schema layer. Every tenant has dedicated tables isolated within their schema namespace, completely eliminating cross-tenant query contamination risks.
- Request-Scoped Tenant Context: In NestJS, a request-scoped provider extracts and validates the tenant context for every incoming API call, guaranteeing that all database connections dynamically switch to the tenant's isolated schema.
3. The Central Double-Entry Accounting Engine
At the financial core of Ackura ERP is an automated double-entry ledger. In double-entry bookkeeping, every financial transaction must satisfy the fundamental equation: Total Debits = Total Credits.
Whether a sale is completed at the POS, inventory is revalued, or payroll is disbursed, the triggering module does not directly manipulate ledger balances. Instead, it emits a standardized financial event that the accounting engine processes into atomic journal_entries and journal_entry_lines within a single database transaction. If the debit/credit sums do not balance to the penny, the entire transaction is rolled back, guaranteeing absolute mathematical consistency.
4. Frontend Architecture: Next.js 15, SWR, and Zustand
The client side demands high responsiveness for data-heavy administrative tables and real-time operational views. We built the frontend using Next.js 15 App Router, React 19, and TypeScript:
- Server Components for Shell & Initial Data: Page shells, permission layouts, and initial metrics are rendered on the server for instant LCP and minimal client-side JavaScript.
- SWR for Real-Time Synchronization: Data grids and operational dashboards leverage SWR with optimistic updates and background revalidation, keeping stock counts and order queues synchronized without manual page reloads.
- Zustand for Complex Module State: For multi-step transactions — such as creating a comprehensive purchase order with dynamic taxes, discounts, and line items — lightweight Zustand stores manage local component state with zero unnecessary re-renders.
5. Background Processing & Compliance (ZATCA)
Heavy operations — such as generating monthly financial balance sheets, processing bulk invoice PDFs, and cryptographic XML signing for ZATCA e-invoicing compliance — are offloaded to BullMQ queues backed by Redis workers. This keeps HTTP response times under 150ms even during peak business operating hours.
Conclusion & Key Takeaways
Engineering an enterprise platform like Ackura ERP requires aligning deep domain understanding — especially in financial accounting and enterprise operations — with robust software architecture. Choosing a modular monolith with strict schema isolation gave us the development velocity of a unified codebase combined with the security and reliability required by enterprise clients.
Learn more about our work at Montalaq, visit the live platform at ackura.net, or explore our other systems in the Projects directory.