# phanhuuphuc/training_project architecture

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

- Interactive diagram: https://gitdiagram.com/phanhuuphuc/training_project
- Repository: https://github.com/phanhuuphuc/training_project

## Overview

##### Project Type and Purpose
- This is a Laravel-based full-stack application.
- The application appears to manage entities such as Customers, Products, and Users. It provides API endpoints, web pages, and authentication processes, while incorporating a clean separation of concerns (controllers, services, repositories, and models).
- The project also includes additional directories (like “packages/mi/l5-core”) that extend core functionality with custom commands and shared libraries.

##### File Structure
- Core Directories:
- app: Contains the core business logic:
▪ Http – Controllers (including Auth, Customer, Product, Profile, User), Middleware, Form Requests, and Resources.
▪ Models – Domain models for Customer, Product, Setting, and User, as well as model traits.
▪ Services – Business logic for handling operations related to Customers, Products, and Users.
▪ Repositories – Data access abstraction for working with entities.
▪ Exceptions, Filters, and Criteria – Custom error handling, request filtering, and query criteria to encapsulate common logic.
- routes: Defines API endpoints and web routes to wire up controllers.
- resources: Contains frontend assets including JS (React components indicated by .jsx files), CSS, and Blade view files for server-side rendering.
- database: Contains migrations, seeders, and factories for setting up and populating the database.
- packages/mi/l5-core: A custom or third-party package that provides scaffold commands, base classes, contracts, and shared traits for Criteria, Filters, Repositories, and Services.
- public: Entry point of the application (index.php), static assets, and configuration (e.g., .htaccess).
- tests: Contains unit and feature tests for ensuring the application behaves as expected.

##### Components and Their Interactions
- Frontend / Presentation Layer:
- resources/views and resources/js: Serve the UI templates (Blade files) and React components for interactivity.
- public: Hosts assets and the entry point for web requests.
- HTTP Layer:
- Controllers in app/Http/Controllers act as the entry point for web/API requests.
- Middleware in app/Http/Middleware processes requests (authentication, CSRF protection, role validation, etc.).
- Form Request validation classes ensure incoming data is validated.
- Business Logic Layer:
- Services (app/Services) encapsulate business rules and use Repositories to communicate with data sources.
- Repositories (app/Repositories) provide abstraction over models and query logic.
- Filters and Criteria help customize queries dynamically.
- Domain / Data Layer:
- Models (app/Models) represent business entities and are used with Eloquent ORM.
- Database: Configured via migrations, seeders, and factories to set up the underlying data store.
- Shared & Infrastructure Components:
- Packages (packages/mi/l5-core) extend or scaffold additional functionality like custom commands (artisan commands) and provide contracts and traits.
- Console: Commands to run scheduled tasks or maintenance jobs.
- Testing: Unit and feature tests ensure reliability.

