# w7corp/easywechat architecture

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

- Interactive diagram: https://gitdiagram.com/w7corp/easywechat
- Repository: https://github.com/w7corp/easywechat

## Overview

##### Project type and purpose
- EasyWeChat is an open-source PHP SDK (library) for integrating with WeChat’s various platforms (Official Account, Mini App, Open Platform, Open Work, Pay, etc.).
- It provides a unified, modular way to call WeChat APIs, handle incoming messages/webhooks, perform encryption/decryption, and manage access tokens.

##### File structure
- Top-level:
- composer.json, src/, tests/, docs/
- CI/CD and linting configs (.github/workflows, phpunit.xml, phpstan.neon, .php-cs-fixer.dist.php)
- src/ directory:
- Kernel/ – core abstractions (Contracts, HttpClient, Support, Encryptor, Traits)
- Modules: MiniApp/, OfficialAccount/, OpenPlatform/, OpenWork/, Pay/, Work/ – each contains Application, Config, AccessToken, Server, Message, Utils, etc.
- tests/ mirrors src/ structure to validate each module and Kernel.
- docs/ – VitePress-based documentation site, not part of runtime.

##### README
- Describes environment (PHP >=8.0), installation (Composer), basic usage example for OfficialAccount.
- No built-in UI or persistent storage – this is a library consumed by a PHP app.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Layer
    App["Your PHP Application"]:::external

    %% SDK Layer
    subgraph "EasyWeChat SDK"
        subgraph "Kernel"
            Config["Config Management"]:::coreKernel
            HttpClient["HTTP Client Subsystem"]:::coreKernel
            Encryptor["Encryption Support"]:::coreKernel
            Support["Support Utilities"]:::coreKernel
            Traits["Common Traits"]:::coreKernel
            ATClient["AccessTokenAwareHttpClient (Contract)"]:::coreKernel
        end
        subgraph "Modules"
            OA["OfficialAccount Module"]:::module
            MA["MiniApp Module"]:::module
            OP["OpenPlatform Module"]:::module
            OW["OpenWork Module"]:::module
            W["Work Module"]:::module
            P["Pay Module"]:::module
        end
    end

    %% External Services
    CacheStorage["Cache/Storage (PSR-16/PSR-6)"]:::external
    WeChatAPI["External WeChat API Endpoints"]:::external

    %% CI/CD and Docs
    subgraph "CI/CD Pipelines"
        Test["Test Workflow"]:::ci
        Lint["Lint Workflow"]:::ci
        Deploy["Deploy Workflow"]:::ci
    end
    Docs["Documentation (VitePress)"]:::external
    Composer["composer.json"]:::external

    %% Connections
    App -->|"Instantiates Modules"| OA
    App --> MA
    App --> OP
    App --> OW
    App --> W
    App --> P
    App -->|"Reads Config"| Composer

    Config -->|"Provides Config"| Traits
    Config -->|"Provides Config"| OA
    HttpClient -->|"Provides HTTP"| OA
    Encryptor -->|"Provides Encryption"| OA
    Support -->|"Provides Utilities"| OA
    Traits -->|"Provides Traits"| OA
    ATClient -->|"PSR-16/6 Contract"| Traits

    Config -->|"Provides Config"| MA
    HttpClient -->|"Provides HTTP"| MA
    Encryptor -->|"Provides Encryption"| MA
    Support -->|"Provides Utilities"| MA
    Traits -->|"Provides Traits"| MA

    Kernel -->|"Provides Core Services"| Modules

    HttpClient -->|"HTTP Calls"| WeChatAPI
    WeChatAPI -->|"Response"| HttpClient

    Kernel -->|"Token Management"| CacheStorage
    ATClient -->|"Uses Cache"| CacheStorage
    Traits -->|"InteractWithCache"| CacheStorage

    Test -->|"Runs on src/, tests/"| App
    Lint -->|"Lints src/"| App
    Deploy -->|"Deploys release"| App
    Test --> Docs
    Lint --> Docs

    %% Click Events
    click Config "https://github.com/w7corp/easywechat/blob/6.x/src/Kernel/Config.php"
    click HttpClient "https://github.com/w7corp/easywechat/tree/6.x/src/Kernel/HttpClient"
    click Encryptor "https://github.com/w7corp/easywechat/blob/6.x/src/Kernel/Encryptor.php"
    click Support "https://github.com/w7corp/easywechat/tree/6.x/src/Kernel/Support"
    click Traits "https://github.com/w7corp/easywechat/tree/6.x/src/Kernel/Traits"
    click ATClient "https://github.com/w7corp/easywechat/blob/6.x/src/Kernel/Contracts/AccessTokenAwareHttpClient.php"
    click OA "https://github.com/w7corp/easywechat/tree/6.x/src/OfficialAccount"
    click MA "https://github.com/w7corp/easywechat/tree/6.x/src/MiniApp"
    click OP "https://github.com/w7corp/easywechat/tree/6.x/src/OpenPlatform"
    click OW "https://github.com/w7corp/easywechat/tree/6.x/src/OpenWork"
    click W "https://github.com/w7corp/easywechat/tree/6.x/src/Work"
    click P "https://github.com/w7corp/easywechat/tree/6.x/src/Pay"
    click Test "https://github.com/w7corp/easywechat/blob/6.x/.github/workflows/test.yml"
    click Lint "https://github.com/w7corp/easywechat/blob/6.x/.github/workflows/lint.yml"
    click Deploy "https://github.com/w7corp/easywechat/blob/6.x/.github/workflows/deploy.yml"
    click Docs "https://github.com/w7corp/easywechat/tree/6.x/docs/"
    click Composer "https://github.com/w7corp/easywechat/blob/6.x/composer.json"

    %% Styles
    classDef coreKernel fill:#f9f,stroke:#333,stroke-width:1px;
    classDef module fill:#9f9,stroke:#333,stroke-width:1px;
    classDef external fill:#ccf,stroke:#333,stroke-width:1px;
    classDef ci fill:#fc9,stroke:#333,stroke-width:1px;
```
