How zoujingli/thinkadmin works
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).