##### Architectural Patterns and Design Principles
- MVC Pattern: Clear separation between Controllers, Models, and Views.
- Service and Repository Patterns: Encapsulation of business logic in services and data access via repositories ensures modularity and easier testing.
- Middleware: Provides cross-cutting concerns such as authentication, request trimming, encryption, etc.
- Layered Architecture: Distinct presentation, business, and data layers, along with extension points (packages) and testing.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    ExternalClients("External Clients"):::client

    %% Public Layer
    PublicLayer("Public Layer\n(index.php)"):::public

    %% HTTP Layer
    subgraph "HTTP Layer"
        subgraph "Routes"
            WebRoutes("Web Routes\n(web.php)"):::http
            ApiRoutes("API Routes\n(api.php)"):::http
            AuthRoutes("Auth Routes\n(auth.php)"):::http
            ChannelsRoutes("Channels Routes\n(channels.php)"):::http
            ConsoleRoutes("Console Routes\n(console.php)"):::http
        end
        Controllers("HTTP Controllers"):::http
        Middleware("Middleware"):::http
        FormRequests("Form Requests"):::http
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Services("Services\n(app/Services)"):::business
        Repositories("Repositories\n(app/Repositories)"):::business
        Filters("Filters\n(app/Filters)"):::business
        Criteria("Criteria\n(app/Criteria)"):::business
    end

    %% Data Layer
    subgraph "Data Layer"
        Models("Models\n(app/Models)"):::data
        Database("Database\n(database)"):::data
    end

    %% Shared & Infrastructure Components
    Packages("Packages\n(mi/l5-core)"):::shared
    Console("Console/CLI\n(app/Console)"):::shared

    %% Frontend / Presentation Layer
    subgraph "Frontend / Presentation Layer"
        BladeViews("Blade Views\n(resources/views)"):::frontend
        ReactComponents("React Components\n(resources/js)"):::frontend
    end

    %% Connections for main flow
    ExternalClients --> PublicLayer
    PublicLayer --> WebRoutes
    PublicLayer --> ApiRoutes
    PublicLayer --> AuthRoutes
    PublicLayer --> ChannelsRoutes
    PublicLayer --> ConsoleRoutes

    WebRoutes --> Controllers
    ApiRoutes --> Controllers
    AuthRoutes --> Controllers
    ChannelsRoutes --> Controllers
    ConsoleRoutes --> Controllers

    Middleware --> Controllers
    Controllers --> FormRequests
    Controllers --> Services
    Services --> Repositories
    Repositories --> Filters
    Repositories --> Criteria
    Repositories --> Models
    Models --> Database

    %% Packages and Console interactions
    Packages --> Services
    Packages --> Repositories
    Packages --> Console

    %% Public layer leads to Frontend
    PublicLayer --> BladeViews
    PublicLayer --> ReactComponents

    %% Class Definitions
    classDef client fill:#c0ffc0,stroke:#333,stroke-width:2px;
    classDef public fill:#ffd700,stroke:#333,stroke-width:2px;
    classDef http fill:#87cefa,stroke:#333,stroke-width:2px;
    classDef business fill:#ffa07a,stroke:#333,stroke-width:2px;
    classDef data fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef shared fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef frontend fill:#90ee90,stroke:#333,stroke-width:2px;

    %% Click Events
    click PublicLayer "https://github.com/phanhuuphuc/training_project/blob/master/public/index.php"
    click WebRoutes "https://github.com/phanhuuphuc/training_project/blob/master/routes/web.php"
    click ApiRoutes "https://github.com/phanhuuphuc/training_project/blob/master/routes/api.php"
    click AuthRoutes "https://github.com/phanhuuphuc/training_project/blob/master/routes/auth.php"
    click ChannelsRoutes "https://github.com/phanhuuphuc/training_project/blob/master/routes/channels.php"
    click ConsoleRoutes "https://github.com/phanhuuphuc/training_project/blob/master/routes/console.php"
    click Controllers "https://github.com/phanhuuphuc/training_project/tree/master/app/Http/Controllers"
    click Middleware "https://github.com/phanhuuphuc/training_project/tree/master/app/Http/Middleware"
    click FormRequests "https://github.com/phanhuuphuc/training_project/tree/master/app/Http/Requests"
    click Services "https://github.com/phanhuuphuc/training_project/tree/master/app/Services"
    click Repositories "https://github.com/phanhuuphuc/training_project/tree/master/app/Repositories"
    click Filters "https://github.com/phanhuuphuc/training_project/tree/master/app/Filters"
    click Criteria "https://github.com/phanhuuphuc/training_project/tree/master/app/Criteria"
    click Models "https://github.com/phanhuuphuc/training_project/tree/master/app/Models"
    click Database "https://github.com/phanhuuphuc/training_project/tree/master/database"
    click Packages "https://github.com/phanhuuphuc/training_project/tree/master/packages/mi/l5-core"
    click Console "https://github.com/phanhuuphuc/training_project/tree/master/app/Console"
    click BladeViews "https://github.com/phanhuuphuc/training_project/tree/master/resources/views"
    click ReactComponents "https://github.com/phanhuuphuc/training_project/tree/master/resources/js"
```
