# Architecture — Wavora / WAGW SaaS ## High-Level Flow ```text Tenant App / Browser ↓ Wavora SaaS PHP App ↓ Wavora Queue + Cron Worker ↓ GOWA WhatsApp Engine ↓ WhatsApp Web Multi Device ``` ## Main Components ### 1. PHP SaaS App Responsibilities: - Auth/login/register - Tenant management - Device dashboard - API key management - Message API wrapper - Message logs - Queue management - Webhook delivery - Billing/plan enforcement - Admin dashboard ### 2. MySQL Database Stores: - Users/groups/rules - Tenants - API keys - Device mappings - Queue - Message logs - Webhook logs - Usage/billing - Audit logs ### 3. Cron Worker Single runner: ```bash php cron/run.php --task=wa-queue php cron/run.php --task=webhook-retry php cron/run.php --task=device-health php cron/run.php --task=billing-check php cron/run.php --task=cleanup ``` Heartbeat: ```text /tmp/wavora_cron_heartbeat ``` Disable flag: ```text /tmp/wavora_cron_disabled ``` ### 4. GOWA Engine Wrapped by Wavora. Tenants never talk directly to GOWA. Important device-scoping rule: ```http X-Device-Id: ``` or: ```text ?device_id= ``` ## Deployment MVP - One PHP app instance. - One MySQL DB. - One GOWA container/node. - Multi-node/sharding later. ## Scaling Later - Multiple GOWA nodes. - Tenant/device assigned to node. - Queue partition by node/device. - Dedicated node for enterprise tenants.