# cuong75201/book-store architecture

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

- Interactive diagram: https://gitdiagram.com/cuong75201/book-store
- Repository: https://github.com/cuong75201/book-store

## Overview

##### Project type and purpose
- This is a full-stack web application (online bookstore) built in PHP following a custom MVC pattern.
- Two main actors: end-users (customers) and Admin.
- Key features: product browsing, shopping cart, user profile, order management, admin product/user management.

##### File structure
- Root files:
- .htaccess – URL rewriting for friendly routes
- index.php – application entry point (bootstraps MVC router)
- config.php – global constants, DB credentials
- admin2/ – legacy or alternate admin UI layer
- database/book_store.sql – database schema and seed data
- media/ – static images (products, banners)
- public/ – public-facing assets
- css/ – style sheets
- js/ – client-side scripts (AjaxLogin, pagination, admin CRUD, etc.)
- lib/bootstrap… – Bootstrap 4.5 distribution
- mvc/ – core MVC implementation
- core/app.php – URL router → controllers
- core/controller.php – base controller class
- core/dbconnect.php – database connector (MySQL)
- controllers/ – all HTTP action handlers (home, product, account, admin, etc.)
- models/ – data access models mapping to tables (User, Cart, Order, Product, Category…)
- views/ – UI templates (layouts, partials, pages, admin pages)

##### README for architecture insights
- Describes MVC flow: incoming URL → app.php router → controller/action → view render or model query.
- Technologies: PHP, MySQL, JS, CSS, Bootstrap.

