# phuclemon/vysoulcosmetic architecture

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

- Interactive diagram: https://gitdiagram.com/phuclemon/vysoulcosmetic
- Repository: https://github.com/phuclemon/vysoulcosmetic

## Overview

##### Project Overview
- This is a full-stack web application built in PHP using the MVC architecture pattern.
- Its purpose is to serve as an e-commerce website for cosmetics, with distinct interfaces and functionalities for Admin (management of products, orders, etc.) and User (browsing, cart, checkout).
- The project uses PHP for server-side logic, MySQL as its database (see the SQL file), and HTML/CSS/JavaScript for front-end interactions (with static assets stored in the Public folder).

##### Analyzing the File Structure
- Top-Level Files/Folders:
- Public: Contains static assets (CSS, JavaScript, images, fonts) which are rendered on the client side.
- index.php: Likely the main entry point for the application.
- mvc: Houses the core MVC architecture components:
▪ Controllers: Contains PHP files handling HTTP requests for Admin and User functionalities.
▪ Models: Contains business logic and database interactions (including separate sub-folders for Admin-related models and general models).
▪ Views: Contains the front-end HTML templates for both Admin and User, organized to clearly separate display blocks, layouts, and pages.
- Core: Contains essential components like App.php (application initialization), Controller.php (base controller), and Database.php.
- Other artifacts: SQL file for database schema and multiple README files for documentation.

##### Main System Components
A. Client Side:
- Web Browser: Renders HTML/CSS/JavaScript from the Public folder.
- Interaction Elements: Static UI assets (stylesheets, scripts), and user-initiated actions like searching, adding to cart, and navigating pages.
B. Web Server / PHP Application:
- Entry Point (index.php): Routes incoming requests.
- MVC Bridge (Bridge.php): Likely responsible for routing or initializing controllers.
- Controllers: Different controllers for both Admin (Bills, Branch, Customer, etc.) and User (TrangChu, SanPham, GioHang, etc.) that process user requests, manage sessions, and enforce action routing.
- Core Components: App, Controller, and Database which manage application bootstrapping and connection to MySQL.
C. Models:
- Data Access Layer: Handles business logic and CRUD operations for products, orders, user accounts, etc.
D. Views:
- Template Engine: Contains reusable blocks, layouts, and pages which render dynamic data from controllers.
E. Database (MySQL):
- Persist data related to users, products, orders, and sessions (schema provided by “u378271986_MyPham.sql”).

##### Relationships and Data Flow
- Requests originate from the client (browser) and are routed by the index.php entry point.
- An MVC Bridge then directs requests to the corresponding controller.
- Controllers invoke Models to retrieve/update data from the MySQL database.
- Once data is processed, controllers pass it to Views, which generate HTML/CSS/JavaScript responses.
- Public folder assets support styling and client-side interactions, including AJAX calls (handled by Public/js/ajax.js) for dynamic content updates.
- For administrative functionalities, separate directories in Controllers, Models, and Views (i.e., within /Admin) ensure proper role-based handling.

##### Architectural Patterns & Design Principles
- Clear MVC Separation: Models (business logic, database operations), Views (rendering), and Controllers (business process flow) are all separated.
- Role-based Access: Distinct Admin and User areas managed by different controllers and views.
- Modular Organization: Distinct folders for static content and dynamic PHP components to facilitate scalability and easier maintenance.
- The use of JavaScript (and libraries such as jQuery/Bootstrap) on the front-end to improve user interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    C1["Browser (Client)"]:::client
    C2["Public Assets"]:::static
    click C2 "https://github.com/phuclemon/vysoulcosmetic/tree/main/Public"
    
    %% Entry Point
    EP["index.php (Entry Point)"]:::entry
    click EP "https://github.com/phuclemon/vysoulcosmetic/blob/main/index.php"
    
    %% MVC Bridge
    MB["MVC Bridge"]:::bridge
    click MB "https://github.com/phuclemon/vysoulcosmetic/blob/main/mvc/Bridge.php"
    
    %% Core Components
    CORE["MVC Core (App,Controller,Database)"]:::core
    click CORE "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Core"
    
    %% Controllers Subgraph
    subgraph "Controllers"
        AC["Admin Controllers"]:::controller
        click AC "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Controllers/Admin"
        UC["User Controllers"]:::controller
        click UC "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Controllers"
        AJAX["AJAX Controller"]:::controller
        click AJAX "https://github.com/phuclemon/vysoulcosmetic/blob/main/mvc/Controllers/Ajax.php"
    end
    
    %% Models Subgraph
    subgraph "Models"
        AM["Admin Models"]:::model
        click AM "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Models/Admin"
        UM["User Models"]:::model
        click UM "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Models"
    end
    
    %% Views Subgraph
    subgraph "Views"
        AV["Admin Views"]:::view
        click AV "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Views/Admin"
        UV["User Views"]:::view
        click UV "https://github.com/phuclemon/vysoulcosmetic/tree/main/mvc/Views/User"
    end
    
    %% External Database
    DB["MySQL Database"]:::database
    click DB "https://github.com/phuclemon/vysoulcosmetic/blob/main/u378271986_MyPham.sql"
    
    %% Data Flow Arrows
    C1 -- "HTTP_Request" --> EP
    EP -- "route" --> MB
    MB -- "init" --> CORE
    MB -- "dispatch" --> AC
    MB -- "dispatch" --> UC
    MB -- "ajax_call" --> AJAX
    
    %% Admin Flow
    AC -- "data_ops" --> AM
    AM -- "query" --> DB
    AC -- "render" --> AV
    
    %% User Flow
    UC -- "data_ops" --> UM
    UM -- "query" --> DB
    UC -- "render" --> UV
    
    %% AJAX Flow (assumed interaction with Models and Views)
    AJAX -- "data_ops" --> UM
    
    %% Public Assets support
    C1 -- "load_assets" --> C2

    %% Class Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef static fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px;
    classDef entry fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef bridge fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef core fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef controller fill:#ABEBC6,stroke:#138D75,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef view fill:#F5CBA7,stroke:#A04000,stroke-width:2px;
    classDef database fill:#E59866,stroke:#9C640C,stroke-width:2px;
```
