# dbpcod/web-nangcao architecture

> Architecture diagram of the GitHub repository dbpcod/web-nangcao, 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/dbpcod/web-nangcao
- Repository: https://github.com/dbpcod/web-nangcao

## Overview

##### Project Type and Purpose
- The file structure and naming conventions indicate that this is a full-stack web application built using the MVC (Model-View-Controller) architectural pattern.
- The presence of both administrative and user sections (found in the views folder) suggests the application serves two distinct roles – one for management (i.e., admin dashboard) and one for end-users (i.e., storefront or portal).
- Additionally, files in the “database” and “erd” directories hint at robust data modeling and significant emphasis on database design, which means the project also pays close attention to data integrity and relational structure.

##### Analyzing the File Structure
- The “src” Directory: This is where the main code lives and is organized following the MVC pattern.
∙ “controllers”: Each file here (e.g., AuthController.php, HoaDonController.php) handles specific parts of the application’s logic and request routing.
∙ “models”: These files (e.g., HoaDonModel.php, SanPhamModel.php) manage data interactions and business logic, including database operations via a central DB.php.
∙ “views”: Divided into “admin” and “user” subdirectories, these files define the presentation layer for different user interfaces.
- The “src/public” directory holds static assets (CSS, JS, images) and third-party libraries (like Bootstrap and jQuery), which are used by the views to render the frontend.

a. Main Components to Include:
- Web Server/Application Server hosting the PHP application (configuration driven by config.php).
- MVC Framework Components:
- Controllers: Represent business logic and request handling.
- Models: Handle database operations, encapsulated business logic, and data management.
- Views: Separate user interfaces for admin and user sections.
- Public Assets: Represent additional static content like CSS, JS, and images which support both the admin and user interfaces.

b. Relationships and Interactions:
- User Requests: HTTP requests from browsers (both admin and user views) hit the web server and are routed to specific controllers.
- Controller-Model Interaction: Controllers call the corresponding models to fetch, update, or store data.
- Model-Database Interaction: Models use the DB.php (and possibly SessionManager or CookieManager) to interact with the database.
- Public Assets Delivery: Static file requests for CSS, JavaScript, images are served from the “src/public” directory.

c. Architectural Patterns and Design Principles:
- The MVC pattern is central: clearly separate data (models), business logic (controllers), and presentation (views).
- Modular Design: Each controller and model handles a specific domain (such as products, promotions, orders), suggesting highly modular components.
- Clear Layer Separation: Document how static assets (public folder) and view templates are decoupled from core business logic.

d. Technologies, Frameworks, or Libraries:
- PHP as the primary backend language.
- Bootstrap and jQuery for frontend styling and interactivity.
- Standard SQL (as indicated by the ss.sql file) for relational database management.
- The organization of controllers, models, and views suggests custom or lightweight MVC framework usage.

- The communication from frontend (browser) to controllers.
- Controllers invoking models.
- Models interacting with the database.
- How responses are funneled back via views to the user.
- Differentiate components:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Client (Browser)"]:::client

    %% Web Server Layer
    WebServer["Web Server (PHP)"]:::backend

    %% Public Assets
    PublicAssets["Public Assets"]:::frontend

    %% MVC Layer
    subgraph "MVC Layer"
        direction TB
        Controllers["Controllers"]:::backend
        Models["Models"]:::backend
        DBConn["DB Connector"]:::backend
        ViewsAdmin["Views - Admin"]:::frontend
        ViewsUser["Views - User"]:::frontend
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        DatabaseSQL["Database (SQL)"]:::database
        ERDiagrams["ER Diagrams"]:::database
    end

    %% Documentation & Design
    Documentation["Documentation & Design"]:::documentation

    %% Connections
    Client -->|"HTTP_Request"| WebServer
    WebServer -->|"Routes_to"| Controllers
    Controllers -->|"Calls"| Models
    Models -->|"Uses"| DBConn
    DBConn -->|"Queries_Updates"| DatabaseSQL
    Controllers -->|"Renders_Admin"| ViewsAdmin
    Controllers -->|"Renders_User"| ViewsUser
    PublicAssets -->|"Serves_to_Admin"| ViewsAdmin
    PublicAssets -->|"Serves_to_User"| ViewsUser
    DatabaseSQL -->|"Based_on"| ERDiagrams
    Documentation -->|"Guides"| ERDiagrams
    Documentation -->|"Informs"| Controllers

    %% Click Events
    click WebServer "https://github.com/dbpcod/web-nangcao/blob/main/config.php"
    click Controllers "https://github.com/dbpcod/web-nangcao/tree/main/src/mvc/controllers"
    click Models "https://github.com/dbpcod/web-nangcao/tree/main/src/mvc/models"
    click DBConn "https://github.com/dbpcod/web-nangcao/blob/main/src/mvc/core/DB.php"
    click ViewsAdmin "https://github.com/dbpcod/web-nangcao/tree/main/src/mvc/views/admin"
    click ViewsUser "https://github.com/dbpcod/web-nangcao/tree/main/src/mvc/views/user"
    click PublicAssets "https://github.com/dbpcod/web-nangcao/tree/main/src/public"
    click DatabaseSQL "https://github.com/dbpcod/web-nangcao/blob/main/database/ss.sql"
    click ERDiagrams "https://github.com/dbpcod/web-nangcao/tree/main/erd"
    click Documentation "https://github.com/dbpcod/web-nangcao/tree/main/DacTa"

    %% Styles
    classDef backend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef frontend fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef client fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef documentation fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
