How jiangyang118/datacenter works
Project type and purpose
• This is a full-stack PHP web application built on ThinkPHP 5.0.
• It exposes both a web UI (in public/ksdist and application/index) and a REST-ful API (application/api), plus background job scheduling (application/cron) and asynchronous workers (application/worker).
• Its domain: synchronizing and processing biomedical device data (HeartRate, Wattbike, Centaur, etc.), storing results in a database, and optionally pushing files to Aliyun OSS.
a. Clients & Entry Points
– Web Browser / SPA: loads public/dist/index.html or public/ksdist/… assets.
– API Consumers: mobile apps or other services calling endpoints under /public/index.php/api/....
– Cron Scheduler: OS cron invoking shell scripts under application/cron/shell or running application/cron/Sync*.php via CLI.
b. Web Server Layer
– Nginx / Apache serving public/ directory, forwarding PHP requests to PHP-FPM.
– .htaccess and router.php enable rewrite rules.
c. ThinkPHP Core
– thinkphp/ directory: framework bootstrap, routing, DI, caching, security, console/CLI support.
– public/index.php or server.php loads ThinkPHP, then dispatches to modules.
d. Application Modules
– API Module (application/api/controller & /logic): controllers implement device-specific sync and data ingestion logic.
– Web Module (application/index/controller): user-facing pages, dashboards, manual sync triggers.
– Common & Base (application/common, application/base): shared utilities (BaiduFace OCR, QwRobot), base controller/logic classes.
– Models (application/model): ORM definitions mapping to MySQL tables under application/db.
e. Background Processing
– Cron Jobs (application/cron/command & /shell): schedule data pulls from devices or databases (Centaur, Polar, KX21N, etc.).
– Queue & Worker (application/extra/queue.php + application/worker): cron or API may push tasks into an internal queue. Worker controllers consume tasks to perform heavy processing (e.g., file parsing, statistical calculations). Shell scripts under application/worker/shell orchestrate starting/restarting worker processes.
f. Data Stores & External Services
– MySQL: persistent data storage for configuration, device results, pipeline logs.
– Aliyun OSS (extend/aliyun-oss-php-sdk): optional blob storage for large files or report exports.
– Redis / Memcached: optional cache (configured via application/config/*).
– Third-party APIs: Baidu Face, MQTT channels, Inbody770, etc.
Relationships and data flows
• Browser → Web Server (HTTP) → PHP-FPM → ThinkPHP router → Web Controllers → Models → MySQL → Response → Browser
• Mobile/API Clients → Web Server → PHP-FPM → ThinkPHP router → API Controllers → Logic → Models → MySQL → JSON → Clients
• Cron Scheduler (OS cron) → Shell scripts → CLI think or PHP CLI → Cron Commands → Logic → Models / Queue → Worker
• Workers → internal queue → Worker Controllers → Logic → Models → database or external OSS
Architectural patterns and design principles
– MVC (Controllers in application/*/controller, Models in application/model, Views in public/ksdist or ThinkPHP’s template engine)
– Layered architecture (Controllers → Logic/Service → Models/DAO → Database)
– Asynchronous processing (Cron + Queue + Worker) for long-running tasks
– Dependency injection and PSR-4 autoloading via Composer
– Configuration management per environment (application/config/dev|test|prod)
Essential details
– Show environment configurations feeding into the ThinkPHP bootstrap (dev/test/prod).
– Include Composer/vendor layer under the core.
– Mark the queue layer (even if in-app).
– Don’t over-split; group similar device controllers under “Device Sync API” or “Device Workers.”