# tamthor/km_mobifone architecture

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

- Interactive diagram: https://gitdiagram.com/tamthor/km_mobifone
- Repository: https://github.com/tamthor/km_mobifone

## Overview

##### Project type and purpose
- This is a full-stack web application built on the Laravel PHP framework.
- The business domain revolves around “promotions” (categories, content, contacts), banners, tags, and comments, with both a public-facing API and an administrative SPA under `public/backend`.

##### File structure
- Top-level directories:
- app/ — Laravel MVC core (Console commands, HTTP Controllers, Middleware, Models, Providers)
- config/ — Laravel config for database, mail, cache, queue, services, etc.
- database/ — Migrations, model factories, seeders
- public/ — Web-server document root (entry `index.php`), SPA assets under `public/backend`, public JS/CSS assets
- resources/ — Blade templates, front-end JS & CSS sources, Vite config
- routes/ — HTTP (`web.php`), API (`api.php`), console routes
- storage/ — File storage (public, private), cache, logs
- tests/ — Feature and unit tests
- artisan, bootstrap/, vendor/ (via composer)

##### Essential architectural elements
- Don’t omit the middleware pipeline, queue worker, scheduled tasks, or storage abstractions.
- Both synchronous flows (HTTP → Controller → DB) and asynchronous ones (Controller → Job → Queue → Worker → DB).
- Aim for enough granularity to show each subclass of controller (web vs. API) and each major model group (Promotion, Banner, Comment, Tag, Contact).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Browser"]:::client
        AdminSPA["Admin SPA"]:::client
        ThirdParty["Third-Party Clients"]:::client
    end

    %% Web Server Layer
    subgraph "Web Server Layer"
        direction TB
        NGNX["Nginx/Apache"]:::infra
        Entry["public/index.php"]:::infra
    end

    %% Application Layer
    subgraph "Laravel Application" 
        direction TB
        Kernel["HTTP Kernel"]:::app
        subgraph "Middleware Pipeline"
            direction TB
            Cors["CorsMiddleware"]:::app
            Csrf["VerifyCsrfToken"]:::app
            Encrypt["EncryptCookies"]:::app
            Trim["TrimStrings"]:::app
            Trust["TrustProxies"]:::app
        end
        subgraph "Controllers - Web"
            direction TB
            AdminCtrl["AdminController"]:::app
            BannerCtrl["BannerController"]:::app
            FilesCtrl["FilesController"]:::app
            CatCtrl["PromotionCategoryController"]:::app
            ContactCtrl["PromotionContactController"]:::app
            ContentCtrl["PromotionContentController"]:::app
            TagsCtrl["TagsController"]:::app
        end
        subgraph "Controllers - API"
            direction TB
            APIBanner["Api/BannerController"]:::app
            APIComment["Api/CommentController"]:::app
            APIPromo["Api/PromotionController"]:::app
        end
        Providers["AppServiceProvider"]:::app
        subgraph "Console & Scheduler"
            direction TB
            Scheduler["UpdatePromotionStatus"]:::app
        end
        subgraph "Queue Worker"
            direction TB
            Worker["Job Worker"]:::app
        end
        subgraph "Models"
            direction TB
            MContent["PromotionContent"]:::model
            MBanner["Banner"]:::model
            MComment["Comment"]:::model
            MTags["Tags"]:::model
            MContact["PromotionContact"]:::model
            MCategory["PromotionCategory"]:::model
            MUser["User"]:::model
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["MySQL/PostgreSQL"]:::db
        Cache["Cache Store"]:::db
        Storage["File Storage"]:::db
        Queue["Queue Backend"]:::db
        MailSvc["Mail Service"]:::db
    end

    %% Front-end Build & Assets
    subgraph "Front-end Assets"
        direction TB
        ViteCfg["vite.config.js"]:::infra
        JSApp["resources/js/app.js"]:::infra
        CSSApp["resources/css/app.css"]:::infra
        AssetsPub["public/js & public/css"]:::infra
        AdminAssets["public/backend assets"]:::infra
    end

    %% Config & Routes
    subgraph "Config & Routes"
        direction TB
        DBConf["config/database.php"]:::infra
        CacheConf["config/cache.php"]:::infra
        QueueConf["config/queue.php"]:::infra
        FSConf["config/filesystems.php"]:::infra
        MailConf["config/mail.php"]:::infra
        ServicesConf["config/services.php"]:::infra
        WebRoutes["routes/web.php"]:::infra
        APIRoutes["routes/api.php"]:::infra
        ConsoleRoutes["routes/console.php"]:::infra
    end

    %% Tests
    subgraph "Tests"
        direction TB
        FeatureTests["tests/Feature"]:::infra
        UnitTests["tests/Unit"]:::infra
    end

    %% Connections
    Browser -->|HTTP/HTML| NGNX
    AdminSPA -->|HTTP/JSON| NGNX
    ThirdParty -->|HTTP/JSON| NGNX
    NGNX --> Entry
    Entry --> Kernel
    Kernel --> Cors
    Cors --> Csrf --> Encrypt --> Trim --> Trust --> AdminCtrl
    Trust --> BannerCtrl
    Trust --> FilesCtrl
    Trust --> CatCtrl
    Trust --> ContactCtrl
    Trust --> ContentCtrl
    Trust --> TagsCtrl
    Trust --> APIBanner
    Trust --> APIComment
    Trust --> APIPromo
    Kernel --> Providers
    AdminCtrl --> MContent
    AdminCtrl --> MBanner
    AdminCtrl --> MComment
    AdminCtrl --> MTags
    AdminCtrl --> MContact
    AdminCtrl --> MCategory
    APIBanner --> MBanner
    APIComment --> MComment
    APIPromo --> MContent
    APIPromo --> MCategory
    APIPromo --> MContact
    APIPromo --> MTags
    AdminCtrl -->|dispatch| Worker
    APIPromo -->|dispatch| Worker
    Scheduler -->|runs| Providers
    Worker -->|process| MContent
    MContent --> DB
    MBanner --> DB
    MComment --> DB
    MTags --> DB
    MContact --> DB
    MCategory --> DB
    MUser --> DB
    MContent --> Storage
    FilesCtrl --> Storage
    AdminCtrl --> MailSvc
    APIBanner --> Cache
    APIPromo --> Cache

    Entry --> WebRoutes
    Entry --> APIRoutes
    Entry --> ConsoleRoutes

    DBConf --> DB
    CacheConf --> Cache
    QueueConf --> Queue
    FSConf --> Storage
    MailConf --> MailSvc
    ServicesConf --> MailSvc
    Queue --> Worker

    ViteCfg --> JSApp
    ViteCfg --> CSSApp
    JSApp --> AssetsPub
    CSSApp --> AssetsPub
    AdminAssets --> AdminSPA

    FeatureTests --> Providers
    UnitTests --> Providers

    %% Click Events
    click Entry "https://github.com/tamthor/km_mobifone/blob/main/public/index.php"
    click Kernel "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Kernel.php"
    click Cors "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Middleware/CorsMiddleware.php"
    click Csrf "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Middleware/VerifyCsrfToken.php"
    click Encrypt "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Middleware/EncryptCookies.php"
    click Trim "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Middleware/TrimStrings.php"
    click Trust "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Middleware/TrustProxies.php"
    click AdminCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/AdminController.php"
    click BannerCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/BannerController.php"
    click FilesCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/FilesController.php"
    click CatCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/PromotionCategoryController.php"
    click ContactCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/PromotionContactController.php"
    click ContentCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/PromotionContentController.php"
    click TagsCtrl "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/TagsController.php"
    click APIBanner "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/Api/BannerController.php"
    click APIComment "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/Api/CommentController.php"
    click APIPromo "https://github.com/tamthor/km_mobifone/blob/main/app/Http/Controllers/Api/PromotionController.php"
    click Scheduler "https://github.com/tamthor/km_mobifone/blob/main/app/Console/Commands/UpdatePromotionStatus.php"
    click Providers "https://github.com/tamthor/km_mobifone/blob/main/app/Providers/AppServiceProvider.php"
    click MContent "https://github.com/tamthor/km_mobifone/blob/main/app/Models/PromotionContent.php"
    click MBanner "https://github.com/tamthor/km_mobifone/blob/main/app/Models/Banner.php"
    click MComment "https://github.com/tamthor/km_mobifone/blob/main/app/Models/Comment.php"
    click MTags "https://github.com/tamthor/km_mobifone/blob/main/app/Models/Tags.php"
    click MContact "https://github.com/tamthor/km_mobifone/blob/main/app/Models/PromotionContact.php"
    click MCategory "https://github.com/tamthor/km_mobifone/blob/main/app/Models/promotionCategory.php"
    click MUser "https://github.com/tamthor/km_mobifone/blob/main/app/Models/User.php"
    click WebRoutes "https://github.com/tamthor/km_mobifone/blob/main/routes/web.php"
    click APIRoutes "https://github.com/tamthor/km_mobifone/blob/main/routes/api.php"
    click ConsoleRoutes "https://github.com/tamthor/km_mobifone/blob/main/routes/console.php"
    click ViteCfg "https://github.com/tamthor/km_mobifone/blob/main/vite.config.js"
    click JSApp "https://github.com/tamthor/km_mobifone/blob/main/resources/js/app.js"
    click CSSApp "https://github.com/tamthor/km_mobifone/blob/main/resources/css/app.css"
    click AdminAssets "https://github.com/tamthor/km_mobifone/blob/main/public/backend/js/app.js"
    click FeatureTests "https://github.com/tamthor/km_mobifone/blob/main/tests/Feature/ExampleTest.php"
    click UnitTests "https://github.com/tamthor/km_mobifone/blob/main/tests/Unit/ExampleTest.php"

    %% Styles
    classDef client fill:#7dafff,stroke:#000,color:#fff
    classDef infra fill:#d3d3d3,stroke:#000
    classDef app fill:#8fbc8f,stroke:#000
    classDef model fill:#90ee90,stroke:#000
    classDef db fill:#f4a460,stroke:#000
```