##### Key details to capture
- Authentication flow for user vs admin paths
- AJAX endpoints vs full-page renders
- Partials and layout inclusion
- Database schema footprint (tables represented by models)
- Asset dependencies (Bootstrap CSS/JS)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    Browser["Web Browser UI"]:::ui
    Browser -->|"HTTP Request"| htaccess
    Browser -->|"Fetch Static Assets"| StaticAssets

    %% URL Rewriting and Front Controller
    htaccess[".htaccess"]:::logic
    htaccess --> index
    index["index.php"]:::logic
    index --> FrontController
    FrontController["Front Controller (mvc/core/app.php)"]:::logic

    %% Configuration and DB Connect
    config["config.php"]:::logic
    FrontController --> config
    dbconnect["mvc/core/dbconnect.php"]:::logic
    FrontController --> dbconnect

    %% MVC Application
    subgraph "Controllers" 
        direction TB
        HomeCtrl["home.php"]:::logic
        ProdCtrl["product.php"]:::logic
        AccCtrl["account.php"]:::logic
        CartCtrl["cart.php"]:::logic
        AdminCtrl["admin.php"]:::logic
        CollCtrl["collections.php"]:::logic
        PagesCtrl["pages.php"]:::logic
    end
    FrontController --> HomeCtrl
    FrontController --> ProdCtrl
    FrontController --> AccCtrl
    FrontController --> CartCtrl
    FrontController --> AdminCtrl
    FrontController --> CollCtrl
    FrontController --> PagesCtrl

    subgraph "Models"
        direction TB
        UserModel["UserModel.php"]:::data
        CartModel["CartModel.php"]:::data
        OrderModel["DonHangModel.php"]:::data
        ProdModel["SachModel.php"]:::data
        CatModel["danhmucModel.php"]:::data
        GenreModel["theloaiModel.php"]:::data
        CartItemModel["ctiet_cartModel.php"]:::data
        OrderItemModel["ctiet_don_hangModel.php"]:::data
        AddressModel["AddressModel.php"]:::data
        NccModel["NccModel.php"]:::data
        StaffModel["NhanVienModel.php"]:::data
    end
    HomeCtrl --> UserModel
    ProdCtrl --> ProdModel
    AccCtrl --> UserModel
    CartCtrl --> CartModel
    CartCtrl --> CartItemModel
    AdminCtrl --> StaffModel
    AdminCtrl --> NccModel
    CollCtrl --> CatModel
    PagesCtrl --> OrderModel

    UserModel --> Database
    CartModel --> Database
    OrderModel --> Database
    ProdModel --> Database
    CatModel --> Database
    GenreModel --> Database
    CartItemModel --> Database
    OrderItemModel --> Database
    AddressModel --> Database
    NccModel --> Database
    StaffModel --> Database

    subgraph "Views"
        direction TB
        Layout["main_layout.php"]:::ui
        MainView["main.php"]:::ui
        ProdDetail["product_detail.php"]:::ui
        Header["inc/header.php"]:::ui
        Footer["inc/footer.php"]:::ui
        Navbar["inc/navbar.php"]:::ui
        Carousel["inc/carousel.php"]:::ui
        Script["inc/script.php"]:::ui
        Head["inc/head.php"]:::ui
        AdminProd["AdminPage/product.php"]:::ui
        AdminStaff["AdminPage/nhanvien.php"]:::ui
        AdminOrder["AdminPage/donhang.php"]:::ui
    end

    HomeCtrl --> Layout
    ProdCtrl --> ProdDetail
    AccCtrl --> MainView
    AdminCtrl --> AdminProd
    AdminCtrl --> AdminStaff
    AdminCtrl --> AdminOrder

    Layout --> Header
    Layout --> Navbar
    Layout --> Footer
    Layout --> Carousel
    Layout --> Script
    Layout --> Head
    MainView --> Browser
    ProdDetail --> Browser
    AdminProd --> Browser

    %% Static Assets
    subgraph StaticAssets["Static Asset Server"]
        direction TB
        CSS["public/css"]:::external
        JS["public/js"]:::external
        Bootstrap["public/lib/bootstrap-4.5.3-dist"]:::external
        Media["media"]:::external
    end

    Browser --> CSS
    Browser --> JS
    Browser --> Bootstrap
    Browser --> Media

    %% Database
    Database["MySQL Database\n(book_store)"]:::data

    %% Click Events
    click htaccess "https://github.com/cuong75201/book-store/blob/main/.htaccess"
    click index "https://github.com/cuong75201/book-store/blob/main/index.php"
    click FrontController "https://github.com/cuong75201/book-store/blob/main/mvc/core/app.php"
    click config "https://github.com/cuong75201/book-store/blob/main/config.php"
    click dbconnect "https://github.com/cuong75201/book-store/blob/main/mvc/core/dbconnect.php"
    click HomeCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/home.php"
    click ProdCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/product.php"
    click AccCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/account.php"
    click CartCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/cart.php"
    click AdminCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/admin.php"
    click CollCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/collections.php"
    click PagesCtrl "https://github.com/cuong75201/book-store/blob/main/mvc/controllers/pages.php"
    click UserModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/UserModel.php"
    click CartModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/CartModel.php"
    click OrderModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/DonHangModel.php"
    click ProdModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/SachModel.php"
    click CatModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/danhmucModel.php"
    click GenreModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/theloaiModel.php"
    click CartItemModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/ctiet_cartModel.php"
    click OrderItemModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/ctiet_don_hangModel.php"
    click AddressModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/AddressModel.php"
    click NccModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/NccModel.php"
    click StaffModel "https://github.com/cuong75201/book-store/blob/main/mvc/models/NhanVienModel.php"
    click Layout "https://github.com/cuong75201/book-store/blob/main/mvc/views/main_layout.php"
    click MainView "https://github.com/cuong75201/book-store/blob/main/mvc/views/main.php"
    click ProdDetail "https://github.com/cuong75201/book-store/blob/main/mvc/views/product_detail.php"
    click Header "https://github.com/cuong75201/book-store/blob/main/mvc/views/inc/header.php"
    click Footer "https://github.com/cuong75201/book-store/blob/main/mvc/views/inc/footer.php"
    click Navbar "https://github.com/cuong75201/book-store/blob/main/mvc/views/inc/navbar.php"
    click Carousel "https://github.com/cuong75201/book-store/blob/main/mvc/views/inc/carousel.php"
    click Script "https://github.com/cuong75201/book-store/blob/main/mvc/views/inc/script.php"
    click Head "https://github.com/cuong75201/book-store/blob/main/mvc/views/inc/head.php"
    click AdminProd "https://github.com/cuong75201/book-store/blob/main/mvc/views/AdminPage/product.php"
    click AdminStaff "https://github.com/cuong75201/book-store/blob/main/mvc/views/AdminPage/nhanvien.php"
    click AdminOrder "https://github.com/cuong75201/book-store/blob/main/mvc/views/AdminPage/donhang.php"
    click CSS "https://github.com/cuong75201/book-store/tree/main/public/css"
    click JS "https://github.com/cuong75201/book-store/tree/main/public/js"
    click Bootstrap "https://github.com/cuong75201/book-store/blob/main/public/lib/bootstrap-4.5.3-dist"
    click Media "https://github.com/cuong75201/book-store/tree/main/media"
    click Database "https://github.com/cuong75201/book-store/blob/main/database/book_store.sql"
    click admin2index "https://github.com/cuong75201/book-store/blob/main/admin2/index.php"
    click admin2css1 "https://github.com/cuong75201/book-store/blob/main/admin2/css/style.css"
    click admin2css2 "https://github.com/cuong75201/book-store/blob/main/admin2/css/style1.css"

    %% Styles
    classDef ui fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef logic fill:#D5F5E3,stroke:#196F3D,color:#145A32
    classDef data fill:#FCF3CF,stroke:#B9770E,color:#7E5109
    classDef external fill:#E5E7E9,stroke:#616A6B,color:#1C2833
```
