# codevix26/whatsapp-ai-auto-reply-bot architecture

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

- Interactive diagram: https://gitdiagram.com/codevix26/whatsapp-ai-auto-reply-bot
- Repository: https://github.com/codevix26/whatsapp-ai-auto-reply-bot

## Overview

This is a WhatsApp auto-reply bot: startup validates configuration and launches the WhatsApp session; incoming text is passed to the AI reply function, which combines a configurable system prompt with the message and requests a completion from OpenRouter; the reply is sent back and the exchange is logged. The README also documents QR login and prompt customization. Relationships below are based on the README and the sampled source; the local session and log storage are implemented in the WhatsApp module, and no separate storage file appears in the tree.

Main entry points: [`app/src/whatsapp/whatsapp.js`](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js) (WhatsApp Session), [`app/src/ai/ai.js`](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/ai/ai.js) (AI Reply Service), [`app/index.js`](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/index.js) (Startup & Config), [`app/src/ai/SystemPrompt.js`](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/ai/SystemPrompt.js) (System Prompt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot Runtime"]
  node_startup["Startup &amp; Config<br/>[index.js]"]
end

subgraph group_whatsapp["WhatsApp Messaging"]
  node_session["WhatsApp Session<br/>[whatsapp.js]"]
  node_message_handler["Incoming Message Handler<br/>[whatsapp.js]"]
  node_qr_login["QR Login<br/>[whatsapp.js]"]
  node_local_state[("Session &amp; Log Storage<br/>[whatsapp.js]")]
end

subgraph group_ai["AI Replies"]
  node_prompt["System Prompt<br/>[SystemPrompt.js]"]
  node_reply_service["AI Reply Service<br/>[ai.js]"]
end

node_user(("WhatsApp User"))
node_openrouter{{"OpenRouter"}}
node_whatsapp_platform{{"WhatsApp"}}
node_terminal["Terminal"]

node_startup -->|"starts"| node_session
node_user -->|"sends message"| node_whatsapp_platform
node_whatsapp_platform -->|"delivers events"| node_session
node_session -->|"renders QR"| node_qr_login
node_qr_login -->|"prints code"| node_terminal
node_session -->|"loads and saves"| node_local_state
node_session -->|"registers handler"| node_message_handler
node_message_handler -->|"requests reply"| node_reply_service
node_reply_service -->|"builds prompt"| node_prompt
node_reply_service -->|"requests completion"| node_openrouter
node_reply_service -->|"returns reply"| node_message_handler
node_message_handler -->|"sends reply"| node_whatsapp_platform
node_message_handler -->|"writes log"| node_local_state

click node_startup "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/index.js"
click node_session "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js"
click node_message_handler "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js"
click node_qr_login "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js"
click node_local_state "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js"
click node_prompt "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/ai/SystemPrompt.js"
click node_reply_service "https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/ai/ai.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_startup,node_user toneBlue
class node_session,node_message_handler,node_qr_login,node_local_state toneAmber
class node_prompt,node_reply_service,node_openrouter toneMint
class node_whatsapp_platform,node_terminal toneIndigo
```

## Components

### Bot Runtime

- [Startup & Config](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/index.js): `app/index.js`

### WhatsApp Messaging

- [WhatsApp Session](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js): `app/src/whatsapp/whatsapp.js`
- [Incoming Message Handler](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js): `app/src/whatsapp/whatsapp.js`
- [QR Login](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js): `app/src/whatsapp/whatsapp.js`
- [Session & Log Storage](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/whatsapp/whatsapp.js): `app/src/whatsapp/whatsapp.js`

### AI Replies

- [System Prompt](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/ai/SystemPrompt.js): `app/src/ai/SystemPrompt.js`
- [AI Reply Service](https://github.com/codevix26/whatsapp-ai-auto-reply-bot/blob/main/app/src/ai/ai.js): `app/src/ai/ai.js`

### Other components

- **WhatsApp User**
- **OpenRouter**
- **WhatsApp**
- **Terminal**

## Connections

- Startup & Config → WhatsApp Session: starts (evidence: `app/index.js`)
- WhatsApp User → WhatsApp: sends message (evidence: `README.md`)
- WhatsApp → WhatsApp Session: delivers events (evidence: `app/src/whatsapp/whatsapp.js`)
- WhatsApp Session → QR Login: renders QR (evidence: `app/src/whatsapp/whatsapp.js`)
- QR Login → Terminal: prints code (evidence: `app/src/whatsapp/whatsapp.js`)
- WhatsApp Session → Session & Log Storage: loads and saves (evidence: `app/src/whatsapp/whatsapp.js`)
- WhatsApp Session → Incoming Message Handler: registers handler (evidence: `app/src/whatsapp/whatsapp.js`)
- Incoming Message Handler → AI Reply Service: requests reply (evidence: `app/src/whatsapp/whatsapp.js`)
- AI Reply Service → System Prompt: builds prompt (evidence: `app/src/ai/ai.js`)
- AI Reply Service → OpenRouter: requests completion (evidence: `app/src/ai/ai.js`)
- AI Reply Service → Incoming Message Handler: returns reply (evidence: `app/src/whatsapp/whatsapp.js`)
- Incoming Message Handler → WhatsApp: sends reply (evidence: `app/src/whatsapp/whatsapp.js`)
- Incoming Message Handler → Session & Log Storage: writes log (evidence: `app/src/whatsapp/whatsapp.js`)
