# ananth-madura/madhura_wa architecture

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

- Interactive diagram: https://gitdiagram.com/ananth-madura/madhura_wa
- Repository: https://github.com/ananth-madura/madhura_wa

## Overview

Whatsapp_CRM is a standalone WhatsApp customer-engagement service with an Express/Socket.IO backend and React frontend. Users log in, open the WhatsApp workspace, manage conversations or configure campaigns and flows, then the backend routes requests to session or Cloud API services and persists state in MySQL. Separate capabilities cover contacts, templates, automation, reminders, analytics, and AI. The graph emphasizes documented route mounting and indexed module references; several route and frontend implementations were not sampled, so their internal connections are omitted.

Main entry points: [`backend/server.js`](https://github.com/ananth-madura/madhura_wa/blob/main/backend/server.js) (Express API), [`backend/services/waFlowEngine.js`](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waFlowEngine.js) (Conversation flows), [`backend/services/waAutomationService.js`](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waAutomationService.js) (Automation engine), [`backend/services/whatsappService.js`](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/whatsappService.js) (WhatsApp sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["React application<br/>[App.js]"]
  node_inbox["Inbox workspace<br/>[whatsapp.jsx]"]
  node_feature_pages["Feature pages"]
  node_campaign_ui["Campaign wizard"]
  node_reminder_ui["Reminder controls"]
end

subgraph group_entry["API and sessions"]
  node_api["Express API<br/>[server.js]"]
  node_auth["Login and access<br/>[authRoutes.js]"]
  node_auth_middleware["Token validation<br/>[authMiddleware.js]"]
  node_wa_routes["WhatsApp routes<br/>[whatsappRoutes.js]"]
end

subgraph group_messaging["Messaging engines"]
  node_wa_service["WhatsApp sessions<br/>[whatsappService.js]"]
  node_cloud_api["Cloud API"]
  node_load_balancer["Sender selection<br/>[waLoadBalancer.js]"]
end

subgraph group_engagement["Engagement features"]
  node_campaign_routes["Campaign routes"]
  node_flow_routes["Flow routes<br/>[waFlowRoutes.js]"]
  node_automation_routes["Automation routes"]
  node_reminder_routes["Reminder routes"]
  node_other_routes["Other WA routes"]
  node_campaign_engine["Campaign engine"]
  node_flow_engine["Conversation flows<br/>[waFlowEngine.js]"]
  node_automation["Automation engine"]
  node_bot_gate["Bot gating<br/>[waBotGate.js]"]
  node_menu["Interactive menus<br/>[waMenuHandler.js]"]
  node_lead_capture["Lead capture<br/>[waLeadCapture.js]"]
  node_confirmation["Confirmations"]
end

subgraph group_state["Persistence and events"]
  node_database[("MySQL database<br/>[database.js]")]
  node_wa_database["WA schema<br/>[waDatabase.js]"]
  node_notifications["Live notifications<br/>[notifications.js]"]
  node_crm_events["CRM event bus<br/>[crmEventBus.js]"]
end

node_user(("WhatsApp user"))

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_inbox
node_app -->|"routes to"| node_feature_pages
node_inbox -->|"requests data"| node_api
node_campaign_ui -.->|"configures"| node_campaign_routes
node_reminder_ui -.->|"configures"| node_reminder_routes
node_api -->|"mounts"| node_auth
node_api -->|"mounts"| node_wa_routes
node_api -->|"mounts"| node_campaign_routes
node_api -->|"mounts"| node_flow_routes
node_api -->|"mounts"| node_automation_routes
node_api -->|"mounts"| node_reminder_routes
node_api -->|"mounts"| node_other_routes
node_wa_routes -->|"validates"| node_auth_middleware
node_auth -->|"reads users"| node_database
node_campaign_routes -->|"starts campaigns"| node_campaign_engine
node_campaign_engine -->|"selects sender"| node_load_balancer
node_load_balancer -->|"sends via session"| node_wa_service
node_load_balancer -->|"sends via cloud"| node_cloud_api
node_flow_routes -->|"triggers flow"| node_flow_engine
node_automation_routes -->|"manages automations"| node_automation
node_wa_service -->|"dispatches messages"| node_flow_engine
node_wa_service -->|"dispatches triggers"| node_automation
node_automation -->|"checks gate"| node_bot_gate
node_automation -->|"sends messages"| node_load_balancer
node_flow_engine -->|"checks gate"| node_bot_gate
node_flow_engine -->|"captures leads"| node_lead_capture
node_flow_engine -->|"uses menus"| node_menu
node_reminder_routes -->|"handles reminders"| node_confirmation
node_confirmation -->|"triggers follow-ups"| node_automation
node_wa_database -->|"creates WA tables"| node_database
node_campaign_engine -->|"records sends"| node_database
node_flow_engine -->|"stores flow state"| node_database
node_wa_service -->|"emits updates"| node_notifications
node_lead_capture -->|"publishes leads"| node_crm_events
node_api -->|"starts sweep"| node_crm_events

click node_app "https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/App.js"
click node_inbox "https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/pages/whatsapp.jsx"
click node_feature_pages "https://github.com/ananth-madura/madhura_wa/tree/main/frontend/src/pages"
click node_campaign_ui "https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/components/WhatsAppCampaignWizard.jsx"
click node_reminder_ui "https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/components/WhatsAppInteractiveReminders.jsx"
click node_api "https://github.com/ananth-madura/madhura_wa/blob/main/backend/server.js"
click node_auth "https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/authRoutes.js"
click node_auth_middleware "https://github.com/ananth-madura/madhura_wa/blob/main/backend/middleware/authMiddleware.js"
click node_wa_routes "https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/whatsappRoutes.js"
click node_campaign_routes "https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waCampaignRoutes.js"
click node_flow_routes "https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waFlowRoutes.js"
click node_automation_routes "https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waAutomationRoutes.js"
click node_reminder_routes "https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waReminderRoutes.js"
click node_other_routes "https://github.com/ananth-madura/madhura_wa/tree/main/backend/routes"
click node_wa_service "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/whatsappService.js"
click node_cloud_api "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/whatsappCloudApi.js"
click node_load_balancer "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waLoadBalancer.js"
click node_campaign_engine "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waCampaignEngine.js"
click node_flow_engine "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waFlowEngine.js"
click node_automation "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waAutomationService.js"
click node_bot_gate "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waBotGate.js"
click node_menu "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waMenuHandler.js"
click node_lead_capture "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waLeadCapture.js"
click node_confirmation "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waConfirmationService.js"
click node_database "https://github.com/ananth-madura/madhura_wa/blob/main/backend/config/database.js"
click node_wa_database "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waDatabase.js"
click node_notifications "https://github.com/ananth-madura/madhura_wa/blob/main/backend/sockets/notifications.js"
click node_crm_events "https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/crmEventBus.js"

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_app,node_inbox,node_feature_pages,node_campaign_ui,node_reminder_ui,node_user toneBlue
class node_api,node_auth,node_auth_middleware,node_wa_routes toneAmber
class node_wa_service,node_cloud_api,node_load_balancer toneMint
class node_campaign_routes,node_flow_routes,node_automation_routes,node_reminder_routes,node_other_routes,node_campaign_engine,node_flow_engine,node_automation,node_bot_gate,node_menu,node_lead_capture,node_confirmation toneRose
class node_database,node_wa_database,node_notifications,node_crm_events toneIndigo
```

## Components

### Web client

- [React application](https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/App.js): `frontend/src/App.js`
- [Inbox workspace](https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/pages/whatsapp.jsx): `frontend/src/pages/whatsapp.jsx`
- [Feature pages](https://github.com/ananth-madura/madhura_wa/tree/main/frontend/src/pages): `frontend/src/pages`
- [Campaign wizard](https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/components/WhatsAppCampaignWizard.jsx): `frontend/src/components/WhatsAppCampaignWizard.jsx`
- [Reminder controls](https://github.com/ananth-madura/madhura_wa/blob/main/frontend/src/components/WhatsAppInteractiveReminders.jsx): `frontend/src/components/WhatsAppInteractiveReminders.jsx`

### API and sessions

- [Express API](https://github.com/ananth-madura/madhura_wa/blob/main/backend/server.js): `backend/server.js`
- [Login and access](https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Token validation](https://github.com/ananth-madura/madhura_wa/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [WhatsApp routes](https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/whatsappRoutes.js): `backend/routes/whatsappRoutes.js`

### Messaging engines

- [WhatsApp sessions](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/whatsappService.js): `backend/services/whatsappService.js`
- [Cloud API](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/whatsappCloudApi.js): `backend/services/whatsappCloudApi.js`
- [Sender selection](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waLoadBalancer.js): `backend/services/waLoadBalancer.js`

### Engagement features

- [Campaign routes](https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waCampaignRoutes.js): `backend/routes/waCampaignRoutes.js`
- [Flow routes](https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waFlowRoutes.js): `backend/routes/waFlowRoutes.js`
- [Automation routes](https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waAutomationRoutes.js): `backend/routes/waAutomationRoutes.js`
- [Reminder routes](https://github.com/ananth-madura/madhura_wa/blob/main/backend/routes/waReminderRoutes.js): `backend/routes/waReminderRoutes.js`
- [Other WA routes](https://github.com/ananth-madura/madhura_wa/tree/main/backend/routes): `backend/routes`
- [Campaign engine](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waCampaignEngine.js): `backend/services/waCampaignEngine.js`
- [Conversation flows](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waFlowEngine.js): `backend/services/waFlowEngine.js`
- [Automation engine](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waAutomationService.js): `backend/services/waAutomationService.js`
- [Bot gating](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waBotGate.js): `backend/services/waBotGate.js`
- [Interactive menus](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waMenuHandler.js): `backend/services/waMenuHandler.js`
- [Lead capture](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waLeadCapture.js): `backend/services/waLeadCapture.js`
- [Confirmations](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waConfirmationService.js): `backend/services/waConfirmationService.js`

### Persistence and events

- [MySQL database](https://github.com/ananth-madura/madhura_wa/blob/main/backend/config/database.js): `backend/config/database.js`
- [WA schema](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/waDatabase.js): `backend/services/waDatabase.js`
- [Live notifications](https://github.com/ananth-madura/madhura_wa/blob/main/backend/sockets/notifications.js): `backend/sockets/notifications.js`
- [CRM event bus](https://github.com/ananth-madura/madhura_wa/blob/main/backend/services/crmEventBus.js): `backend/services/crmEventBus.js`

### Other components

- **WhatsApp user**

## Connections

- WhatsApp user → React application: uses (evidence: `README.md`)
- React application → Inbox workspace: routes to (evidence: `frontend/src/App.js`)
- React application → Feature pages: routes to (evidence: `frontend/src/App.js`)
- Inbox workspace → Express API: requests data (evidence: `README.md`)
- Campaign wizard → Campaign routes: configures
- Reminder controls → Reminder routes: configures
- Express API → Login and access: mounts (evidence: `backend/server.js`)
- Express API → WhatsApp routes: mounts (evidence: `backend/server.js`)
- Express API → Campaign routes: mounts (evidence: `README.md`)
- Express API → Flow routes: mounts (evidence: `backend/server.js`)
- Express API → Automation routes: mounts (evidence: `backend/server.js`)
- Express API → Reminder routes: mounts (evidence: `README.md`)
- Express API → Other WA routes: mounts (evidence: `README.md`)
- WhatsApp routes → Token validation: validates (evidence: `backend/server.js`)
- Login and access → MySQL database: reads users (evidence: `backend/routes/authRoutes.js`)
- Campaign routes → Campaign engine: starts campaigns (evidence: `backend/routes/waCampaignRoutes.js`)
- Campaign engine → Sender selection: selects sender (evidence: `backend/services/waCampaignEngine.js`)
- Sender selection → WhatsApp sessions: sends via session (evidence: `backend/services/waLoadBalancer.js`)
- Sender selection → Cloud API: sends via cloud (evidence: `backend/services/waLoadBalancer.js`)
- Flow routes → Conversation flows: triggers flow (evidence: `backend/routes/waFlowRoutes.js`)
- Automation routes → Automation engine: manages automations (evidence: `backend/routes/waAutomationRoutes.js`)
- WhatsApp sessions → Conversation flows: dispatches messages (evidence: `backend/services/whatsappService.js`)
- WhatsApp sessions → Automation engine: dispatches triggers (evidence: `backend/services/whatsappService.js`)
- Automation engine → Bot gating: checks gate (evidence: `backend/services/waAutomationService.js`)
- Automation engine → Sender selection: sends messages (evidence: `backend/services/waAutomationService.js`)
- Conversation flows → Bot gating: checks gate (evidence: `backend/services/waFlowEngine.js`)
- Conversation flows → Lead capture: captures leads (evidence: `backend/services/waFlowEngine.js`)
- Conversation flows → Interactive menus: uses menus (evidence: `backend/services/waFlowEngine.js`)
- Reminder routes → Confirmations: handles reminders (evidence: `backend/routes/waReminderRoutes.js`)
- Confirmations → Automation engine: triggers follow-ups (evidence: `backend/services/waConfirmationService.js`)
- WA schema → MySQL database: creates WA tables (evidence: `backend/services/waDatabase.js`)
- Campaign engine → MySQL database: records sends (evidence: `backend/services/waCampaignEngine.js`)
- Conversation flows → MySQL database: stores flow state (evidence: `backend/services/waFlowEngine.js`)
- WhatsApp sessions → Live notifications: emits updates (evidence: `backend/services/whatsappService.js`)
- Lead capture → CRM event bus: publishes leads (evidence: `backend/services/waLeadCapture.js`)
- Express API → CRM event bus: starts sweep (evidence: `backend/server.js`)
