# yiisoft/yii2-app-advanced architecture

> Architecture diagram of the GitHub repository yiisoft/yii2-app-advanced, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yiisoft/yii2-app-advanced
- Repository: https://github.com/yiisoft/yii2-app-advanced

## Overview

##### Project Type and Purpose
- This is a full-stack web application template using the Yii 2 framework.
- Its purpose is to provide a skeleton structure for building complex web applications. It separates concerns into three tiers (frontend, backend, console) and provides shared functionality (common), which helps in team development and environment-specific configuration.

##### File Structure for Architectural Clues
- Key top-level directories:
- frontend: Contains the user-facing web application (controllers, models, views, assets, and web entry point).
- backend: Hosts the administrative or internal interface with similar structure to the frontend.
- console: Contains command-line scripts, controllers, and migrations for running background tasks and database migrations.
- common: Shares configuration files, models, mail templates, tests, and widgets used by both frontend and backend.
- environments: Provides environment-specific overrides (e.g., for development and production).
- docs and vendor: The documentation and third-party libraries.
- Other supporting files include Dockerfiles, Vagrant setup, Codeception test configurations, and CI/CD workflows in the .github directory – each indicating aspects of deployment, testing, and continuous integration.

- Frontend Application: Mark as “Frontend” and include elements like assets, configuration, controllers, models, views, and entry scripts (web/ directory).
- Backend Application: Mark as “Backend” with its corresponding subcomponents (controllers, views, assets, models, and config).
- Console Application: Display this as a separate block with its controllers, migration scripts, and models.
- Common Shared Library: Show this as a central repository of shared components (common/config, common/models, common/mail, and common/tests).

##### Relationships and Interactions
- That the Frontend and Backend are separate web applications communicating with users via HTTP. Indicate:
- Frontend receives standard web requests from the public internet (user browsers).
- Backend often serves administrative tasks and has a similar HTTP flow.
- That the Console application is used for tasks like running migrations and background jobs which may interact with the Database or affect both Frontend and Backend.
- If applicable, include data flows (or dependencies) toward external persistence (e.g., a DB, which isn’t directly visible in the file tree but is a common part of any Yii application).

##### Important Architectural Patterns & Technologies
- Separation of concerns: MVC pattern in both the Frontend and Backend.
- That the shared “common” directory centralizes shared logic, adhering to DRY principles.
- Annotations for environment-based configuration (overrides in environments/dev and environments/prod).
- Mention build/deployment support using Docker, Vagrant, and CI/CD pipelines found in .github and docker-compose.yml.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    A["User"]:::external
    B["Admin"]:::external

    %% Web Applications
    subgraph "Web Applications"
        C["Frontend Application"]:::web
        D["Backend Application"]:::web
    end

    %% Shared and Support Components
    E["Common Shared Library"]:::common
    F["Console Application"]:::console

    %% Infrastructure and Configurations
    G["Environment Configurations"]:::env
    H["Deployment & CI/CD"]:::deploy
    I["Documentation"]:::docs
    J["Database"]:::db

    %% Relationships from External Clients
    A -->|"HTTP_Request"| C
    B -->|"HTTP_Request"| D

    %% Relationships among Application Tiers
    C -->|"uses"| E
    D -->|"uses"| E

    %% Interactions with Database
    C -->|"reads/writes"| J
    D -->|"reads/writes"| J
    F -->|"runs migrations"| J

    %% Environment Overrides to Applications
    G -->|"overrides"| C
    G -->|"overrides"| D
    G -->|"overrides"| E
    G -->|"overrides"| F

    %% Deployment Connections
    H -->|"deploys"| C
    H -->|"deploys"| D
    H -->|"deploys"| F

    %% Documentation Guides
    I -->|"guides"| C
    I -->|"guides"| D
    I -->|"guides"| E
    I -->|"guides"| F

    %% Click Events
    click C "https://github.com/yiisoft/yii2-app-advanced/tree/master/frontend/"
    click D "https://github.com/yiisoft/yii2-app-advanced/tree/master/backend/"
    click F "https://github.com/yiisoft/yii2-app-advanced/tree/master/console/"
    click E "https://github.com/yiisoft/yii2-app-advanced/tree/master/common/"
    click G "https://github.com/yiisoft/yii2-app-advanced/tree/master/environments/"
    click H "https://github.com/yiisoft/yii2-app-advanced/tree/master/.github/"
    click I "https://github.com/yiisoft/yii2-app-advanced/tree/master/docs/"

    %% Styles
    classDef web fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef common fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef console fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef env fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef deploy fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef docs fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef db fill:#A3E4D7,stroke:#16A085,stroke-width:2px;
    classDef external fill:#D5DBDB,stroke:#566573,stroke-width:2px;
```
