# zhayujie/chatgpt-on-wechat architecture

> Architecture diagram of the GitHub repository zhayujie/chatgpt-on-wechat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhayujie/chatgpt-on-wechat
- Repository: https://github.com/zhayujie/chatgpt-on-wechat

## Overview

##### Main Components Structure

The system should be represented in layers, with these key components:

a) Channel Layer (Top)
- Multiple messaging platforms (WeChat, DingTalk, Feishu, Terminal, Web)
- Each channel has its own implementation for message handling
- Common interface through channel.py

b) Bridge Layer (Middle)
- Handles communication between channels and bots
- Manages context and reply formatting
- Acts as a middleware for message processing

c) Bot Layer (Core)
- Multiple AI model integrations (OpenAI, Claude, Gemini, etc.)
- Session management
- Message processing logic

d) Plugin System (Side)
- Extensible plugin architecture
- Various functional plugins (role-playing, keyword detection, etc.)
- Plugin management system

e) Supporting Services (Bottom)
- Voice processing (multiple providers)
- Translation services
- Image generation capabilities
- Knowledge base integration

##### Component Relationships

**Channels → Bridge → Bot Layer → AI Models**
- ↕
- Plugin System
- ↕
- Supporting Services

##### Detailed Elements

Specific components:

a) Channel Implementations:
- WeChatMP Channel
- WeChatCom Channel
- DingTalk Channel
- Feishu Channel
- Terminal Channel
- Web Channel

b) Bot Implementations:
- OpenAI Bot
- Claude Bot
- Gemini Bot
- Wenxin Bot
- Other AI model integrations

c) Plugin System:
- Plugin Manager
- Event System
- Individual Plugins (Role, Keyword, etc.)

d) Supporting Features:
- Voice Processing (Multiple providers)
- Translation Services
- Image Generation
- Knowledge Base Integration

##### Technical Details

- Python-based implementation
- Docker container support
- External API integrations
- Database connections (if any)
- Cache systems
- Message queues

##### Deployment Options

A separate section showing deployment possibilities:
- Local deployment
- Docker deployment
- Railway deployment
- Server deployment

Remember to emphasize the modular nature of the system, showing how new channels or AI models can be easily integrated through the existing architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Channel Layer"
        CH["Channel Interface"]
        WMP["WeChat MP"]
        WCM["WeChat Com"]
        DT["DingTalk"]
        FL["Feishu"]
        TM["Terminal"]
        WB["Web"]
    end

    subgraph "Bridge Layer"
        BR["Bridge"]
        CTX["Context Manager"]
        RPL["Reply Handler"]
    end

    subgraph "Bot Layer"
        BOT["Bot Interface"]
        SM["Session Manager"]
        
        subgraph "AI Implementations"
            OAI["OpenAI Bot"]
            CLD["Claude Bot"]
            GMN["Gemini Bot"]
            WXN["Wenxin Bot"]
        end
    end

    subgraph "Plugin System"
        PM["Plugin Manager"]
        EV["Event System"]
        BP["Base Plugin"]
    end

    subgraph "Supporting Services"
        subgraph "Voice Services"
            VI["Voice Interface"]
            VF["Voice Factory"]
        end
        
        subgraph "Translation Services"
            TI["Translation Interface"]
            TF["Translation Factory"]
        end
        
        subgraph "Image Generation"
            OIG["OpenAI Image"]
            ZIG["ZhipuAI Image"]
        end
    end

    %% Relationships
    CH --> BR
    WMP & WCM & DT & FL & TM & WB --> CH
    BR --> BOT
    BR <--> PM
    BR --> CTX
    BR --> RPL
    BOT --> SM
    BOT --> OAI & CLD & GMN & WXN
    PM --> EV
    PM --> BP
    
    %% Component Mappings
    click CH "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/channel.py"
    click WMP "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/wechatmp/wechatmp_channel.py"
    click WCM "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/wechatcom/wechatcomapp_channel.py"
    click DT "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/dingtalk/dingtalk_channel.py"
    click FL "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/feishu/feishu_channel.py"
    click TM "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/terminal/terminal_channel.py"
    click WB "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/web/web_channel.py"
    click BR "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bridge/bridge.py"
    click CTX "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bridge/context.py"
    click RPL "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bridge/reply.py"
    click BOT "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/bot.py"
    click SM "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/session_manager.py"
    click OAI "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/openai/open_ai_bot.py"
    click CLD "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/claude/claude_ai_bot.py"
    click GMN "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/gemini/google_gemini_bot.py"
    click WXN "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/baidu/baidu_wenxin.py"
    click PM "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/plugins/plugin_manager.py"
    click EV "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/plugins/event.py"
    click BP "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/plugins/plugin.py"
    click VI "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/voice/voice.py"
    click VF "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/voice/factory.py"
    click TI "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/translate/translator.py"
    click TF "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/translate/factory.py"
    click OIG "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/openai/open_ai_image.py"
    click ZIG "https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/zhipuai/zhipu_ai_image.py"

    %% Styling
    classDef channel fill:#90EE90
    classDef bridge fill:#ADD8E6
    classDef bot fill:#4169E1
    classDef plugin fill:#FFD700
    classDef service fill:#DDA0DD
    
    class CH,WMP,WCM,DT,FL,TM,WB channel
    class BR,CTX,RPL bridge
    class BOT,SM,OAI,CLD,GMN,WXN bot
    class PM,EV,BP plugin
    class VI,VF,TI,TF,OIG,ZIG service
```
