# royal300/whatsapp_panel architecture

> Architecture diagram of the GitHub repository royal300/whatsapp_panel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/royal300/whatsapp_panel
- Repository: https://github.com/royal300/whatsapp_panel

## Overview

#### 1. Purpose and deployment shape
Royal300 is a multi-tenant WhatsApp marketing, inbox, campaign, template, and automation SaaS built around Meta’s WhatsApp Cloud API. It is a separate React SPA and Laravel API deployment: the browser app calls Laravel endpoints; Laravel persists tenant-scoped data and integrates with Meta.
Paths: `frontend/src/main.jsx`, `backend/public/index.php`, `backend/routes/api.php`

#### 2. Frontend application shell
The React 18 SPA provides authenticated operational screens and shared navigation/state. `App.jsx` is the primary UI composition/routing boundary; authentication and theme state are supplied through contexts. API communication is centralized rather than embedded in page components.
Paths: `frontend/src/App.jsx`, `frontend/src/context/AuthContext.jsx`, `frontend/src/services/api.js`

#### 3. Operations UI domains
The SPA exposes distinct workflows for inbox/chat handling, contacts, templates, campaigns, automation/flow design, analytics, settings, agents, and super-admin functions. These pages are the client-side boundary over corresponding Laravel controller APIs.
Paths: `frontend/src/pages/Inbox.jsx`, `frontend/src/pages/Campaigns.jsx`, `frontend/src/pages/FlowBuilder.jsx`

#### 4. Laravel API, identity, and tenancy
Laravel 11 is the system-of-record API. Controllers expose domain operations; Sanctum configuration indicates token-based API authentication, while role middleware gates privileged routes. Tenants, users, plans, and subscriptions model SaaS ownership, access, credentials, domains, and validity.
Paths: `backend/routes/api.php`, `backend/app/Http/Middleware/RoleMiddleware.php`, `backend/app/Models/Tenant.php`

#### 5. Messaging and webhook flow
Meta sends inbound/status webhook traffic to Laravel. The webhook controller and WhatsApp service normalize external API interaction; received messages become chat/message records and emit a `MessageReceived` event. The frontend supports polling fallback, while Laravel broadcasting/Pusher services provide a real-time integration boundary.
Paths: `backend/app/Http/Controllers/WebhookController.php`, `backend/app/Services/WhatsAppService.php`, `backend/app/Events/MessageReceived.php`

#### 6. Campaign, contact, and template pipeline
Contacts and tags define campaign audiences. Campaigns reference content/media/templates and create campaign logs for send outcomes. Bulk processing is deliberately asynchronous through a queue job, separating API request handling from potentially long-running Meta sends. Templates are stored locally and synchronize against approved WhatsApp templates.
Paths: `backend/app/Jobs/ProcessCampaignJob.php`, `backend/app/Models/Campaign.php`, `backend/app/Models/CampaignLog.php`

#### 7. Automation, AI, and commercial services
Automation rules support keyword/autoresponder behavior, orchestrated by a dedicated service. AI quick-reply capability is represented by an AI service and tenant feature data. Billing is isolated behind a service with plan/subscription models; email notifications cover onboarding, OTP, and tenant portal expiration.
Paths: `backend/app/Services/AutomationService.php`, `backend/app/Services/AIService.php`, `backend/app/Services/BillingService.php`

#### 8. Runtime and infrastructure boundaries
Backend runtime is PHP 8.2+/Laravel, MySQL migrations/schema, Laravel queues/cache, mail, Sanctum, and optional broadcast/Pusher infrastructure. Frontend is React 18 with Tailwind and Rsbuild. The key external service is Meta WhatsApp Cloud API; local webhook testing requires a public tunnel such as ngrok.
Paths: `backend/config/database.php`, `backend/config/queue.php`, `frontend/rsbuild.config.mjs`

