# TEMLOL Diagnostic Centre ERP - Technical Architecture

## 1. Stack & Framework Architecture
- **Backend:** Laravel 12 (PHP 8.3+) utilizing Eloquent ORM, Sanctum token authentication, and background job processing.
- **Frontend Reactive Layer:** Livewire 3 + Alpine.js + Tailwind CSS.
- **Database Engine:** MySQL 9.0+ / MariaDB 10.11+ enforcing InnoDB transaction engine.

## 2. Automated Reagent Consumption Engine
The mapping between tests and physical stock is defined in `lab_test_reagents`.
When `App\Services\ReagentConsumptionService::deductForBill($bill)` executes inside a DB transaction:
1. Locks inventory records using `select ... for update`.
2. Computes total consumption ($QuantityRequired \times TestQuantity$).
3. Creates immutable ledger entries in `reagent_consumptions` and `stock_movements`.

## 3. Double-Entry General Ledger Engine
Every financial transaction invokes `App\Services\AccountingService`.
Double-entry transactions strictly enforce:
$$\sum \text{Debits} = \sum \text{Credits}$$
Posting directly to Chart of Accounts (`accounts`) and Journal entries (`journal_entries`).
