# zoujingli/thinkadmin architecture

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

- Interactive diagram: https://gitdiagram.com/zoujingli/thinkadmin
- Repository: https://github.com/zoujingli/thinkadmin

## Overview

##### Project Type and Purpose
- This is a full-stack web application framework and demo system (“ThinkAdmin v6.1”) built on ThinkPHP6 (compatible with v8).
- It provides two core modules under app/:
- app/admin – a backend administration panel (RBAC, file storage, configuration, queue, logs, menus)
- app/wechat – a WeChat management console (auto-reply, fans, media, menu, payment).
- It also bundles a lightweight core library (ThinkLibrary), asynchronous queue tasks, multi-storage support, and migration tooling.

##### File Structure Analysis
- Top-level:
- app/ – two multi-layered MVC/Service modules (admin, wechat)
- config/ – application, database, cache, session, route, view settings
- public/ – web document root (index.php, router.php, static assets)
- composer.json, .env.example – dependency and environment setup
- app/admin and app/wechat each follow a layered structure:
- controller/ – HTTP routes and business entry points (including /api)
- service/ or command/ – domain logic, queue handlers, CLI commands
- model/ (wechat only) – ORM mapping
- view/ – HTML templates and JS assets loaded via RequireJS/LayUI
- lang/ – localization files
- route/ (admin) – custom route definitions
- Public/static:
- theme/, plugs/, extra/ – front-end libraries (LayUI, RequireJS, jQuery, CKEditor, Vue), custom styles and scripts
- Tools & Config:
- Phinx migration (config/phinx.php), queue commands (php think xadmin:queue …), composer-managed plugins.

##### Key Technologies & Patterns
- MVC pattern per module, augmented with a service layer.
- RESTful and RPC-style API controllers under /api.
- Asynchronous queue subsystem with CLI commands to start/listen/stop processes.
- Pluggable storage adapters (local, alist, Qiniu, OSS, COS, Upyun).
- Front-end uses RequireJS for module loading, LayUI for UI components, jQuery/Angular for dynamic behavior.
- Multi-application support via ThinkPHP6’s multi-app component.

##### Main Components & Interactions
- Browser Client
- Loads HTML templates (admin vs wechat) and static assets (CSS, JS via RequireJS).
- Sends HTTP requests to controllers (admin/auth, wechat/api, etc.).
- Web Server (Apache/Nginx or built-in PHP server)
- Entrypoint: public/index.php → ThinkPHP bootstrap → dispatch to module/controller/action.
- router.php handles custom rewrite.
- Application Layer
- Controllers receive HTTP requests.
- Controllers delegate to Services (business logic), Models (data access), and Storage adapters.
- Views are rendered server-side and delivered to client.
- Database
- Configured via config/database.php, managed by Phinx migrations.
- Tables for admin (users, roles, menus, logs, queue tasks), wechat (fans, media, payment records).
- Queue/Sub-process Manager
- CLI tasks (xadmin:queue start/listen) orchestrate background jobs.
- Services handle asynchronous tasks (auto-reply, exports, notifications).
- External Services
- WeChat API endpoints (OAuth, push, JS-SDK).
- Storage/CDN endpoints for media files.
- Optional plugins via Composer (WechatDeveloper, QRcode).

##### Architectural Patterns and Principles
- Layered architecture: HTTP Controller → Service → Model/Storage → External.
- Dependency inversion: Controllers depend on abstracted service interfaces.
- Pluggable modules: new modules follow the same directory conventions.
- Configuration-driven storage, queue, caching.
- Annotation-based RBAC (metadata-driven code).

