# zhimaai/qiweidoc architecture

> Architecture diagram of the GitHub repository zhimaai/qiweidoc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhimaai/qiweidoc
- Repository: https://github.com/zhimaai/qiweidoc

## Overview

##### Project type and purpose
- From the README (“芝麻会话存档私有化部署”) and folder layout, this is a full-stack, private-cloud chat-archiving solution.
- It ingests real‐time chat content (WeChat/企业微信), stores messages, media, and metadata in a dedicated environment, and exposes both a user-facing management UI and background processing pipelines.

##### File structure
Top level:
- docker/ – all containers (httpbatch, main, minio, nats, postgres, redis, wxfinance)
- golang/ – Go microservices (httpbatch, master orchestrator, wxfinance bridge)
- php/ – PHP application using RoadRunner + Yii to serve HTTP APIs and run consumers (modules under php/modules/*)
- static/ – front-end assets:
– static/home – marketing site
– static/management – Vue.js SPA for admin
– static/vitepress – documentation site
Key patterns:
- Docker Compose ties everything together.
- Event-driven, plugin-based Go “master” with NATS as message bus.
- PHP back end handles user HTTP API, integrates directly with DB, Redis, and NATS.
- Storage: Postgres (relational data), Redis (cache/state), MinIO (binary/media).

##### README
- Confirms one-click local deployment, open-source license, high-privacy, self-hosted.
- Use cases: real-time capture (text, media, deletions/recalls), multi-angle views, sensitive-word alerts, statistics.

##### Detail
- For Go, illustrate plugin sub-components inside the master orchestrator.
- Lifecycle: from HTTP/webhook → NATS → worker → DB/MinIO → back to UI or alert channel.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser and Frontend Layer
    subgraph "Browser Layer"
        direction TB
        A1["Marketing Site"]:::frontend
        A2["Management UI (Vue SPA)"]:::frontend
        A3["Documentation Site"]:::frontend
    end

    %% API Layer
    subgraph "API / PHP Layer"
        direction TB
        B1["PHP HTTP/API (RoadRunner + Yii)"]:::api
        B2["PHP Consumers & Cron"]:::api
    end

    %% Message Bus
    subgraph "Message Bus"
        direction TB
        C1["NATS"]:::bus
    end

    %% Go Processing Layer
    subgraph "Go Services (Background Processing)"
        direction TB
        D1["Go Master Orchestrator"]:::processing
        D2["Go HTTPBatch Ingest"]:::processing
        D3["Go WeWork Finance Bridge"]:::processing
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        E1["Postgres Database"]:::db
        E2["Redis Cache/State"]:::db
        E3["MinIO Object Storage"]:::db
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        F1["WeChat / 企业微信"]:::external
        F2["DingTalk / Webhooks"]:::external
        F3["WeWork Finance API"]:::external
    end

    %% Connections
    A1 -->|"HTTP" | B1
    A2 -->|"API Calls"| B1
    A3 -->|"Docs HTTP"| B1
    B1 -->|"Read/Write"| E1
    B1 -->|"Cache/State"| E2
    B1 -->|"Publish Jobs"| C1
    B2 -->|"Publish/Subscribe"| C1

    C1 -->|"Subscribe"| D1
    C1 -->|"Subscribe"| D2
    C1 -->|"Subscribe"| D3

    D1 -->|"Write"| E1
    D1 -->|"Write"| E2
    D1 -->|"Publish"| C1

    D2 -->|"Batch Fetch"| F1
    D2 -->|"Store Media"| E3
    D2 -->|"Write Data"| E1

    D3 -->|"Stream Read"| F3
    D3 -->|"Upload Media"| E3
    D3 -->|"Write Data"| E1

    %% External triggers
    F1 -->|"Webhooks"| B1
    F2 -->|"Webhooks"| B1
    F3 -->|"SDK Bridge"| D3

    %% Click Events
    click A1 "https://github.com/zhimaai/qiweidoc/tree/main/static/home"
    click A2 "https://github.com/zhimaai/qiweidoc/tree/main/static/management"
    click A3 "https://github.com/zhimaai/qiweidoc/tree/main/static/vitepress"
    click B1 "https://github.com/zhimaai/qiweidoc/tree/main/php"
    click B1 "https://github.com/zhimaai/qiweidoc/tree/main/php/yii"
    click B1 "https://github.com/zhimaai/qiweidoc/tree/main/php/common"
    click B1 "https://github.com/zhimaai/qiweidoc/tree/main/php/config"
    click B2 "https://github.com/zhimaai/qiweidoc/tree/main/php/common/Runner"
    click B2 "https://github.com/zhimaai/qiweidoc/blob/main/php/common/Cron.php"
    click B2 "https://github.com/zhimaai/qiweidoc/tree/main/php/modules/*/backend/Consumer"
    click B2 "https://github.com/zhimaai/qiweidoc/tree/main/php/modules/*/backend/Cron"
    click B2 "https://github.com/zhimaai/qiweidoc/tree/main/php/modules/*/migration"
    click C1 "https://github.com/zhimaai/qiweidoc/tree/main/docker/nats"
    click C1 "https://github.com/zhimaai/qiweidoc/blob/main/docker/nats/config.conf"
    click C1 "https://github.com/zhimaai/qiweidoc/tree/main/docker/nats/nats-cli"
    click D1 "https://github.com/zhimaai/qiweidoc/tree/main/golang/cmd/master"
    click D1 "https://github.com/zhimaai/qiweidoc/tree/main/golang/internal/master/rr_plugins"
    click D1 "https://github.com/zhimaai/qiweidoc/blob/main/golang/cmd/master/main.go"
    click D2 "https://github.com/zhimaai/qiweidoc/tree/main/golang/cmd/httpbatch"
    click D2 "https://github.com/zhimaai/qiweidoc/blob/main/golang/cmd/httpbatch/main.go"
    click D2 "https://github.com/zhimaai/qiweidoc/blob/main/golang/cmd/httpbatch/process.go"
    click D3 "https://github.com/zhimaai/qiweidoc/tree/main/golang/cmd/wxfinance"
    click D3 "https://github.com/zhimaai/qiweidoc/blob/main/golang/cmd/wxfinance/bridge.go"
    click D3 "https://github.com/zhimaai/qiweidoc/blob/main/golang/cmd/wxfinance/stream_reader.go"
    click D3 "https://github.com/zhimaai/qiweidoc/blob/main/golang/cmd/wxfinance/stream_upload.go"
    click D1 "https://github.com/zhimaai/qiweidoc/blob/main/golang/rr.yml"
    click E1 "https://github.com/zhimaai/qiweidoc/tree/main/docker/postgres"
    click E1 "https://github.com/zhimaai/qiweidoc/blob/main/docker/postgres/00-init-db.sql"
    click E2 "https://github.com/zhimaai/qiweidoc/tree/main/docker/redis"
    click E2 "https://github.com/zhimaai/qiweidoc/blob/main/docker/redis/redis.conf"
    click E3 "https://github.com/zhimaai/qiweidoc/tree/main/docker/minio"
    click C1 "https://github.com/zhimaai/qiweidoc/blob/main/docker/docker-compose-dev.yml"
    click C1 "https://github.com/zhimaai/qiweidoc/blob/main/docker/docker-compose-prod.yml"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#004080
    classDef api fill:#D5F5E3,stroke:#145A32
    classDef bus fill:#FDEBD0,stroke:#B9770E
    classDef processing fill:#FCF3CF,stroke:#7D6608
    classDef db fill:#E5E7E9,stroke:#2E4053
    classDef external fill:#EBDEF0,stroke:#512E5F
```
