# wthing/teacher-api architecture

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

- Interactive diagram: https://gitdiagram.com/wthing/teacher-api
- Repository: https://github.com/wthing/teacher-api

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    Browser("Client Browser"):::external
    Codeception("Codeception"):::testing
    CLI("CLI / Console User"):::external

    %% Infrastructure Layer
    subgraph "Web Server Layer"
        direction TB
        WebServer["Nginx/Apache"]:::webserver
        PHPFPM["PHP-FPM"]:::webserver
    end

    %% Yii2 Application Layer
    subgraph "Yii2 Application"
        direction TB
        ConfigLoader["Bootstrap & Config Loader"]:::app
        Router["Router & Dispatcher"]:::app
        Controllers["Controllers"]:::app
        Services["Services (FormService)"]:::app
        Models["Models"]:::app
        ViewRenderer["Views & Layout Renderer"]:::app
        AssetManager["Asset Manager"]:::app
        Mailer["Mailer Component"]:::app
    end

    %% Database
    DB["MySQL Database"]:::db

    %% Console Application
    subgraph "Console Application"
        direction TB
        CLIEntry["CLI Entry Point (yii)"]:::console
        Commands["Console Commands"]:::console
        Migrations["Migrations Runner"]:::console
    end

    %% Testing Infrastructure
    subgraph "Testing Infrastructure"
        direction TB
        Unit["Unit Tests"]:::testing
        Functional["Functional Tests"]:::testing
        Acceptance["Acceptance Tests"]:::testing
        Selenium["Selenium"]:::testing
    end

    %% Development Environments
    subgraph "Development Environments"
        direction TB
        Docker["Docker Compose"]:::dev
        Vagrant["Vagrant VM"]:::dev
    end

    %% Relationships
    Browser -->|"HTTP request"| WebServer
    WebServer -->|"fastcgi"| PHPFPM
    PHPFPM -->|"index.php"| ConfigLoader
    ConfigLoader --> Router
    Router --> Controllers
    Controllers --> Services
    Services --> Models
    Models --> DB
    Controllers --> ViewRenderer
    ViewRenderer -->|"HTML response"| Browser
    Browser -->|"asset request"| AssetManager
    AssetManager -->|"serve from web/assets"| Browser
    Controllers --> Mailer

    CLI --> CLIEntry
    CLIEntry --> Commands
    Commands --> Migrations
    Migrations --> DB

    Codeception -->|"via HTTP"| WebServer
    Codeception -->|"via CLI"| CLIEntry
    Acceptance --> Selenium

    Docker --> WebServer
    Docker --> PHPFPM
    Docker --> DB
    Vagrant --> WebServer
    Vagrant --> PHPFPM
    Vagrant --> DB

    %% Click Events
    click Browser "https://github.com/wthing/teacher-api/blob/master/web/index.php"
    click WebServer "https://github.com/wthing/teacher-api/blob/master/web/index.php"
    click CLIEntry "https://github.com/wthing/teacher-api/tree/master/yii"
    click Controllers "https://github.com/wthing/teacher-api/tree/master/controllers/"
    click Models "https://github.com/wthing/teacher-api/tree/master/models/"
    click Views "https://github.com/wthing/teacher-api/tree/master/views/"
    click Services "https://github.com/wthing/teacher-api/blob/master/services/FormService.php"
    click AssetManager "https://github.com/wthing/teacher-api/blob/master/assets/AppAsset.php"
    click DB "https://github.com/wthing/teacher-api/blob/master/config/db.php"
    click Migrations "https://github.com/wthing/teacher-api/tree/master/migrations/"
    click Mailer "https://github.com/wthing/teacher-api/blob/master/mail/layouts/html.php"
    click Unit "https://github.com/wthing/teacher-api/tree/master/tests/"
    click Docker "https://github.com/wthing/teacher-api/blob/master/docker-compose.yml"
    click Vagrant "https://github.com/wthing/teacher-api/tree/master/Vagrantfile"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef webserver fill:#f96,stroke:#333,stroke-width:1px
    classDef app fill:#9cf,stroke:#333,stroke-width:1px
    classDef db fill:#c9f,stroke:#333,stroke-width:1px
    classDef console fill:#fc9,stroke:#333,stroke-width:1px
    classDef testing fill:#ccc,stroke:#333,stroke-width:1px
    classDef dev fill:#ff9,stroke:#333,stroke-width:1px
```
