# map1605/datn-project architecture

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

- Interactive diagram: https://gitdiagram.com/map1605/datn-project
- Repository: https://github.com/map1605/datn-project

## Overview

##### Project Type and Purpose
- This is a monolithic full-stack e-commerce web application written in PHP, HTML, CSS and JavaScript.
- It supports browsing products, viewing details, managing a cart, checkout, user registration/login and seller channel (“Kênh Người Bán”).

##### File Structure Analysis
- Top-level entrypoint: index.php
- datn-project/
- assets/ (static images)
- css/ (base styles and per-component CSS)
- js/ (component scripts, page-specific scripts, utilities)
- components/ (PHP/HTML partials: header, footer, product cards, etc.)
- pages/ (PHP/HTML endpoints handling routing and business logic)
- Standalone PHP scripts (e.g., get-image.php) for AJAX or media loading
- No separate “backend” microservice: PHP pages and components implement both routing and data access.

##### Missing Architecture Info in README
- README contains only a placeholder.
- We infer a classic LAMP-style stack with MySQL (or similar) as the database.

##### Main System Components
a. Client Browser
b. Web Server (Apache/Nginx + PHP runtime)
c. PHP Application Layer
- Router/Front Controller: index.php and per-page PHP scripts
- View Components: components/*.php & .html
- Business Logic: pages/*.php (cart operations, checkout, searches)
d. Static Assets Server
- CSS (css/base, css/components, main.css)
- JS (js/utils, js/components, js/pages, main.js)
- Images (assets/images)
e. Database
- User, Product, Cart, Order tables
f. External Services (optional)
- Payment gateway for checkout
- Email/SMS service for notifications

##### Relationships & Data Flow
1. Client issues HTTP(S) request for URL → Web Server
2. Web Server invokes index.php or pages/<action>.php
3. PHP script performs:
– Input validation & session/auth checks
– Database queries/updates
– Includes view components to render HTML
4. Server returns assembled HTML + CSS + JS references
5. Browser downloads static assets and executes JS (page scripts & components scripts)
6. JS may call AJAX endpoints (e.g., get-image.php, update-quantity.php) for dynamic updates
7. Checkout triggers server-side order processing and possibly external payment API

##### Architectural Patterns & Principles
- Component-based views: reusable header, footer, product card, banner
- Front Controller pattern via index.php and page scripts
- Separation of concerns:
- Presentation (HTML/CSS)
- Behavior (JS)
- Data Access & Business Logic (PHP + SQL)

##### Technologies & Frameworks
- PHP 7+ for server-side scripting
- Vanilla JavaScript with modular structure (utils, components, pages)
- CSS Modules by folder for maintainability
- Apache/Nginx web server, MySQL or MariaDB database

##### Detailed Capture of Elements
- AJAX endpoints (get-image.php, update-quantity.php)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Client Layer
  subgraph "Client Browser" 
    direction TB
    Browser["User Browser"]:::client
  end

  %% Server Layer
  subgraph "Web Server & PHP Runtime" 
    direction TB
    FC["Front Controller<br>index.php"]:::server
    subgraph "View Components"
      direction TB
      Header["Header Component"]:::view
      Footer["Footer Component"]:::view
      ProductCard["Product Card Component"]:::view
      Banner["Banner Component"]:::view
      SellerChannelComp["Seller Channel Component"]:::view
    end
    subgraph "Business Logic Pages"
      direction TB
      CartPage["Cart Operations Page"]:::biz
      CheckoutPage["Checkout Page"]:::biz
      AddToCart["Add-to-Cart AJAX Endpoint"]:::ajax
      UpdateQty["Update Quantity Endpoint"]:::ajax
      GetImage["Image Loader Endpoint"]:::ajax
      UserReg["User Registration Page"]:::biz
      UserLogin["User Login Page"]:::biz
      ProductDetail["Product Detail Page"]:::biz
      SearchPage["Search Page"]:::biz
    end
  end

  %% Static Assets
  subgraph "Static Asset Delivery"
    direction TB
    CSS["CSS Files"]:::static
    JS["JS Files"]:::static
    Images["Image Files"]:::static
  end

  %% Database
  Database[(Database)]:::db

  %% External Services
  subgraph "External Services"
    direction TB
    Payment["Payment Gateway"]:::external
    Email["Email/SMS Service"]:::external
  end

  %% Data Flows
  Browser -->|"HTTP Request"| FC
  FC -->|"route to"| CartPage
  FC -->|"route to"| CheckoutPage
  FC -->|"route to"| UserReg
  FC -->|"route to"| UserLogin
  FC -->|"route to"| ProductDetail
  FC -->|"route to"| SearchPage

  CartPage -->|"include"| Header
  CartPage -->|"include"| Footer
  CartPage -->|"include"| ProductCard
  CartPage -->|"DB Query/Update"| Database

  CheckoutPage -->|"include"| Header
  CheckoutPage -->|"include"| Footer
  CheckoutPage -->|"include"| Banner
  CheckoutPage -->|"DB Query/Update"| Database
  CheckoutPage -->|"call API"| Payment
  CheckoutPage -->|"send notification"| Email

  ProductDetail -->|"include"| Header
  ProductDetail -->|"include"| Footer
  ProductDetail -->|"include"| ProductCard
  ProductDetail -->|"DB Query"| Database

  SearchPage -->|"include"| Header
  SearchPage -->|"include"| Footer
  SearchPage -->|"DB Query"| Database

  CartPage -->|"include"| SellerChannelComp
  CheckoutPage -->|"include"| SellerChannelComp

  Browser -->|"download"| CSS
  Browser -->|"download"| JS
  Browser -->|"download"| Images

  JS -->|"AJAX Calls"| AddToCart
  JS -->|"AJAX Calls"| UpdateQty
  JS -->|"AJAX Calls"| GetImage

  AddToCart -->|"DB Update"| Database
  UpdateQty -->|"DB Update"| Database
  GetImage -->|"serve image"| Images

  %% Click Events
  click FC "https://github.com/map1605/datn-project/blob/main/datn-project/index.php"
  click Header "https://github.com/map1605/datn-project/blob/main/datn-project/components/header.html"
  click Footer "https://github.com/map1605/datn-project/blob/main/datn-project/components/footer.html"
  click ProductCard "https://github.com/map1605/datn-project/blob/main/datn-project/components/product.php"
  click Banner "https://github.com/map1605/datn-project/blob/main/datn-project/components/banner.html"
  click SellerChannelComp "https://github.com/map1605/datn-project/blob/main/datn-project/components/KenhNguoiBan.php"
  click CartPage "https://github.com/map1605/datn-project/blob/main/datn-project/pages/cart.php"
  click CheckoutPage "https://github.com/map1605/datn-project/blob/main/datn-project/pages/checkout.php"
  click AddToCart "https://github.com/map1605/datn-project/blob/main/datn-project/pages/add-to-cart.php"
  click UpdateQty "https://github.com/map1605/datn-project/blob/main/datn-project/pages/update-quantity.php"
  click GetImage "https://github.com/map1605/datn-project/blob/main/datn-project/pages/get-image.php"
  click UserReg "https://github.com/map1605/datn-project/blob/main/datn-project/pages/dangky.php"
  click UserLogin "https://github.com/map1605/datn-project/blob/main/datn-project/pages/dangnhap.php"
  click ProductDetail "https://github.com/map1605/datn-project/blob/main/datn-project/pages/product-detail.php"
  click SearchPage "https://github.com/map1605/datn-project/blob/main/datn-project/pages/search.php"
  click CSS "https://github.com/map1605/datn-project/blob/main/datn-project/css/base/base.css"
  click CSS "https://github.com/map1605/datn-project/tree/main/datn-project/css/components/"
  click CSS "https://github.com/map1605/datn-project/blob/main/datn-project/css/main.css"
  click JS "https://github.com/map1605/datn-project/blob/main/datn-project/js/main.js"
  click JS "https://github.com/map1605/datn-project/tree/main/datn-project/js/pages/"
  click JS "https://github.com/map1605/datn-project/blob/main/datn-project/js/pages/cart.js"
  click JS "https://github.com/map1605/datn-project/blob/main/datn-project/js/pages/checkout.js"
  click JS "https://github.com/map1605/datn-project/blob/main/datn-project/js/pages/product-detail.js"
  click JS "https://github.com/map1605/datn-project/blob/main/datn-project/js/pages/search.js"
  click JS "https://github.com/map1605/datn-project/tree/main/datn-project/js/components/"
  click JS "https://github.com/map1605/datn-project/blob/main/datn-project/js/components/KenhNguoiBan.js"
  click JS "https://github.com/map1605/datn-project/tree/main/datn-project/js/utils/"
  click Images "https://github.com/map1605/datn-project/tree/main/datn-project/assets/images/"

  %% Styles
  classDef client fill:#AED6F1,stroke:#1B4F72,color:#1B4F72;
  classDef server fill:#A9DFBF,stroke:#145A32,color:#145A32;
  classDef view fill:#F9E79F,stroke:#B9770E,color:#B9770E;
  classDef biz fill:#D2B4DE,stroke:#6C3483,color:#6C3483;
  classDef ajax fill:#F5CBA7,stroke:#B03A2E,color:#B03A2E;
  classDef static fill:#D6EAF8,stroke:#1A5276,color:#1A5276;
  classDef db fill:#FAD7A0,stroke:#7D6608,color:#7D6608;
  classDef external fill:#D5D8DC,stroke:#566573,color:#566573;
```
