# wangrongding/wechat-bot architecture

> Architecture diagram of the GitHub repository wangrongding/wechat-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wangrongding/wechat-bot
- Repository: https://github.com/wangrongding/wechat-bot

## Overview

WeChat Bot is a command-line IM agent and local-WeChat analysis tool. Its main reply flow is an IM event through a channel agent, optional message capture, a selected AI service, and a reply sent back through that channel. Separate workflows operate Lark messages, invoke OpenCLI for local WeChat data, and analyze chat data with statistics or AI. The README documents these capabilities, but most platform-agent and analysis implementations were not sampled, so their internal call wiring is shown only where documented or evidenced by the CLI excerpt.

Main entry points: [`src`](https://github.com/wangrongding/wechat-bot/tree/main/src) (Reply service dispatch), [`src/index.js`](https://github.com/wangrongding/wechat-bot/blob/main/src/index.js) (CLI commands), [`src/adapters`](https://github.com/wangrongding/wechat-bot/tree/main/src/adapters) (IM APIs), [`src/platforms/wechat/bot.js`](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/wechat/bot.js) (WeChat agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command entry"]
  node_cli["CLI commands<br/>[index.js]"]
  node_config["Runtime config<br/>[env.js]"]
end

subgraph group_channels["IM channels"]
  node_wechat["WeChat agent<br/>[bot.js]"]
  node_wechatstore[("WeChat message store<br/>[messageStore.js]")]
  node_larkagent["Lark agent<br/>[agent.js]"]
  node_larkstore[("Lark message store<br/>[messageStore.js]")]
  node_telegramagent["Telegram agent<br/>[agent.js]"]
  node_telegramstore[("Telegram message store<br/>[messageStore.js]")]
  node_whatsappagent["WhatsApp agent<br/>[agent.js]"]
  node_whatsappstore[("WhatsApp message store<br/>[messageStore.js]")]
  node_imservices["IM APIs"]
  node_larkops["Lark operations<br/>[lark.js]"]
end

subgraph group_ai["AI services"]
  node_providerdispatch["Reply service dispatch"]
  node_providers["Model providers"]
end

subgraph group_local["Local data"]
  node_opencli["OpenCLI adapter<br/>[opencli.js]"]
  node_analyzer["Chat analyzer<br/>[wechatAnalyzer.js]"]
end

node_user(("User"))
node_imusers(("IM users"))
node_modelservices["Model APIs"]
node_wxcli["Local WeChat tools"]
node_localdata[("Local chat data")]
node_larkapi["Lark API"]
node_telegramapi["Telegram Bot API"]
node_whatsappapi["WhatsApp Cloud API"]

node_user -->|"runs commands"| node_cli
node_cli -->|"loads settings"| node_config
node_cli -->|"starts agent"| node_wechat
node_cli -->|"starts agent"| node_larkagent
node_cli -->|"starts agent"| node_telegramagent
node_cli -->|"starts agent"| node_whatsappagent
node_cli -->|"invokes operations"| node_larkops
node_cli -->|"runs local tools"| node_opencli
node_cli -->|"requests analysis"| node_analyzer
node_wechat -->|"requests reply"| node_providerdispatch
node_larkagent -->|"requests reply"| node_providerdispatch
node_telegramagent -->|"requests reply"| node_providerdispatch
node_whatsappagent -->|"requests reply"| node_providerdispatch
node_providerdispatch -->|"selects service"| node_providers
node_providers -->|"sends prompt"| node_modelservices
node_modelservices -->|"returns reply"| node_providers
node_providers -->|"returns reply"| node_providerdispatch
node_providerdispatch -->|"returns reply"| node_wechat
node_providerdispatch -->|"returns reply"| node_larkagent
node_providerdispatch -->|"returns reply"| node_telegramagent
node_providerdispatch -->|"returns reply"| node_whatsappagent
node_imusers -->|"sends messages"| node_wechat
node_imusers -->|"sends events"| node_larkagent
node_imusers -->|"sends messages"| node_telegramagent
node_imusers -->|"sends webhooks"| node_whatsappagent
node_wechat -.->|"captures messages"| node_wechatstore
node_larkagent -.->|"stores messages"| node_larkstore
node_telegramagent -.->|"stores messages"| node_telegramstore
node_whatsappagent -.->|"stores messages"| node_whatsappstore
node_wechat -->|"sends replies"| node_imservices
node_larkagent -->|"sends replies"| node_imservices
node_telegramagent -->|"sends replies"| node_imservices
node_whatsappagent -->|"sends replies"| node_imservices
node_imservices -->|"uses"| node_larkapi
node_imservices -->|"uses"| node_telegramapi
node_imservices -->|"uses"| node_whatsappapi
node_larkops -->|"reads and sends"| node_larkapi
node_opencli -->|"invokes"| node_wxcli
node_wxcli -->|"reads cached data"| node_localdata
node_analyzer -->|"analyzes chats"| node_localdata
node_analyzer -.->|"requests AI analysis"| node_providerdispatch

click node_cli "https://github.com/wangrongding/wechat-bot/blob/main/src/index.js"
click node_config "https://github.com/wangrongding/wechat-bot/blob/main/src/config/env.js"
click node_wechat "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/wechat/bot.js"
click node_wechatstore "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/wechat/messageStore.js"
click node_larkagent "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/lark/agent.js"
click node_larkstore "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/lark/messageStore.js"
click node_telegramagent "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/telegram/agent.js"
click node_telegramstore "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/telegram/messageStore.js"
click node_whatsappagent "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/whatsapp/agent.js"
click node_whatsappstore "https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/whatsapp/messageStore.js"
click node_imservices "https://github.com/wangrongding/wechat-bot/tree/main/src/adapters"
click node_providerdispatch "https://github.com/wangrongding/wechat-bot/tree/main/src"
click node_providers "https://github.com/wangrongding/wechat-bot/tree/main/src"
click node_opencli "https://github.com/wangrongding/wechat-bot/blob/main/src/adapters/opencli.js"
click node_analyzer "https://github.com/wangrongding/wechat-bot/blob/main/src/analysis/wechatAnalyzer.js"
click node_larkops "https://github.com/wangrongding/wechat-bot/blob/main/src/adapters/lark.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_cli,node_config,node_user,node_imusers toneBlue
class node_wechat,node_wechatstore,node_larkagent,node_larkstore,node_telegramagent,node_telegramstore,node_whatsappagent,node_whatsappstore,node_imservices,node_larkops,node_localdata toneAmber
class node_providerdispatch,node_providers,node_modelservices,node_larkapi,node_telegramapi,node_whatsappapi toneMint
class node_opencli,node_analyzer toneRose
class node_wxcli toneIndigo
```

## Components

### Command entry

- [CLI commands](https://github.com/wangrongding/wechat-bot/blob/main/src/index.js): `src/index.js`
- [Runtime config](https://github.com/wangrongding/wechat-bot/blob/main/src/config/env.js): `src/config/env.js`

### IM channels

- [WeChat agent](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/wechat/bot.js): `src/platforms/wechat/bot.js`
- [WeChat message store](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/wechat/messageStore.js): `src/platforms/wechat/messageStore.js`
- [Lark agent](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/lark/agent.js): `src/platforms/lark/agent.js`
- [Lark message store](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/lark/messageStore.js): `src/platforms/lark/messageStore.js`
- [Telegram agent](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/telegram/agent.js): `src/platforms/telegram/agent.js`
- [Telegram message store](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/telegram/messageStore.js): `src/platforms/telegram/messageStore.js`
- [WhatsApp agent](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/whatsapp/agent.js): `src/platforms/whatsapp/agent.js`
- [WhatsApp message store](https://github.com/wangrongding/wechat-bot/blob/main/src/platforms/whatsapp/messageStore.js): `src/platforms/whatsapp/messageStore.js`
- [IM APIs](https://github.com/wangrongding/wechat-bot/tree/main/src/adapters): `src/adapters`
- [Lark operations](https://github.com/wangrongding/wechat-bot/blob/main/src/adapters/lark.js): `src/adapters/lark.js`

### AI services

- [Reply service dispatch](https://github.com/wangrongding/wechat-bot/tree/main/src): `src`
- [Model providers](https://github.com/wangrongding/wechat-bot/tree/main/src): `src`

### Local data

- [OpenCLI adapter](https://github.com/wangrongding/wechat-bot/blob/main/src/adapters/opencli.js): `src/adapters/opencli.js`
- [Chat analyzer](https://github.com/wangrongding/wechat-bot/blob/main/src/analysis/wechatAnalyzer.js): `src/analysis/wechatAnalyzer.js`

### Other components

- **User**
- **IM users**
- **Model APIs**
- **Local WeChat tools**
- **Local chat data**
- **Lark API**
- **Telegram Bot API**
- **WhatsApp Cloud API**

## Connections

- User → CLI commands: runs commands
- CLI commands → Runtime config: loads settings
- CLI commands → WeChat agent: starts agent
- CLI commands → Lark agent: starts agent
- CLI commands → Telegram agent: starts agent
- CLI commands → WhatsApp agent: starts agent
- CLI commands → Lark operations: invokes operations
- CLI commands → OpenCLI adapter: runs local tools
- CLI commands → Chat analyzer: requests analysis
- WeChat agent → Reply service dispatch: requests reply
- Lark agent → Reply service dispatch: requests reply
- Telegram agent → Reply service dispatch: requests reply
- WhatsApp agent → Reply service dispatch: requests reply
- Reply service dispatch → Model providers: selects service
- Model providers → Model APIs: sends prompt
- Model APIs → Model providers: returns reply
- Model providers → Reply service dispatch: returns reply
- Reply service dispatch → WeChat agent: returns reply
- Reply service dispatch → Lark agent: returns reply
- Reply service dispatch → Telegram agent: returns reply
- Reply service dispatch → WhatsApp agent: returns reply
- IM users → WeChat agent: sends messages
- IM users → Lark agent: sends events
- IM users → Telegram agent: sends messages
- IM users → WhatsApp agent: sends webhooks
- WeChat agent → WeChat message store: captures messages
- Lark agent → Lark message store: stores messages
- Telegram agent → Telegram message store: stores messages
- WhatsApp agent → WhatsApp message store: stores messages
- WeChat agent → IM APIs: sends replies
- Lark agent → IM APIs: sends replies
- Telegram agent → IM APIs: sends replies
- WhatsApp agent → IM APIs: sends replies
- IM APIs → Lark API: uses
- IM APIs → Telegram Bot API: uses
- IM APIs → WhatsApp Cloud API: uses
- Lark operations → Lark API: reads and sends
- OpenCLI adapter → Local WeChat tools: invokes
- Local WeChat tools → Local chat data: reads cached data
- Chat analyzer → Local chat data: analyzes chats
- Chat analyzer → Reply service dispatch: requests AI analysis
