How wthing/teacher-api works
Project type and purpose
• This is a full-stack web application skeleton built on the Yii 2 PHP framework.
• It provides MVC-style web routes (controllers/views/models), console commands, migrations, asset management, e-mail templates, and built-in testing support.
• Designed as a rapid-start template for small PHP apps with user login/logout and contact form features.
File structure and infer components
• Entry points:
– web/index.php and web/index-test.php (HTTP request entry, PHP-FPM via Nginx/Apache).
– yii (console) script at project root (CLI entry for migrations, custom commands).
• MVC layers:
– controllers/ (Web controllers such as SiteController, DataController, UserController)
– models/ (ActiveRecord models and form models)
– views/ (view scripts under views/site, views/data, layouts, widgets)
• Services layer:
– services/FormService.php (business logic for forms)
• Assets & client resources:
– assets/AppAsset.php defines CSS/JS bundles, published to web/assets/
– web/css/site.css
• Configuration:
– config/web.php, console.php, db.php, params.php, test.php, test_db.php
• Database migrations:
– migrations/*.php
• Mail templates:
– mail/layouts/html.php, text.php
• Testing:
– tests/ (unit, functional, acceptance using Codeception)
• Dev environments:
– docker-compose.yml (Docker orchestration)
– Vagrantfile and vagrant/ (virtual machine provisioning)
Main components
1. Client Browser (HTTP)
2. Web Server Layer
• Nginx or Apache (serving web/index.php)
• PHP-FPM process running Yii2 application
3. Yii2 Application
a. Bootstrap & Config Loader
b. Router & Dispatcher
c. Controllers → Services → Models
d. Views & Layout Renderer
e. Asset Manager (publishes CSS/JS)
f. Mailer Component (SMTP or file transport)
4. Database
• MySQL (configured in config/db.php)
• Schema managed by migrations
5. Console Application
• CLI entry point (yii)
• Custom console commands under commands/
• Migrations runner and other scripts
6. Testing Infrastructure
• Codeception suites (unit, functional, acceptance)
• Selenium (for acceptance tests)
7. Development Environments
• Docker Compose services (php, db, web)
• Vagrant VM with Nginx, PHP, MySQL provisioning scripts
Relationships and data flow
• Browser → HTTP request → Web server → PHP-FPM → index.php
• index.php → loads config → route to Controller
• Controller → invokes FormService, Model ActiveRecord → DB query/transaction
• Model ↔ Database
• Controller → View renderer → HTML → Browser
• Assets requested by Browser → served from web/assets/
• Mailer invoked by Controller/Service → SMTP or file transport
• Console “yii migrate” → migrations → DB
• Codeception → PHPUnit/Browser interactions → Application
Highlighted architectural patterns
• MVC (Model-View-Controller)
• Service layer (services/) for business logic separation
• Active Record for DB access
• Asset bundling (AppAsset)
• Configuration-driven modules (config/*.php)
• Dependency Injection via Yii container if used
• Environment isolation (config/test, config/test_db, runtime/, web/index-test.php)