How royal300/whatsapp_panel works
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: api.php API routes & controllers · App.jsx App shell & routes · ProcessCampaignJob.php Campaign processor · api.js API client
Components 21
React SPA
- SPA entry
frontend/src/main.jsx - App shell & routes · Authenticated navigation and operational screen routing.
frontend/src/App.jsx - Auth state
frontend/src/context/AuthContext.jsx - API client
frontend/src/services/api.js - Operations UI · Client workflows for messaging, campaigns, and automation design.
frontend/src/pages/Inbox.jsx - Campaigns UI
frontend/src/pages/Campaigns.jsx - Flow builder
frontend/src/pages/FlowBuilder.jsx
Laravel API
- Laravel runtime
backend/public/index.php - API routes & controllers · Tenant-scoped domain operations exposed to the SPA.
backend/routes/api.php - Token auth & roles · Token authentication with privileged-route role gating.
backend/app/Http/Middleware/RoleMiddleware.php - Tenant & subscription domain · Tenants own users, credentials, plans, subscriptions, and feature access.
backend/app/Models/Tenant.php - Webhook controller
backend/app/Http/Controllers/WebhookController.php - WhatsApp service · Normalizes outbound and inbound Cloud API interaction.
backend/app/Services/WhatsAppService.php - Automation & AI · Keyword/autoresponder orchestration and AI quick replies.
backend/app/Services/AutomationService.php - Billing service
backend/app/Services/BillingService.php
Async & realtime
- Campaign processor · Processes audience sends outside the request lifecycle.
backend/app/Jobs/ProcessCampaignJob.php - Campaigns & send logs · Campaign content, audiences, media/templates, and delivery outcomes.
backend/app/Models/CampaignLog.php - Message received event · Triggers realtime message delivery to clients.
backend/app/Events/MessageReceived.php - MySQL, queue & cache
backend/config/database.php
External services
- Meta WhatsApp Cloud API
- Pusher / broadcast · Optional realtime transport; polling remains a frontend fallback.
Connections 25
- 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