All projects

Core ERP purchasing, sales, and inventory modules with replicated MySQL

Backend architecture for core ERP transaction modules — purchasing, sales, stock opname, and transfers — backed by MySQL/MariaDB cross-server replication on Ubuntu and Nginx.

  • PHP
  • Laravel
  • MySQL / MariaDB
  • Nginx
  • Linux
Core modules
5+
Purchasing, sales & inventory
Data resilience
Cross-server
MySQL / MariaDB replication
Server stack
Ubuntu + Nginx
Automated SSL & ops

The problem

ERP workflows are unforgiving when transaction boundaries are loose. A purchase invoice, a purchase return, a sales order, a stock opname adjustment, and an inter-warehouse transfer all mutate the same underlying inventory and accounting state. If one module updates stock differently from another, reconciliation breaks at month-end.

Alongside application correctness, the production environment needed predictable availability and clear separation between primary write workloads and replicated database state.

Constraints

  • Inventory movements across purchasing, sales, returns, opname, and transfers had to follow consistent accounting and stock-ledger rules.
  • Multi-step document posting could never leave partial stock or invoice entries committed on failure.
  • Production Ubuntu servers, Nginx configuration, SSL certificates, and MySQL/MariaDB replication had to be maintainable without a dedicated platform team.

Architecture

flowchart LR; Users[Operations & Finance] --> Nginx[Nginx + Automated SSL]; Nginx --> Laravel[Laravel ERP Backend]; Laravel --> Primary[(Primary MySQL / MariaDB)]; Primary -->|Cross-Server Replication| Replica[(Replica DB Server)]; Laravel --> Modules[Purchase · Return · Sales · Opname · Transfer]
ERP transaction modules and cross-server database replication

The Laravel backend organizes purchasing, returns, sales invoicing, stock opname, and stock transfers around explicit transactional boundaries in MySQL/MariaDB. At the infrastructure layer, Ubuntu hosts run Nginx with automated SSL termination and cross-server database replication to protect availability and operational continuity.

Decisions

Treat stock and accounting movements as atomic transactions. Posting a Purchase Invoice, Purchase Return, Sales Invoice, or Transfer Stock wraps header, line items, and inventory balance changes inside a single database transaction so failures roll back cleanly.

Model business rules from accounting fundamentals. Document states (draft, posted, returned, adjusted) are explicit instead of relying on ad-hoc edits, making stock opname discrepancies and historical audits traceable.

Own the production path end to end. Pairing Laravel application work with direct ownership of Ubuntu server hardening, Nginx tuning, SSL automation, and cross-server MySQL/MariaDB replication removes the handoff gap between code and deployment.

Result

Operations and finance teams run purchasing, sales, stock opname, and stock transfers on a unified transactional model backed by replicated MySQL/MariaDB infrastructure and automated TLS on Nginx.

What I would change

Introducing an append-only ledger projection and automated replication-lag alerting earlier would make auditing historical stock valuations and detecting replica drift even faster during peak closing periods.