Main entry points: [`backend/routes/api.php`](https://github.com/royal300/whatsapp_panel/blob/main/backend/routes/api.php) (API routes & controllers), [`frontend/src/App.jsx`](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/App.jsx) (App shell & routes), [`backend/app/Jobs/ProcessCampaignJob.php`](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Jobs/ProcessCampaignJob.php) (Campaign processor), [`frontend/src/services/api.js`](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/services/api.js) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_entry["SPA entry<br/>React bootstrap<br/>[main.jsx]"]
  node_app_shell["App shell &amp; routes<br/>React composition<br/>[App.jsx]"]
  node_auth_state["Auth state<br/>React context<br/>[AuthContext.jsx]"]
  node_api_client["API client<br/>HTTP service<br/>[api.js]"]
  node_operations_ui["Operations UI<br/>Inbox, campaigns &amp; flows<br/>[Inbox.jsx]"]
  node_campaigns_ui["Campaigns UI<br/>Campaign workflow<br/>[Campaigns.jsx]"]
  node_flow_builder["Flow builder<br/>Automation workflow<br/>[FlowBuilder.jsx]"]
end

subgraph group_api["Laravel API"]
  node_laravel_entry["Laravel runtime<br/>PHP API entry<br/>[index.php]"]
  node_api_routes["API routes &amp; controllers<br/>Laravel HTTP boundary<br/>[api.php]"]
  node_access_control["Token auth &amp; roles<br/>Sanctum and middleware<br/>[RoleMiddleware.php]"]
  node_tenant_domain[("Tenant &amp; subscription domain<br/>SaaS ownership model<br/>[Tenant.php]")]
  node_webhook_controller["Webhook controller<br/>Meta webhook endpoint"]
  node_whatsapp_service["WhatsApp service<br/>Meta integration"]
  node_automation_ai["Automation &amp; AI<br/>Domain services"]
  node_billing["Billing service<br/>Commercial service<br/>[BillingService.php]"]
end

subgraph group_async["Async &amp; realtime"]
  node_campaign_job["Campaign processor<br/>Queued job"]
  node_campaign_records[("Campaigns &amp; send logs<br/>Campaign persistence<br/>[CampaignLog.php]")]
  node_message_event["Message received event<br/>Broadcast event"]
  node_data_runtime[("MySQL, queue &amp; cache<br/>Laravel infrastructure<br/>[database.php]")]
end

subgraph group_external["External services"]
  node_meta{{"Meta WhatsApp Cloud API<br/>External messaging platform"}}
  node_realtime{{"Pusher / broadcast<br/>Realtime provider"}}
end

node_spa_entry --> node_app_shell
node_app_shell -->|"uses"| node_auth_state
node_app_shell -->|"renders"| node_operations_ui
node_app_shell -->|"renders"| node_campaigns_ui
node_app_shell -->|"renders"| node_flow_builder
node_operations_ui -->|"calls through"| node_api_client
node_campaigns_ui -->|"calls through"| node_api_client
node_flow_builder -->|"calls through"| node_api_client
node_api_client -->|"HTTPS API"| node_api_routes
node_laravel_entry -->|"boots"| node_api_routes
node_api_routes -->|"enforces"| node_access_control
node_api_routes -->|"scopes data"| node_tenant_domain
node_api_routes -->|"queues campaigns"| node_campaign_job
node_api_routes -->|"configures rules"| node_automation_ai
node_api_routes -->|"manages plans"| node_billing
node_campaign_job -->|"records outcomes"| node_campaign_records
node_campaign_job -->|"sends batches"| node_whatsapp_service
node_whatsapp_service -->|"Cloud API"| node_meta
node_meta -->|"inbound/status webhooks"| node_webhook_controller
node_webhook_controller -->|"normalizes payload"| node_whatsapp_service
node_webhook_controller -->|"emits"| node_message_event
node_message_event -->|"broadcasts via"| node_realtime
node_campaign_records -->|"persists in"| node_data_runtime
node_tenant_domain -->|"persists in"| node_data_runtime
node_campaign_job -->|"consumes queue"| node_data_runtime

click node_spa_entry "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/main.jsx"
click node_app_shell "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/App.jsx"
click node_auth_state "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/context/AuthContext.jsx"
click node_api_client "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/services/api.js"
click node_operations_ui "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/pages/Inbox.jsx"
click node_campaigns_ui "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/pages/Campaigns.jsx"
click node_flow_builder "https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/pages/FlowBuilder.jsx"
click node_laravel_entry "https://github.com/royal300/whatsapp_panel/blob/main/backend/public/index.php"
click node_api_routes "https://github.com/royal300/whatsapp_panel/blob/main/backend/routes/api.php"
click node_access_control "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Http/Middleware/RoleMiddleware.php"
click node_tenant_domain "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Models/Tenant.php"
click node_webhook_controller "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Http/Controllers/WebhookController.php"
click node_whatsapp_service "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Services/WhatsAppService.php"
click node_automation_ai "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Services/AutomationService.php"
click node_billing "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Services/BillingService.php"
click node_campaign_job "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Jobs/ProcessCampaignJob.php"
click node_campaign_records "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Models/CampaignLog.php"
click node_message_event "https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Events/MessageReceived.php"
click node_data_runtime "https://github.com/royal300/whatsapp_panel/blob/main/backend/config/database.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa_entry,node_app_shell,node_auth_state,node_api_client,node_operations_ui,node_campaigns_ui,node_flow_builder toneBlue
class node_laravel_entry,node_api_routes,node_access_control,node_tenant_domain,node_webhook_controller,node_whatsapp_service,node_automation_ai,node_billing toneAmber
class node_campaign_job,node_campaign_records,node_message_event,node_data_runtime toneMint
class node_meta,node_realtime toneRose
```

## Components

### React SPA

- [SPA entry](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/main.jsx): React bootstrap · `frontend/src/main.jsx`
- [App shell & routes](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/App.jsx): React composition · Authenticated navigation and operational screen routing. · `frontend/src/App.jsx`
- [Auth state](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/context/AuthContext.jsx): React context · `frontend/src/context/AuthContext.jsx`
- [API client](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/services/api.js): HTTP service · `frontend/src/services/api.js`
- [Operations UI](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/pages/Inbox.jsx): Inbox, campaigns & flows · Client workflows for messaging, campaigns, and automation design. · `frontend/src/pages/Inbox.jsx`
- [Campaigns UI](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/pages/Campaigns.jsx): Campaign workflow · `frontend/src/pages/Campaigns.jsx`
- [Flow builder](https://github.com/royal300/whatsapp_panel/blob/main/frontend/src/pages/FlowBuilder.jsx): Automation workflow · `frontend/src/pages/FlowBuilder.jsx`

### Laravel API

- [Laravel runtime](https://github.com/royal300/whatsapp_panel/blob/main/backend/public/index.php): PHP API entry · `backend/public/index.php`
- [API routes & controllers](https://github.com/royal300/whatsapp_panel/blob/main/backend/routes/api.php): Laravel HTTP boundary · Tenant-scoped domain operations exposed to the SPA. · `backend/routes/api.php`
- [Token auth & roles](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Http/Middleware/RoleMiddleware.php): Sanctum and middleware · Token authentication with privileged-route role gating. · `backend/app/Http/Middleware/RoleMiddleware.php`
- [Tenant & subscription domain](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Models/Tenant.php): SaaS ownership model · Tenants own users, credentials, plans, subscriptions, and feature access. · `backend/app/Models/Tenant.php`
- [Webhook controller](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Http/Controllers/WebhookController.php): Meta webhook endpoint · `backend/app/Http/Controllers/WebhookController.php`
- [WhatsApp service](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Services/WhatsAppService.php): Meta integration · Normalizes outbound and inbound Cloud API interaction. · `backend/app/Services/WhatsAppService.php`
- [Automation & AI](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Services/AutomationService.php): Domain services · Keyword/autoresponder orchestration and AI quick replies. · `backend/app/Services/AutomationService.php`
- [Billing service](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Services/BillingService.php): Commercial service · `backend/app/Services/BillingService.php`

### Async & realtime

- [Campaign processor](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Jobs/ProcessCampaignJob.php): Queued job · Processes audience sends outside the request lifecycle. · `backend/app/Jobs/ProcessCampaignJob.php`
- [Campaigns & send logs](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Models/CampaignLog.php): Campaign persistence · Campaign content, audiences, media/templates, and delivery outcomes. · `backend/app/Models/CampaignLog.php`
- [Message received event](https://github.com/royal300/whatsapp_panel/blob/main/backend/app/Events/MessageReceived.php): Broadcast event · Triggers realtime message delivery to clients. · `backend/app/Events/MessageReceived.php`
- [MySQL, queue & cache](https://github.com/royal300/whatsapp_panel/blob/main/backend/config/database.php): Laravel infrastructure · `backend/config/database.php`

### External services

- **Meta WhatsApp Cloud API**: External messaging platform
- **Pusher / broadcast**: Realtime provider · Optional realtime transport; polling remains a frontend fallback.

## Connections

- SPA entry → App shell & routes
- App shell & routes → Auth state: uses
- App shell & routes → Operations UI: renders
- App shell & routes → Campaigns UI: renders
- App shell & routes → Flow builder: renders
- Operations UI → API client: calls through
- Campaigns UI → API client: calls through
- Flow builder → API client: calls through
- API client → API routes & controllers: HTTPS API
- Laravel runtime → API routes & controllers: boots
- API routes & controllers → Token auth & roles: enforces
- API routes & controllers → Tenant & subscription domain: scopes data
- API routes & controllers → Campaign processor: queues campaigns
- API routes & controllers → Automation & AI: configures rules
- API routes & controllers → Billing service: manages plans
- Campaign processor → Campaigns & send logs: records outcomes
- Campaign processor → WhatsApp service: sends batches
- WhatsApp service → Meta WhatsApp Cloud API: Cloud API
- Meta WhatsApp Cloud API → Webhook controller: inbound/status webhooks
- Webhook controller → WhatsApp service: normalizes payload
- Webhook controller → Message received event: emits
- Message received event → Pusher / broadcast: broadcasts via
- Campaigns & send logs → MySQL, queue & cache: persists in
- Tenant & subscription domain → MySQL, queue & cache: persists in
- Campaign processor → MySQL, queue & cache: consumes queue
