# gnuh24/sgu-php architecture

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

- Interactive diagram: https://gitdiagram.com/gnuh24/sgu-php
- Repository: https://github.com/gnuh24/sgu-php

## Overview

##### Project Type and Purpose
- It is a full-stack web application built using PHP and organized using an MVC (Model–View–Controller) pattern.
- The project supports multiple user roles (such as admin, manager, and regular user) with modules for account handling, product management, order processing, inventory, supplier management, statistics, and more.
- The README (although showing a shell function for searching student names) indicates that this project is part of an advanced web programming course (SGU Lập trình web nâng cao). This code snippet might be an auxiliary tool, but the overall project architecture is centered on the PHP/MVC application.

##### Analyzing the File Structure
- Top-level Files/Directories:
- index.php: Likely the main entry point that bootstraps the application.
- SQLFile: Contains SQL scripts for database creation, queries, and a database design file (logical.mwb) indicating planned database relationships.
- src: The heart of the application that is subdivided into config, controller, model, public, and view directories.
- Key Directories:
- src/config: Houses configuration files (e.g., MysqlConfig.php) that set up the database connection.
- src/controller: Contains many subdirectories corresponding to application modules (Account, Admin, Home, Inventory, Order, Product, ProductType, Supplier, ThongKe, etc.). Each subdirectory (and files within) represents controllers that handle route-specific business logic.
- src/model: Contains models for each module that encapsulate data access and domain logic (e.g., ProductModels, CartModel, InventoryModel).
- src/view: Includes view files with PHP/HTML, CSS, and JS for rendering the user interface. It is further subdivided based on modules (account, admin, cart, detail don hang, etc.).
- src/public: Contains public/static assets (images, template files, CSS, JS) used for the front-end presentation.
- Other Notable Elements:
- Multiple SQL scripts and a MySQL Workbench file suggest a relational database backend design.
- The file tree indicates that the application is modular and employs clear separations between layers.

a. Main Components:
- Client/Browser – Represents the user interface (views/templates in src/view and src/public).
- Web Server/Application Entry Point – index.php that channels requests into the application.
- Controllers – Located in src/controller; they receive incoming HTTP requests, validate data, coordinate with models, and assemble responses.
- Models – In src/model; these abstract database operations and encapsulate business logic.
- Database – Backed by MySQL (as suggested by src/config/MysqlConfig.php and the SQLFile directory with scripts, queries, and design files).
- Supporting Assets – Static resources like CSS, JavaScript, and images found in src/public help build the UI.

b. Relationships and Interactions:
- Request Flow: A browser makes a request → index.php routes to the appropriate controller → the controller accesses models (and thus the database) → the controller passes data to the view.
- “Client” to “Web Server/Entry Point”
- “Web Server” to “Controllers”
- “Controllers” to “Models” (for data operations) and to “Views” (for rendering output)
- “Models” to “Database” (data storage and retrieval)
- Internal module interactions where controllers or models for one feature (like Inventory) might interact with those for orders or suppliers.

c. Architectural Patterns & Design Principles:
- Modular Approach: Emphasize the project’s modular design with distinct components (e.g., separate controllers for Admin, Home, Product, Order, etc.).
- Config and Dependency Management: Show how configuration (e.g., MysqlConfig.php) is injected into models or controllers.
- Database Interactions: Represent SQL scripts and the underlying relational database schema as part of the data layer.

