# thnhtai19/bkstore architecture

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

- Interactive diagram: https://gitdiagram.com/thnhtai19/bkstore
- Repository: https://github.com/thnhtai19/bkstore

## Overview

##### Main Components
a. Clients
- Public users browsing/catalog (`/views/public`, `/views/client`)
- Authenticated customers (account pages, cart, checkout)
- Admin users (`/views/admin`)
b. Web Server & Application Layer
- Apache/nginx + PHP runtime serving files under `public/`
- MVC components in `app/`
- Controllers (`app/controllers/*`)
- Service layer / Models (`app/models/*`)
- Views (`app/views/*`)
c. Data Layer
- MySQL database (schemas from `config/create_database.sql`, sample data)
d. Static Asset Storage
- Image files on disk under `public/image/…`
- CSS and JS under `public/css`, `public/js`
e. External Service
- Payment provider integration (`app/controllers/payment/*`, `PayOsService`)

##### Relationships & Data Flows
- User browsers ➞ HTTP requests to Web Server
- Web Server routes requests to specific Controller (by URL pattern)
- Controller invokes Service/Model methods for business logic & DB access
- Service layer executes SQL queries on MySQL, returns domain objects/data
- Controller selects a View template, passes data for rendering HTML
- Web Server returns HTML + static assets (CSS/JS/images) to browser
- For payment operations: Controller calls external Payment Gateway API, processes callbacks
- File uploads (e.g. product images, user avatars) flow through Controller → stored in `public/image/…`

##### Architectural Patterns & Principles
- MVC separation:
- “View” templates are purely presentation
- “Controllers” handle routing, request/response, validation
- “Models” encapsulate database access (one Service class per domain)
- Layered architecture: Presentation ↔ Business Logic ↔ Data Access
- Modular controllers organized by feature (auth, admin, product, cart, order, system, etc.)
- Single monolithic codebase, no microservices

##### Relevant Technologies & Frameworks
- PHP 7/8, built-in web server or Apache/nginx (`.htaccess` for rewrites)
- MySQL (connect details in `config/db.php`)
- Front-end: HTML5, CSS3, Tailwind, vanilla JS (files under `public/js`)
- SQL scripts for schema and seed data

##### Tool Recommendations & Detail Level
- Aim for readability: group related controllers as a package, but don’t omit any major feature (auth, cart, order, product, admin)
- Five layers/components, but avoid over-fragmenting identical services

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        Public["Public User"]:::external
        AuthClient["Authenticated Customer"]:::external
        AdminUser["Admin User"]:::external
    end

    subgraph "Web Server / PHP Application"
        subgraph "Controllers"
            AuthController["AuthController"]:::business
            AdminController["AdminController"]:::business
            ProductController["ProductController"]:::business
            CartController["CartController"]:::business
            OrderController["OrderController"]:::business
            PaymentController["PaymentController"]:::business
            SystemController["SystemController"]:::business
        end
        subgraph "Models / Services"
            AuthService["AuthService"]:::business
            UserService["UserService"]:::business
            ProductService["ProductService"]:::business
            CartService["CartService"]:::business
            OrderService["OrderService"]:::business
            AdminService["AdminService"]:::business
            SystemService["SystemService"]:::business
            PayOsService["PayOsService"]:::business
        end
        subgraph "Views & Static Assets"
            PublicViews["Public Views"]:::presentation
            ClientViews["Client Views"]:::presentation
            AdminViews["Admin Views"]:::presentation
            CSS["CSS Files"]:::static
            JS["JavaScript Files"]:::static
            Images["Image Files"]:::static
        end
    end

    subgraph "Data Layer"
        DB["MySQL Database"]:::data
        Disk["Disk Storage"]:::disk
    end

    PaymentGateway["Payment Gateway"]:::external

    Public -->|"HTTP"| AuthController
    AuthClient -->|"HTTP"| CartController
    AuthClient -->|"HTTP"| OrderController
    AuthClient -->|"HTTP"| ProductController
    AdminUser -->|"HTTP"| AdminController

    AuthController -->|"calls"| AuthService
    AuthController -->|"calls"| UserService
    AdminController -->|"calls"| AdminService
    ProductController -->|"calls"| ProductService
    CartController -->|"calls"| CartService
    OrderController -->|"calls"| OrderService
    SystemController -->|"calls"| SystemService
    PaymentController -->|"calls"| PayOsService

    AuthService -->|"SQL"| DB
    UserService -->|"SQL"| DB
    ProductService -->|"SQL"| DB
    CartService -->|"SQL"| DB
    OrderService -->|"SQL"| DB
    AdminService -->|"SQL"| DB
    SystemService -->|"SQL"| DB

    AuthController -->|"renders"| ClientViews
    AdminController -->|"renders"| AdminViews
    ProductController -->|"renders"| PublicViews
    CartController -->|"renders"| ClientViews
    OrderController -->|"renders"| ClientViews
    SystemController -->|"renders"| AdminViews

    ClientViews --> CSS
    ClientViews --> JS
    ClientViews --> Images
    PublicViews --> CSS
    PublicViews --> JS
    PublicViews --> Images
    AdminViews --> CSS
    AdminViews --> JS
    AdminViews --> Images

    AuthController -->|"read/write files"| Disk
    ProductController -->|"read/write files"| Disk
    CartController -->|"read/write files"| Disk

    PaymentController -->|"REST API"| PaymentGateway

    click PublicViews "https://github.com/thnhtai19/bkstore/tree/main/app/views/public"
    click ClientViews "https://github.com/thnhtai19/bkstore/tree/main/app/views/client"
    click AdminViews "https://github.com/thnhtai19/bkstore/tree/main/app/views/admin"
    click AuthController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/auth"
    click AdminController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/admin"
    click ProductController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/product"
    click CartController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/cart"
    click OrderController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/order"
    click PaymentController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/payment"
    click SystemController "https://github.com/thnhtai19/bkstore/tree/main/app/controllers/system"
    click AuthService "https://github.com/thnhtai19/bkstore/blob/main/app/models/AuthService.php"
    click UserService "https://github.com/thnhtai19/bkstore/blob/main/app/models/UserService.php"
    click ProductService "https://github.com/thnhtai19/bkstore/blob/main/app/models/ProductService.php"
    click CartService "https://github.com/thnhtai19/bkstore/blob/main/app/models/CartService.php"
    click OrderService "https://github.com/thnhtai19/bkstore/blob/main/app/models/OrderService.php"
    click AdminService "https://github.com/thnhtai19/bkstore/blob/main/app/models/AdminService.php"
    click SystemService "https://github.com/thnhtai19/bkstore/blob/main/app/models/SystemService.php"
    click PayOsService "https://github.com/thnhtai19/bkstore/blob/main/app/models/PayOsService.php"
    click CSS "https://github.com/thnhtai19/bkstore/tree/main/public/css"
    click JS "https://github.com/thnhtai19/bkstore/tree/main/public/js"
    click Images "https://github.com/thnhtai19/bkstore/tree/main/public/image"

    classDef business fill:#dcedc1,stroke:#000
    classDef presentation fill:#d0e1f9,stroke:#000
    classDef static fill:#b0d4f1,stroke:#000
    classDef data fill:#ffd3b6,stroke:#000
    classDef disk fill:#ffaaa5,stroke:#000
    classDef external fill:#c3aed6,stroke:#000
```
