# shahd132/whatsapp-assistant-agent architecture

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

- Interactive diagram: https://gitdiagram.com/shahd132/whatsapp-assistant-agent
- Repository: https://github.com/shahd132/whatsapp-assistant-agent

## Overview

This is a WhatsApp assistant that replies in its owner’s style while holding uncertain or owner-only decisions for approval. Incoming messages pass through the bridge and FastAPI webhook, then media resolution, history/style context, reply generation, and verification before sending or holding. The owner can also manage held replies, controls, message history, and Mika through the dashboard. The sampled sources establish the main agent and webhook calls; some dashboard and approval relationships are documented in the README or SOURCE INDEX rather than shown in full source excerpts.

Main entry points: [`app/main.py`](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/main.py) (Webhook policy), [`app/agent_graph.py`](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/agent_graph.py) (Agent graph), [`app/dashboard.py`](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/dashboard.py) (Dashboard API), [`app/controls.py`](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/controls.py) (Controls and history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingress["WhatsApp ingress"]
  node_bridge["WhatsApp bridge<br/>[bridge_api.js]"]
  node_webhook["Webhook policy<br/>[main.py]"]
end

subgraph group_reply["Reply pipeline"]
  node_agent["Agent graph<br/>[agent_graph.py]"]
  node_media["Media resolution<br/>[agent_graph.py]"]
  node_speech_recognition["Voice transcription<br/>[stt.py]"]
  node_image_caption["Image captioning<br/>[vision.py]"]
  node_conversation_memory["Conversation memory<br/>[memory.py]"]
  node_style_examples["Style retrieval<br/>[style_retrieval.py]"]
  node_reply_generation["Reply generation<br/>[llm.py]"]
  node_style_exports["Chat export parsing<br/>[export_parser.py]"]
end

subgraph group_owner["Owner dashboard"]
  node_held_approvals["Held approvals<br/>[approvals.py]"]
  node_dashboard_api["Dashboard API<br/>[dashboard.py]"]
  node_dashboard_ui["Dashboard interface<br/>[dashboard.html]"]
  node_mika["Mika assistant<br/>[assistant.py]"]
  node_owner_controls["Controls and history<br/>[controls.py]"]
  node_contacts["Contact directory<br/>[contacts.py]"]
  node_speech_output["Speech synthesis<br/>[tts.py]"]
end

subgraph group_state["State and observability"]
  node_sqlite[("SQLite state<br/>[db.py]")]
  node_event_log["Structured logging<br/>[log.py]"]
end

node_owner_user(("Owner"))
node_whatsapp(("WhatsApp"))

node_whatsapp -->|"exchanges messages"| node_bridge
node_bridge -->|"posts incoming"| node_webhook
node_webhook -->|"processes message"| node_agent
node_webhook -->|"resolves sender"| node_contacts
node_webhook -->|"checks mode; records result"| node_sqlite
node_agent -->|"resolves media"| node_media
node_media -->|"transcribes voice"| node_speech_recognition
node_media -->|"captions image"| node_image_caption
node_agent -->|"loads history"| node_conversation_memory
node_agent -->|"retrieves examples"| node_style_examples
node_agent -->|"generates reply"| node_reply_generation
node_reply_generation -.->|"uses parsed exports"| node_style_exports
node_agent -->|"logs verification"| node_event_log
node_webhook -->|"routes dashboard"| node_held_approvals
node_webhook -->|"registers routes"| node_dashboard_api
node_webhook -->|"registers routes"| node_mika
node_webhook -->|"registers routes"| node_owner_controls
node_webhook -->|"stores messages"| node_conversation_memory
node_webhook -->|"speaks voice replies"| node_speech_output
node_held_approvals -->|"reads and updates holds"| node_sqlite
node_held_approvals -->|"sends approved item"| node_bridge
node_dashboard_ui -->|"uses dashboard routes"| node_dashboard_api
node_dashboard_api -->|"sends text or location"| node_bridge
node_mika -->|"queries messages"| node_sqlite
node_mika -->|"uses control settings"| node_owner_controls
node_owner_controls -->|"reads and changes state"| node_sqlite
node_owner_controls -->|"validates contact"| node_contacts
node_dashboard_api -->|"transcribes dictation"| node_speech_recognition
node_dashboard_api -->|"creates spoken replies"| node_speech_output
node_owner_controls -->|"logs changes"| node_event_log
node_owner_user -->|"operates dashboard"| node_dashboard_ui
node_owner_user -->|"reviews held replies"| node_held_approvals

click node_bridge "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/whatsapp-bridge/bridge_api.js"
click node_webhook "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/main.py"
click node_agent "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/agent_graph.py"
click node_media "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/agent_graph.py"
click node_speech_recognition "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/stt.py"
click node_image_caption "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/vision.py"
click node_conversation_memory "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/memory.py"
click node_style_examples "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/style_retrieval.py"
click node_reply_generation "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/llm.py"
click node_style_exports "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/export_parser.py"
click node_held_approvals "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/approvals.py"
click node_dashboard_api "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/dashboard.py"
click node_dashboard_ui "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/dashboard.html"
click node_mika "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/assistant.py"
click node_owner_controls "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/controls.py"
click node_contacts "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/contacts.py"
click node_speech_output "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/tts.py"
click node_sqlite "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/db.py"
click node_event_log "https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/log.py"

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_bridge,node_webhook toneBlue
class node_agent,node_media,node_speech_recognition,node_image_caption,node_conversation_memory,node_style_examples,node_reply_generation,node_style_exports toneAmber
class node_held_approvals,node_dashboard_api,node_dashboard_ui,node_mika,node_owner_controls,node_contacts,node_speech_output toneMint
class node_sqlite,node_event_log toneRose
class node_owner_user,node_whatsapp toneIndigo
```

## Components

### WhatsApp ingress

- [WhatsApp bridge](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/whatsapp-bridge/bridge_api.js): `whatsapp-bridge/bridge_api.js`
- [Webhook policy](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/main.py): `app/main.py`

### Reply pipeline

- [Agent graph](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/agent_graph.py): `app/agent_graph.py`
- [Media resolution](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/agent_graph.py): `app/agent_graph.py`
- [Voice transcription](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/stt.py): `app/stt.py`
- [Image captioning](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/vision.py): `app/vision.py`
- [Conversation memory](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/memory.py): `app/memory.py`
- [Style retrieval](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/style_retrieval.py): `app/style_retrieval.py`
- [Reply generation](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/llm.py): `app/llm.py`
- [Chat export parsing](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/export_parser.py): `app/export_parser.py`

### Owner dashboard

- [Held approvals](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/approvals.py): `app/approvals.py`
- [Dashboard API](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/dashboard.py): `app/dashboard.py`
- [Dashboard interface](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/dashboard.html): `app/dashboard.html`
- [Mika assistant](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/assistant.py): `app/assistant.py`
- [Controls and history](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/controls.py): `app/controls.py`
- [Contact directory](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/contacts.py): `app/contacts.py`
- [Speech synthesis](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/tts.py): `app/tts.py`

### State and observability

- [SQLite state](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/db.py): `app/db.py`
- [Structured logging](https://github.com/shahd132/whatsapp-assistant-agent/blob/main/app/log.py): `app/log.py`

### Other components

- **Owner**
- **WhatsApp**

## Connections

- WhatsApp → WhatsApp bridge: exchanges messages (evidence: `README.md`)
- WhatsApp bridge → Webhook policy: posts incoming (evidence: `README.md`)
- Webhook policy → Agent graph: processes message (evidence: `app/main.py`)
- Webhook policy → Contact directory: resolves sender (evidence: `app/main.py`)
- Webhook policy → SQLite state: checks mode; records result (evidence: `app/main.py`)
- Agent graph → Media resolution: resolves media (evidence: `app/agent_graph.py`)
- Media resolution → Voice transcription: transcribes voice (evidence: `app/agent_graph.py`)
- Media resolution → Image captioning: captions image (evidence: `app/agent_graph.py`)
- Agent graph → Conversation memory: loads history (evidence: `app/agent_graph.py`)
- Agent graph → Style retrieval: retrieves examples (evidence: `app/agent_graph.py`)
- Agent graph → Reply generation: generates reply (evidence: `app/agent_graph.py`)
- Reply generation → Chat export parsing: uses parsed exports
- Agent graph → Structured logging: logs verification (evidence: `app/agent_graph.py`)
- Webhook policy → Held approvals: routes dashboard (evidence: `app/main.py`)
- Webhook policy → Dashboard API: registers routes (evidence: `app/main.py`)
- Webhook policy → Mika assistant: registers routes (evidence: `app/main.py`)
- Webhook policy → Controls and history: registers routes (evidence: `app/main.py`)
- Webhook policy → Conversation memory: stores messages (evidence: `app/main.py`)
- Webhook policy → Speech synthesis: speaks voice replies (evidence: `app/main.py`)
- Held approvals → SQLite state: reads and updates holds (evidence: `app/approvals.py`)
- Held approvals → WhatsApp bridge: sends approved item (evidence: `README.md`)
- Dashboard interface → Dashboard API: uses dashboard routes (evidence: `README.md`)
- Dashboard API → WhatsApp bridge: sends text or location (evidence: `app/dashboard.py`)
- Mika assistant → SQLite state: queries messages (evidence: `app/assistant.py`)
- Mika assistant → Controls and history: uses control settings (evidence: `app/assistant.py`)
- Controls and history → SQLite state: reads and changes state (evidence: `app/controls.py`)
- Controls and history → Contact directory: validates contact (evidence: `app/controls.py`)
- Dashboard API → Voice transcription: transcribes dictation (evidence: `app/dashboard.py`)
- Dashboard API → Speech synthesis: creates spoken replies (evidence: `app/dashboard.py`)
- Controls and history → Structured logging: logs changes (evidence: `app/controls.py`)
- Owner → Dashboard interface: operates dashboard (evidence: `README.md`)
- Owner → Held approvals: reviews held replies (evidence: `README.md`)