##### Detail Level
- Essential elements without clutter: focus on major directories and flows.
- Drill into sub-components only where behavior differs (e.g., asynchronous queue vs synchronous HTTP).
- Modules with key controllers or service responsibilities (e.g., AdminAuth, WechatPaymentService).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        BrowserAdmin["Browser Client (Admin UI)"]:::frontend
        BrowserWechat["Browser Client (WeChat UI)"]:::frontend
        StaticAssets["Static Assets Server\n(public/static)"]:::frontend
    end

    %% Web/App Tier
    subgraph "Web/App Tier"
        direction TB
        PublicIndex["public/index.php\n(Entrypoint)"]:::infra
        Router["public/router.php\n(Custom Rewrite)"]:::infra
        ThinkLib["Core Framework Library\nthink/"]:::infra

        subgraph "Admin Module\n(MVC + Service Layer)" 
            direction TB
            AdminControllers["Controllers\napp/admin/controller"]:::backend
            AdminAPI["API Controllers\napp/admin/controller/api"]:::backend
            AdminViews["Views\napp/admin/view"]:::frontend
            AdminLang["Lang Files\napp/admin/lang/en-us.php"]:::backend
            AdminRoute["Routes\napp/admin/route/demo.php"]:::backend
            AdminConfigController["Config Controller\nConfig.php"]:::backend
            AdminQueueController["Queue Controller\nQueue.php"]:::backend
            AdminCoreService["Core Service\nService.php"]:::backend
        end

        subgraph "WeChat Module\n(MVC + Service + Command)" 
            direction TB
            WeChatControllers["Controllers\napp/wechat/controller"]:::backend
            WeChatAPI["API Controllers\napp/wechat/controller/api"]:::backend
            WeChatPayment["Payment Controllers\napp/wechat/controller/payment"]:::backend
            WeChatServiceLayer["Service Layer\napp/wechat/service"]:::backend
            WeChatModels["Models\napp/wechat/model"]:::backend
            WeChatCommands["CLI Commands\napp/wechat/command"]:::infra
            WeChatViews["Views\napp/wechat/view"]:::frontend
            WeChatLang["Lang Files\napp/wechat/lang/en-us.php"]:::backend
            WeChatCoreService["Core Service\nService.php"]:::backend
        end
    end

    %% Data/Integration Tier
    subgraph "Data/Integration Tier"
        direction TB
        Database["Database\n(config/database.php)"]:::infra
        StorageAdapters["Storage Adapters\n(local, Qiniu, OSS, etc)"]:::infra
        ExternalWeChat["WeChat API\n(OAuth, push, JS-SDK)"]:::external
        ExternalCDN["CDN Storage\n(media files)"]:::external
        Migrations["Phinx Migrations\nconfig/phinx.php"]:::infra
        ComposerConfig["Composer & Plugins\ncomposer.json"]:::infra
        EnvExample["Env Example\n.env.example"]:::infra
    end

    %% Connections
    BrowserAdmin -->|"GET HTML/CSS/JS"| StaticAssets
    BrowserWechat -->|"GET HTML/CSS/JS"| StaticAssets

    BrowserAdmin -->|"HTTP Request"| PublicIndex
    BrowserWechat -->|"HTTP Request"| PublicIndex
    StaticAssets --> PublicIndex

    PublicIndex --> Router
    Router --> ThinkLib

    ThinkLib --> AdminControllers
    ThinkLib --> WeChatControllers

    AdminControllers --> AdminCoreService
    AdminAPI --> AdminCoreService
    AdminCoreService --> AdminQueueController
    AdminCoreService --> AdminConfigController
    AdminControllers --> AdminViews
    AdminControllers --> AdminLang
    AdminControllers --> AdminRoute

    WeChatControllers --> WeChatCoreService
    WeChatAPI --> WeChatServiceLayer
    WeChatPayment --> WeChatServiceLayer
    WeChatCoreService --> WeChatCommands
    WeChatControllers --> WeChatViews
    WeChatControllers --> WeChatLang
    WeChatCommands --> WeChatServiceLayer

    AdminCoreService --> StorageAdapters
    WeChatServiceLayer --> StorageAdapters

    StorageAdapters --> Database
    StorageAdapters --> ExternalCDN

    AdminQueueController --> Database
    WeChatCommands --> Database

    WeChatServiceLayer --> ExternalWeChat

    %% Click Events
    click AdminModule "https://github.com/zoujingli/thinkadmin/tree/v6/app/admin"
    click AdminControllers "https://github.com/zoujingli/thinkadmin/tree/v6/app/admin/controller"
    click AdminAPI "https://github.com/zoujingli/thinkadmin/tree/v6/app/admin/controller/api"
    click AdminViews "https://github.com/zoujingli/thinkadmin/tree/v6/app/admin/view"
    click AdminLang "https://github.com/zoujingli/thinkadmin/blob/v6/app/admin/lang/en-us.php"
    click AdminRoute "https://github.com/zoujingli/thinkadmin/blob/v6/app/admin/route/demo.php"
    click AdminConfigController "https://github.com/zoujingli/thinkadmin/blob/v6/app/admin/controller/Config.php"
    click AdminQueueController "https://github.com/zoujingli/thinkadmin/blob/v6/app/admin/controller/Queue.php"
    click AdminCoreService "https://github.com/zoujingli/thinkadmin/blob/v6/app/admin/Service.php"

    click WeChatModule "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat"
    click WeChatControllers "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/controller"
    click WeChatAPI "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/controller/api"
    click WeChatPayment "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/controller/payment"
    click WeChatServiceLayer "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/service"
    click WeChatModels "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/model"
    click WeChatCommands "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/command"
    click WeChatViews "https://github.com/zoujingli/thinkadmin/tree/v6/app/wechat/view"
    click WeChatLang "https://github.com/zoujingli/thinkadmin/blob/v6/app/wechat/lang/en-us.php"
    click WeChatCoreService "https://github.com/zoujingli/thinkadmin/blob/v6/app/wechat/Service.php"

    click PublicIndex "https://github.com/zoujingli/thinkadmin/blob/v6/public/index.php"
    click Router "https://github.com/zoujingli/thinkadmin/blob/v6/public/router.php"
    click StaticAssets "https://github.com/zoujingli/thinkadmin/tree/v6/public/static"
    click InfraHTAccess "https://github.com/zoujingli/thinkadmin/blob/v6/public/.htaccess"
    click ComposerConfig "https://github.com/zoujingli/thinkadmin/blob/v6/composer.json"
    click EnvExample "https://github.com/zoujingli/thinkadmin/blob/v6/.env.example"
    click Migrations "https://github.com/zoujingli/thinkadmin/blob/v6/config/phinx.php"
    click ThinkLib "https://github.com/zoujingli/thinkadmin/tree/v6/think/"

    %% Styles
    classDef frontend fill:#87CEFA,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
```
