# btoann/waka architecture

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

- Interactive diagram: https://gitdiagram.com/btoann/waka
- Repository: https://github.com/btoann/waka

## Overview

##### Main components
- Frontend / Presentation Layer
- This is represented by the “view” directory.
- Separate subdirectories exist for admin, client (cart, home, product, user, etc.), and general client pages.
- Also includes static resources like CSS, JavaScript (jQuery, product list scripts, catalog list scripts, etc.), and images.
- Controller Layer
- The “controller” directory is split into “admin” and “client” subdirectories, each handling specific user interactions.
- The role of these controllers is to process the incoming requests (for example via admin.php, comment.php, index.php, etc.) and interact with the models.
- Model Layer
- The “model” directory contains business logic related to various entities (e.g., books ("sanpham"), comments ("binhluan"), cart ("giohang"), publishers ("nhaxuatban"), authors ("tacgia"), accounts ("taikhoan"), categories ("theloai"), searches ("timkiem")).
- The file “connect.php” suggests a central connection to a database.
- Database
- The existence of “waka.sql” implies the database schema that supports the models.
- Global Configuration / Entry Points
- Files such as “index.php”, “admin.php”, “global.php”, and “comment.php” serve as entry points or bootstrap files that initialize the application.

##### Relationships and interactions
- Users interact via two separate portals:
- A Client Interface (handled primarily in “controller/client” and views under “view/home”, “view/product”, “view/cart”, “view/user”, etc.)
- An Admin Interface (handled in “controller/admin” and “view/admin”).
- Both interface layers interact with the Model layer for data operations.
- The Controller layer serves as the intermediary between user requests (coming from the views) and the Model layer (which accesses/manipulates data in the database).
- Static files and assets are served from defined directories (e.g., “view/css”, “view/js”, “view/image”) to support the frontend design.

##### Architectural patterns and technologies
- MVC Pattern – This pattern is clearly in use with a separation of controllers, models, and views.
- PHP is the underlying server-side technology.
- JavaScript (with jQuery and other custom scripts) is used for enhanced client-side interactivity.
- The database (MySQL is a likely candidate given the SQL file) interacts with the models via a dedicated connection defined in “model/connect.php”.
- There is clear segregation between administration and client functionality, which hints at either role-based access control or simply modular development for maintainability.

