# xiaohuihui-ue/wechat-on-airflow architecture

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

- Interactive diagram: https://gitdiagram.com/xiaohuihui-ue/wechat-on-airflow
- Repository: https://github.com/xiaohuihui-ue/wechat-on-airflow

## Overview

##### Main Components
- Web Frontend & Authentication: Although not heavily represented in the file tree, the README clearly outlines a “管理页面” (management page) accessed by users via a browser, and an associated authentication service.
- Reverse Proxy / Nginx: The project uses Nginx for managing inbound HTTPS requests and load balancing between public and internal services.
- Airflow Orchestrator: The core of your project is Airflow (as seen in the README and multiple “dags” directories) which schedules and manages workflows.
- Database & Cache: Components include MySQL (for storing key chat records and other persistent data) and Redis (referenced through both database configurations and utility modules).
- Cloud Functions: Several tasks are offloaded to cloud functions that act for tasks like message reporting and data querying.
- AI Agents & External Services: There is integration with external AI services (e.g., Dify for intelligent customer care, a large model API for AI inference) and custom “agent” modules in the “dags/ai_agent” directory.
- WeChat Integrations: Separate workflows exist for personal WeChat functionality, WeChat public account interactions, and additional integrations based on the “wx_dags”, “wx_mp_dags”, and scf directories.
- Auxiliary Services: Other supporting components include Cron DAGs for periodic tasks, proxy watchers, and utility modules that handle specific networking (e.g., proxy tools) or data tasks.

##### Representing Relationships and Data Flows
- Within the internal network, show how Nginx interacts with:
- The Airflow module – which schedules and executes DAGs that call various agent scripts found under directories such as “dags/ai_agent” and “dags/ai_tennis_dags”.
- Database systems (MySQL and Redis) that store chat logs and state information.
- External services and cloud functions, which further integrate into intelligent response flows (e.g., Dify, large model service).

##### Architectural Patterns and Design Principles
- Modular Design: The file tree’s segmentation (e.g., distinct directories for “ai_agent”, “ai_tennis_dags”, “cron_dags”, “wx_dags”, etc.) indicates a modular architecture where each folder encapsulates a part of the overall functionality.
- Separation of Concerns: The system clearly separates concerns by using Apache Airflow to coordinate and schedule tasks rather than embedding this logic in a monolithic service.
- Integration of External Services: The design leverages both open-source tools (Airflow, Nginx, Dify) and cloud services (Tencent Cloud functions for intermediate processing).

- The “dags” directory is central; within it, use clusters to represent:
- “ai_agent”: Each Python file (like “brocad_agent_001.py”, “dify_agent_001.py”, “zacks_ai_agent.py”) becomes an individual agent node, detailing the specific AI tasks they support.
- “ai_tennis_dags”: Separate clusters for “action_score_v1” and “action_score_v2” to show versioning differences, each containing script modules and models.
- “wx_dags” & “wx_mp_dags”: Represent these as integration nodes for WeChat client and public account messaging, including the “handlers” and supporting tools.
- The “database” and “dify_conf” directories indicate the infrastructure for configuration and database provisioning.
- Additional directories (such as “scf” and “supabase-sql-storage”) hint at further subsystem integrations with SQL-based dashboards and storage, which should be represented as supportive components connecting to the central workflow engine.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User Layer
    subgraph "用户层"
        UserBrowser("用户/浏览器"):::external
        WebFrontend("Web前端 & 鉴权服务"):::external
    end

    %% Gateway Layer
    subgraph "入口网关"
        ProxyNginx("Nginx (反向代理)"):::internal
        WebServer("Web Server"):::internal
    end

    %% Orchestration Layer
    subgraph "调度层"
        Airflow("Airflow Orchestrator"):::orchestrator
    end

    %% 数据存储 & 外部服务层
    subgraph "数据 & 服务层"
        PostgresDB("PostgreSQL Database"):::database
        RedisCache("Redis Cache"):::database
        CloudFunctions("云函数"):::cloud
        DifyService("Dify 智能客服"):::external
        LargeModelService("大模型服务"):::external
        AIAgents("通用 AI Agents"):::agent
        AITennis("AI Tennis Workflows"):::agent
        WeChatGroup("WeChat 群 & 消息处理"):::external
        WeChatMP("微信公众号集成"):::external
    end

    %% 辅助工具层
    subgraph "辅助服务"
        CronTasks("Cron & 定时任务"):::internal
        ProxyTools("代理工具"):::internal
        API_Utils("额外API & 工具"):::internal
    end

    %% Connections from User Layer to Gateway
    UserBrowser -->|"访问"| WebFrontend
    WebFrontend -->|"请求"| ProxyNginx

    %% Gateway flows split to Web Server and Airflow
    ProxyNginx -->|"静态内容"| WebServer
    ProxyNginx -->|"API请求"| Airflow

    %% Cloud Functions trigger orchestration
    CloudFunctions -->|"触发任务"| Airflow

    %% Airflow connections to Data Storage & External Services
    Airflow -->|"数据存储"| PostgresDB
    Airflow -->|"缓存操作"| RedisCache
    Airflow -->|"调用"| DifyService
    Airflow -->|"调用"| LargeModelService
    Airflow -->|"调度"| AIAgents
    Airflow -->|"调度"| AITennis
    Airflow -->|"触发"| WeChatGroup
    Airflow -->|"触发"| WeChatMP

    %% Airflow connections to Auxiliary Services
    Airflow -->|"定时任务"| CronTasks
    Airflow -->|"代理监控"| ProxyTools
    Airflow -->|"工具调用"| API_Utils

    %% Click Events
    click ProxyNginx "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/nginx/wcf"
    click Airflow "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags"
    click PostgresDB "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/database/postgresql"
    click RedisCache "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/database/redis"
    click CloudFunctions "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/scf"
    click AIAgents "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/ai_agent"
    click AITennis "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/ai_tennis_dags"
    click WeChatGroup "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/wechat_group_dags"
    click WeChatMP "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/wx_mp_dags"
    click CronTasks "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/cron_dags"
    click ProxyTools "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/tennis_dags/proxy_tools"
    click API_Utils "https://github.com/xiaohuihui-ue/wechat-on-airflow/tree/main/dags/utils"

    %% Styles
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px,color:#000;
    classDef internal fill:#90EE90,stroke:#333,stroke-width:2px,color:#000;
    classDef orchestrator fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000;
    classDef database fill:#FFB6C1,stroke:#333,stroke-width:2px,color:#000;
    classDef cloud fill:#D3D3D3,stroke:#333,stroke-width:2px,color:#000;
    classDef agent fill:#FFDEAD,stroke:#333,stroke-width:2px,color:#000;
```
