# kanna-sakthi27/whatsapp-ai-autoreply architecture

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

- Interactive diagram: https://gitdiagram.com/kanna-sakthi27/whatsapp-ai-autoreply
- Repository: https://github.com/kanna-sakthi27/whatsapp-ai-autoreply

## Overview

WhatsApp AI Auto-Reply receives WAHA webhooks, filters incoming messages, generates replies with a configured local or cloud LLM, then applies outgoing safeguards and can hold replies for human approval before sending. The FastAPI service also exposes message history, statistics, settings, and logs to a React dashboard. The README documents the overall webhook-to-reply flow and dashboard capabilities; source excerpts confirm selected backend storage and frontend API relationships, but do not expose the full webhook handler implementation.

Main entry points: [`ai_service/main.py`](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/main.py) (FastAPI Webhooks), [`frontend/src/App.jsx`](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/App.jsx) (Dashboard App), [`frontend/src/api/client.js`](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/api/client.js) (API Client), [`frontend/src/components/ApprovalQueue.jsx`](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/ApprovalQueue.jsx) (Approval UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_messaging["WhatsApp Processing"]
end

subgraph group_service["AI Service"]
  node_api["FastAPI Webhooks<br/>[main.py]"]
  node_guard["Guard Rails<br/>[guard_rails.py]"]
  node_approval["Approval Queue<br/>[main.py]"]
end

subgraph group_data["Service Data"]
  node_history[("Message History<br/>[message_history.py]")]
  node_logs[("Log Store<br/>[logs_store.py]")]
end

subgraph group_dashboard["Admin Dashboard"]
  node_dashboard["Dashboard App<br/>[App.jsx]"]
  node_api_client["API Client<br/>[client.js]"]
  node_messages["Message History UI<br/>[MessageList.jsx]"]
  node_send["Manual Send UI<br/>[SendMessage.jsx]"]
  node_approvals["Approval UI<br/>[ApprovalQueue.jsx]"]
  node_provider_config["Provider Settings UI"]
  node_guard_config["Guard Settings UI"]
  node_general_config["General Settings UI"]
  node_logs_ui["Log Viewer UI<br/>[LogViewer.jsx]"]
  node_status_ui["Connection Status UI"]
  node_stats_ui["Statistics UI<br/>[StatsCards.jsx]"]
end

node_whatsapp(("WhatsApp"))
node_waha["WAHA API"]
node_llm["Ollama / OpenAI"]
node_human(("Operator"))

node_whatsapp -->|"sends messages"| node_waha
node_waha -->|"posts webhook"| node_api
node_api -->|"filters messages"| node_guard
node_api -->|"requests replies"| node_llm
node_api -.->|"queues review"| node_approval
node_human -->|"reviews replies"| node_approvals
node_approvals -->|"submits decisions"| node_api_client
node_api -->|"sends replies"| node_waha
node_api -->|"stores messages"| node_history
node_api -->|"reads logs"| node_logs
node_dashboard -->|"routes to"| node_messages
node_dashboard -->|"routes to"| node_send
node_dashboard -->|"routes to"| node_approvals
node_dashboard -->|"routes to"| node_provider_config
node_dashboard -->|"routes to"| node_guard_config
node_dashboard -->|"routes to"| node_general_config
node_dashboard -->|"routes to"| node_logs_ui
node_dashboard -->|"routes to"| node_status_ui
node_dashboard -->|"renders"| node_stats_ui
node_messages -->|"requests history"| node_api_client
node_send -->|"submits message"| node_api_client
node_provider_config -->|"updates provider"| node_api_client
node_guard_config -->|"updates guards"| node_api_client
node_general_config -->|"updates settings"| node_api_client
node_logs_ui -->|"fetches logs"| node_api_client
node_status_ui -->|"checks status"| node_api_client
node_api_client -->|"calls REST API"| node_api
node_api -.->|"serves history"| node_history
node_api -->|"serves log data"| node_logs

click node_api "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/main.py"
click node_guard "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/guard_rails.py"
click node_approval "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/main.py"
click node_history "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/message_history.py"
click node_logs "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/logs_store.py"
click node_dashboard "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/App.jsx"
click node_api_client "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/api/client.js"
click node_messages "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/MessageList.jsx"
click node_send "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/SendMessage.jsx"
click node_approvals "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/ApprovalQueue.jsx"
click node_provider_config "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/AIProviderConfig.jsx"
click node_guard_config "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/GuardRailsConfig.jsx"
click node_general_config "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/GeneralSettings.jsx"
click node_logs_ui "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/LogViewer.jsx"
click node_status_ui "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/ConnectionStatus.jsx"
click node_stats_ui "https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/StatsCards.jsx"

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_api,node_guard,node_approval toneAmber
class node_history,node_logs,node_waha toneMint
class node_dashboard,node_api_client,node_messages,node_send,node_approvals,node_provider_config,node_guard_config,node_general_config,node_logs_ui,node_status_ui,node_stats_ui toneRose
class node_whatsapp,node_llm,node_human toneIndigo
```

## Components

### AI Service

- [FastAPI Webhooks](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/main.py): `ai_service/main.py`
- [Guard Rails](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/guard_rails.py): `ai_service/guard_rails.py`
- [Approval Queue](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/main.py): `ai_service/main.py`

### Service Data

- [Message History](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/message_history.py): `ai_service/message_history.py`
- [Log Store](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/ai_service/logs_store.py): `ai_service/logs_store.py`

### Admin Dashboard

- [Dashboard App](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [API Client](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`
- [Message History UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/MessageList.jsx): `frontend/src/components/MessageList.jsx`
- [Manual Send UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/SendMessage.jsx): `frontend/src/components/SendMessage.jsx`
- [Approval UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/ApprovalQueue.jsx): `frontend/src/components/ApprovalQueue.jsx`
- [Provider Settings UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/AIProviderConfig.jsx): `frontend/src/components/AIProviderConfig.jsx`
- [Guard Settings UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/GuardRailsConfig.jsx): `frontend/src/components/GuardRailsConfig.jsx`
- [General Settings UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/GeneralSettings.jsx): `frontend/src/components/GeneralSettings.jsx`
- [Log Viewer UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/LogViewer.jsx): `frontend/src/components/LogViewer.jsx`
- [Connection Status UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/ConnectionStatus.jsx): `frontend/src/components/ConnectionStatus.jsx`
- [Statistics UI](https://github.com/kanna-sakthi27/whatsapp-ai-autoreply/blob/main/frontend/src/components/StatsCards.jsx): `frontend/src/components/StatsCards.jsx`

### Other components

- **WhatsApp**
- **WAHA API**
- **Ollama / OpenAI**
- **Operator**

## Connections

- WhatsApp → WAHA API: sends messages (evidence: `README.md`)
- WAHA API → FastAPI Webhooks: posts webhook (evidence: `README.md`)
- FastAPI Webhooks → Guard Rails: filters messages (evidence: `ai_service/main.py`)
- FastAPI Webhooks → Ollama / OpenAI: requests replies (evidence: `README.md`)
- FastAPI Webhooks → Approval Queue: queues review (evidence: `ai_service/main.py`)
- Operator → Approval UI: reviews replies (evidence: `README.md`)
- Approval UI → API Client: submits decisions (evidence: `frontend/src/components/ApprovalQueue.jsx`)
- FastAPI Webhooks → WAHA API: sends replies (evidence: `README.md`)
- FastAPI Webhooks → Message History: stores messages (evidence: `ai_service/main.py`)
- FastAPI Webhooks → Log Store: reads logs (evidence: `ai_service/main.py`)
- Dashboard App → Message History UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Manual Send UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Approval UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Provider Settings UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Guard Settings UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → General Settings UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Log Viewer UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Connection Status UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard App → Statistics UI: renders (evidence: `frontend/src/App.jsx`)
- Message History UI → API Client: requests history (evidence: `frontend/src/components/MessageList.jsx`)
- Manual Send UI → API Client: submits message (evidence: `frontend/src/components/SendMessage.jsx`)
- Provider Settings UI → API Client: updates provider (evidence: `frontend/src/components/AIProviderConfig.jsx`)
- Guard Settings UI → API Client: updates guards (evidence: `frontend/src/components/GuardRailsConfig.jsx`)
- General Settings UI → API Client: updates settings (evidence: `frontend/src/components/GeneralSettings.jsx`)
- Log Viewer UI → API Client: fetches logs (evidence: `frontend/src/components/LogViewer.jsx`)
- Connection Status UI → API Client: checks status (evidence: `frontend/src/components/ConnectionStatus.jsx`)
- API Client → FastAPI Webhooks: calls REST API (evidence: `README.md`)
- FastAPI Webhooks → Message History: serves history (evidence: `ai_service/main.py`)
- FastAPI Webhooks → Log Store: serves log data (evidence: `ai_service/main.py`)