d. Relevant Technologies, Frameworks, and Libraries:
- PHP as the programming language.
- MySQL as the database (configured via MysqlConfig.php and managed by SQL scripts).
- HTML, CSS, and JavaScript for front-end rendering (found in src/public and src/view).
- Any additional libraries (implied by file names such as “font-awesome.css” found in the public templates) can be noted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client/Browser"):::client
    Entry("index.php (Entry Point)"):::server
    Config("MysqlConfig.php (src/config/MysqlConfig.php)"):::config

    subgraph "Controllers (Business Logic)"
        direction TB
        AccC("Account Controller"):::controller
        AdminC("Admin Controller"):::controller
        HomeC("Home Controller"):::controller
        InvC("Inventory Controller"):::controller
        ManC("Manager & Order Controller"):::controller
        ProdC("Product Controller"):::controller
        ProdTypeC("Product Type Controller"):::controller
        SuppC("Supplier Controller"):::controller
        ThongKeC("Statistics Controller"):::controller
        ThongTinC("User Information Controller"):::controller
        CartC("Cart/Order Detail Controller"):::controller
    end

    subgraph "Models (Data Access)"
        direction TB
        AccM("Account Models"):::model
        CartM("Cart Models"):::model
        InvM("Inventory Models"):::model
        ProdM("Product Models"):::model
        ProdTypeM("Product Type Models"):::model
        SuppM("Supplier Models"):::model
        ThongKeM("Statistics Models"):::model
    end

    subgraph "Presentation (UI Layer)"
        direction TB
        Views("Views (src/view/)"):::view
        FrontEnd("Front-end Assets (src/public/template/frontEnd/)"):::view
        Shared("Shared Assets (src/view/assets/ & src/public)"):::view
    end

    DB("SQL Scripts & DB Design (SQLFile/)"):::database

    Client -->|"HTTP_Request"| Entry
    Entry -->|"Routes_to"| AccC
    Entry -->|"Routes_to"| AdminC
    Entry -->|"Routes_to"| HomeC
    Entry -->|"Routes_to"| InvC
    Entry -->|"Routes_to"| ManC
    Entry -->|"Routes_to"| ProdC
    Entry -->|"Routes_to"| ProdTypeC
    Entry -->|"Routes_to"| SuppC
    Entry -->|"Routes_to"| ThongKeC
    Entry -->|"Routes_to"| ThongTinC
    Entry -->|"Routes_to"| CartC
    Entry -->|"Uses"| Config

    AccC -->|"Calls"| AccM
    AdminC -->|"Calls"| AccM
    HomeC -->|"Calls"| AccM
    InvC -->|"Calls"| InvM
    ManC -->|"Calls"| CartM
    ProdC -->|"Calls"| ProdM
    ProdTypeC -->|"Calls"| ProdTypeM
    SuppC -->|"Calls"| SuppM
    ThongKeC -->|"Calls"| ThongKeM
    ThongTinC -->|"Calls"| AccM
    CartC -->|"Calls"| CartM

    AccC -->|"Renders"| Views
    AdminC -->|"Renders"| Views
    HomeC -->|"Renders"| Views
    InvC -->|"Renders"| Views
    ManC -->|"Renders"| Views
    ProdC -->|"Renders"| Views
    ProdTypeC -->|"Renders"| Views
    SuppC -->|"Renders"| Views
    ThongKeC -->|"Renders"| Views
    ThongTinC -->|"Renders"| Views
    CartC -->|"Renders"| Views

    AccM -->|"DB_Operations"| DB
    CartM -->|"DB_Operations"| DB
    InvM -->|"DB_Operations"| DB
    ProdM -->|"DB_Operations"| DB
    ProdTypeM -->|"DB_Operations"| DB
    SuppM -->|"DB_Operations"| DB
    ThongKeM -->|"DB_Operations"| DB

    Views -->|"Loads_Assets"| FrontEnd
    Views -->|"Loads_Assets"| Shared

    click Entry "https://github.com/gnuh24/sgu-php/blob/main/index.php"
    click Config "https://github.com/gnuh24/sgu-php/blob/main/src/config/MysqlConfig.php"
    click AccC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/AccountController/"
    click AdminC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/AdminController/"
    click HomeC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/HomeController/"
    click InvC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/InventoryController/"
    click ManC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/ManagerController/"
    click ProdC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/ProductController/"
    click ProdTypeC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/ProductTypeController/"
    click SuppC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/SupplierController/"
    click ThongKeC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/ThongKeController/"
    click ThongTinC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/ThongTinUser/"
    click CartC "https://github.com/gnuh24/sgu-php/tree/main/src/controller/cartControll/"
    click AccM "https://github.com/gnuh24/sgu-php/tree/main/src/model/AccountModels/"
    click CartM "https://github.com/gnuh24/sgu-php/tree/main/src/model/CartModel/"
    click InvM "https://github.com/gnuh24/sgu-php/tree/main/src/model/InventoryModel/"
    click ProdM "https://github.com/gnuh24/sgu-php/tree/main/src/model/ProductModels/"
    click ProdTypeM "https://github.com/gnuh24/sgu-php/tree/main/src/model/ProductTypeModel/"
    click SuppM "https://github.com/gnuh24/sgu-php/tree/main/src/model/SupplierModels/"
    click ThongKeM "https://github.com/gnuh24/sgu-php/tree/main/src/model/ThongKeModel/"
    click Views "https://github.com/gnuh24/sgu-php/tree/main/src/view/"
    click FrontEnd "https://github.com/gnuh24/sgu-php/tree/main/src/public/template/frontEnd/"
    click Shared "https://github.com/gnuh24/sgu-php/tree/main/src/view/assets/"
    click DB "https://github.com/gnuh24/sgu-php/tree/main/SQLFile/"

    classDef client fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef server fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef config fill:#FFD1DC,stroke:#333,stroke-width:2px;
    classDef controller fill:#C1E1C1,stroke:#333,stroke-width:2px;
    classDef model fill:#F2D1D1,stroke:#333,stroke-width:2px;
    classDef view fill:#E0BBE4,stroke:#333,stroke-width:2px;
    classDef database fill:#D3D3D3,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
