# 5. Data & Integration Strategy

## Database

- **Fase awal:** Satu database (MySQL/PostgreSQL).
- **Logical separation:** Prefix/schema per modul opsional; yang wajib: **foreign key terjaga** dan naming konsisten (e.g. `orders`, `order_items`, `outlets`).
- **Migrasi:** Satu `database/migrations` atau migrasi per modul di `Modules/{Module}/Database/Migrations`; run order harus jelas (Auth/User/Outlet dulu, lalu Order, POS, dll).

## Event System (Laravel Events)

| Event (contoh) | Listener (contoh) |
|----------------|-------------------|
| `OrderCreated` | SendNotification, UpdateReportCache, SyncKitchen |
| `OrderPaid` | CloseOrderPayment, LoyaltyPoints, Receipt |
| `StockReduced` | CheckLowStockAlert, UpdateInventoryReport |
| `PaymentCompleted` | POSTransactionLog, SettlementQueue |

Event payload: ID + minimal data; hindari object besar. Listener berat (report, sync) pakai **queue**.

## Queue

- **Driver:** Redis (production); database/sync (dev).
- **Use case:** Notifikasi (email/push), report generation, sync ke KDS/third-party.
- **Naming:** `notifications`, `reports`, `sync`. Job class per modul di `Modules/{Module}/Jobs/`.

## Cache

- **Config/setting outlet:** cache dengan TTL (e.g. 5–15 menit), invalidate on update.
- **Menu per outlet:** cache list category + product; invalidate on ProductUpdated/CategoryUpdated.
- **Session:** Laravel default (file/redis).

## External API (Fase Lanjut)

- Payment gateway, delivery aggregator, marketplace: satu layer **Integration** atau per modul `Modules/{Module}/Integrations/`.
- Credential & endpoint dari config/env; jangan hardcode.