##### Instructing the Principal Software Engineer
- One for the Client Portal (with specifics such as home page, product pages, checkout/cart, user authentication, etc.)
- One for the Admin Portal (including catalog management, product management, user management, etc.)
- One for the Controllers grouping the HTTP request management for both client and admin functionalities.
- One for the Models covering business logic and database interactions.
- One for the Database, clearly marking the connection from “model/connect.php”.
- From the user’s browser to the entry point (index.php, admin.php).
- From the entry point to the respective controller.
- From the controller to the model (for data operations) and back.
- Finally, from the controller to the views which are sent back to the user.
- Modularity of the admin and client sections, which is crucial for an e-commerce site’s separation of concerns.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface
    B["User Browser"]:::view

    %% Entry Points
    subgraph "Entry Points"
        EP1["index.php"]:::entry
        EP2["admin.php"]:::entry
        EP3["global.php"]:::entry
        EP4["comment.php"]:::entry
    end

    %% Controller Layer
    subgraph "Controller Layer"
        CC["Client Controller"]:::controller
        AC["Admin Controller"]:::controller
        
        subgraph "Client Controllers"
            CCH["home.php"]:::controller
            CCC["cart.php"]:::controller
            CCP["product.php"]:::controller
            CCS["search.php"]:::controller
        end
        
        subgraph "Admin Controllers"
            ACH["home.php"]:::controller
            ACC["catalog.php"]:::controller
            ACP["product.php"]:::controller
            ACU["user.php"]:::controller
        end
    end

    %% Model Layer
    subgraph "Model Layer"
        M["Models"]:::model
        subgraph "Business Models"
            MSM["sanpham.php"]:::model
            MBL["binhluan.php"]:::model
            MGH["giohang.php"]:::model
            MNB["nhaxuatban.php"]:::model
            MTG["tacgia.php"]:::model
            MTA["taikhoan.php"]:::model
            MTL["theloai.php"]:::model
            MTM["timkiem.php"]:::model
        end
        MC["connect.php"]:::model
    end

    %% Database
    D["Database (waka.sql)"]:::db

    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "Admin Views"
            AV["Admin Panel (view/admin)"]:::view
        end
        subgraph "Client Views"
            VH["Home Page (view/home)"]:::view
            VP["Product Page (view/product)"]:::view
            VC["Cart Page (view/cart)"]:::view
            VU["User Page (view/user)"]:::view
        end
        subgraph "Static Assets"
            CSS["CSS (view/css)"]:::asset
            JS["JS (view/js)"]:::asset
            IMG["Images (view/image)"]:::asset
        end
    end

    %% Connections from User Browser to Entry Points
    B --> EP1
    B --> EP2
    B --> EP3
    B --> EP4

    %% Entry Points to Controllers
    EP1 --> CC
    EP3 --> CC
    EP4 --> CC
    EP2 --> AC

    %% Controllers to their detailed subcontrollers
    CC --> CCH
    CC --> CCC
    CC --> CCP
    CC --> CCS

    AC --> ACH
    AC --> ACC
    AC --> ACP
    AC --> ACU

    %% Controllers interface with Models (bidirectional communication)
    CC --> M
    AC --> M
    M --> CC
    M --> AC

    %% Models use DB connector to access Database
    M --> MC
    MC --> D

    %% Subcontrollers call Business Models (illustrative)
    CCH --> MSM
    CCC --> MGH
    CCP --> MSM
    CCS --> MTM

    ACH --> MSM
    ACC --> MSM
    ACP --> MSM
    ACU --> MTA

    %% Controllers send responses to Views
    CCH ---> VH
    CCC ---> VC
    CCP ---> VP
    CCS ---> VH
    ACH ---> AV
    ACC ---> AV
    ACP ---> AV
    ACU ---> AV

    %% Views return content to User Browser
    VH --> B
    VP --> B
    VC --> B
    VU --> B
    AV --> B

    %% Static Assets support Client Views
    CSS --- VH
    JS --- VP
    IMG --- VH

    %% Click Events
    click EP1 "https://github.com/btoann/waka/blob/master/index.php"
    click EP2 "https://github.com/btoann/waka/blob/master/admin.php"
    click EP3 "https://github.com/btoann/waka/blob/master/global.php"
    click EP4 "https://github.com/btoann/waka/blob/master/comment.php"
    click CC "https://github.com/btoann/waka/tree/master/controller/client/"
    click AC "https://github.com/btoann/waka/tree/master/controller/admin/"
    click CCH "https://github.com/btoann/waka/blob/master/controller/client/home.php"
    click CCC "https://github.com/btoann/waka/blob/master/controller/client/cart.php"
    click CCP "https://github.com/btoann/waka/blob/master/controller/client/product.php"
    click CCS "https://github.com/btoann/waka/blob/master/controller/client/search.php"
    click ACH "https://github.com/btoann/waka/blob/master/controller/admin/home.php"
    click ACC "https://github.com/btoann/waka/blob/master/controller/admin/catalog.php"
    click ACP "https://github.com/btoann/waka/blob/master/controller/admin/product.php"
    click ACU "https://github.com/btoann/waka/blob/master/controller/admin/user.php"
    click M "https://github.com/btoann/waka/tree/master/model/"
    click MSM "https://github.com/btoann/waka/blob/master/model/sanpham.php"
    click MBL "https://github.com/btoann/waka/blob/master/model/binhluan.php"
    click MGH "https://github.com/btoann/waka/blob/master/model/giohang.php"
    click MNB "https://github.com/btoann/waka/blob/master/model/nhaxuatban.php"
    click MTG "https://github.com/btoann/waka/blob/master/model/tacgia.php"
    click MTA "https://github.com/btoann/waka/blob/master/model/taikhoan.php"
    click MTL "https://github.com/btoann/waka/blob/master/model/theloai.php"
    click MTM "https://github.com/btoann/waka/blob/master/model/timkiem.php"
    click MC "https://github.com/btoann/waka/blob/master/model/connect.php"
    click D "https://github.com/btoann/waka/blob/master/waka.sql"
    click AV "https://github.com/btoann/waka/tree/master/view/admin/"
    click VH "https://github.com/btoann/waka/tree/master/view/home"
    click VP "https://github.com/btoann/waka/tree/master/view/product"
    click VC "https://github.com/btoann/waka/tree/master/view/cart"
    click VU "https://github.com/btoann/waka/tree/master/view/user"
    click CSS "https://github.com/btoann/waka/tree/master/view/css"
    click JS "https://github.com/btoann/waka/tree/master/view/js"
    click IMG "https://github.com/btoann/waka/tree/master/view/image"

    %% Styles
    classDef entry fill:#fff3cd,stroke:#000,stroke-width:2px;
    classDef controller fill:#d1e7dd,stroke:#000,stroke-width:2px;
    classDef model fill:#f8d7da,stroke:#000,stroke-width:2px;
    classDef view fill:#cff4fc,stroke:#000,stroke-width:2px;
    classDef db fill:#dbe2ef,stroke:#000,stroke-width:2px;
    classDef asset fill:#e2e3e5,stroke:#000,stroke-width:2px;
```
