# huuhau235/gleamcraft architecture

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

## Overview

##### Project Type and Purpose
- This is a monolithic, server-rendered PHP web application following an MVC (Model-View-Controller) pattern.
- Purpose: an e-commerce jewelry store with features for browsing products, managing a shopping cart, processing payments, and user administration.

##### File Structure
- Top-level directories:
- app/controllers – HTTP request handlers (Admin, Cart, Detail, Homepage, Payment, Product, User, Shared)
- app/models – Data models (Admin, CartModel, PaymentModel, ProductsModel, Reviews, UserModel)
- app/views – Templates (organized by feature: aboutUs, admin, brands, cart, collection, detail, homepage, payment, product, shared, user)
- app/core – Framework core (Controller.php, Db.php, app.php, init.php)
- assets – Static files (CSS, JS, images)
- database – SQL schema and migration stubs
- index.php – Single entry point
- composer.json/lock – Dependency management
- .htaccess – URL rewriting
- Patterns:
- MVC separation (controllers → models → views)
- Front controller (index.php + app/core/app.php dispatch requests)
- Static assets served from /assets

##### README for Additional Insights
- Team workflow notes (branch naming, commits, Bootstrap usage)

a. Client / Browser
– UI in HTML/CSS/JS, served via HTTP.
– Uses Bootstrap and custom CSS/JS under /assets.
b. Web Server / PHP Runtime
– Apache or Nginx with PHP-FPM, invoking index.php.
– .htaccess defines URL rewrites to index.php.
c. Front Controller & Router
– app/init.php and app/core/app.php parse the request URI.
– Maps to the appropriate Controller.
d. Controllers
– app/controllers/*.php handle input, invoke Models, select Views.
e. Models & Database
– app/models/*.php interface with Db.php (MySQL via PDO).
– database/jewelry_store.sql holds schema; migrations in database/migrations.
f. Views / Templating
– app/views/* generate the HTML response using data from Models.
g. Static Asset Delivery
– CSS, JS, Images are served directly or via a CDN link (Bootstrap).
h. External Services
– Payment gateway integration within PaymentController/PaymentModel.

##### Relationships & Data Flow
- Web Server → Front Controller (index.php).
- Front Controller → Controller classes.
- Controller → Model (calls to Db, queries).
- Model → Database (SQL operations).
- Controller ← Model (data returned).
- Controller → View (rendering).
- View → Browser (HTTP response).
- Browser → Assets (CSS/JS/images).
- Payment flow: Controller → External Payment API → Controller.

##### Architectural Patterns & Principles
- MVC Separation: group components into distinct layers.
- Single entry-point: index.php as front controller.
- Dependency injection: Db.php config passed into models.
- Configuration externalization: composer.json for dependencies.
- Modularity: separate controllers for each functional area.

##### Technologies & Frameworks
- PHP 7+ (custom micro-framework in app/core).
- MySQL (or MariaDB) via PDO.
- Bootstrap 5.3 for UI.
- Composer for autoloading.
- Apache/Nginx + .htaccess for URL rewriting.
- Vanilla JS for interactivity.

##### Final Checklist
- All components included and labeled.
- Annotations for technologies (e.g., “MySQL via PDO”, “Bootstrap 5.3”, “Composer autoload”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Browser["Browser"]:::client
        CSS["CSS Files"]:::client
        JS["JavaScript Files"]:::client
        Images["Image Files"]:::client
    end

    subgraph "Web Server / PHP Runtime"
        Server["Apache/Nginx + PHP-FPM"]:::server
        Index["index.php"]:::server
        HT[".htaccess"]:::server
    end

    subgraph "PHP Application"
        subgraph "Front Controller & Router"
            Init["app/init.php"]:::server
            AppCore["app/core/app.php"]:::server
        end
        subgraph "Core Framework"
            ControllerBase["app/core/Controller.php"]:::server
            DbCore["app/core/Db.php"]:::server
        end
        subgraph "Controllers"
            AdminC["AdminController"]:::server
            CartC["CartController"]:::server
            DetailC["DetailController"]:::server
            HomeC["HomepageController"]:::server
            PaymentC["PaymentController"]:::server
            ProductC["ProductController"]:::server
            SharedC["SharedController"]:::server
            UserC["UserController"]:::server
        end
        subgraph "Models"
            AdminM["Admin.php"]:::server
            CartM["CartModel.php"]:::server
            PaymentM["PaymentModel.php"]:::server
            ProductsM["ProductsModel.php"]:::server
            ReviewsM["Reviews.php"]:::server
            UserM["UserModel.php"]:::server
        end
        subgraph "Views"
            AboutV["aboutUs/index.php"]:::server
            AdminV["admin/index.php"]:::server
            BrandsV["brands/index.php"]:::server
            CartV["cart/index.php"]:::server
            CollectionV["collection/index.php"]:::server
            DetailVw["detail/index.php"]:::server
            HomeV["homepage/index.php"]:::server
            PaymentV["payment/index.php"]:::server
            ProductV["product/index.php"]:::server
            SharedV["app/views/shared/"]:::server
            UserV["app/views/user/"]:::server
        end
    end

    Database["MySQL Database"]:::storage
    Schema["database/jewelry_store.sql"]:::storage
    Migrations["database/migrations/"]:::storage
    PaymentAPI["Payment Gateway API"]:::external

    Browser -->|HTTP GET/POST| Server
    Server --> Index
    Server --> HT
    Index --> Init
    Init --> AppCore
    AppCore --> ControllerBase
    ControllerBase -->|extends| AdminC & CartC & DetailC & HomeC & PaymentC & ProductC & SharedC & UserC
    AdminC & CartC & DetailC & HomeC & PaymentC & ProductC & SharedC & UserC --> Models
    Models --> DbCore
    DbCore --> Database
    Database --> Models
    Controllers --> Views
    Views --> Browser
    Browser --> CSS
    Browser --> JS
    Browser --> Images
    PaymentC -->|calls API| PaymentAPI
    PaymentAPI -->|response| PaymentC

    click CSS "https://github.com/huuhau235/gleamcraft/tree/main/assets/css/"
    click JS "https://github.com/huuhau235/gleamcraft/tree/main/assets/js/"
    click Images "https://github.com/huuhau235/gleamcraft/tree/main/assets/images/"
    click Index "https://github.com/huuhau235/gleamcraft/blob/main/index.php"
    click HT "https://github.com/huuhau235/gleamcraft/blob/main/.htaccess"
    click Init "https://github.com/huuhau235/gleamcraft/blob/main/app/init.php"
    click AppCore "https://github.com/huuhau235/gleamcraft/blob/main/app/core/app.php"
    click ControllerBase "https://github.com/huuhau235/gleamcraft/blob/main/app/core/Controller.php"
    click DbCore "https://github.com/huuhau235/gleamcraft/blob/main/app/core/Db.php"
    click AdminC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/AdminController.php"
    click CartC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/CartController.php"
    click DetailC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/DetailController.php"
    click HomeC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/HomepageController.php"
    click PaymentC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/PaymentController.php"
    click ProductC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/ProductController.php"
    click SharedC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/SharedController.php"
    click UserC "https://github.com/huuhau235/gleamcraft/blob/main/app/controllers/UserController.php"
    click AdminM "https://github.com/huuhau235/gleamcraft/blob/main/app/models/Admin.php"
    click CartM "https://github.com/huuhau235/gleamcraft/blob/main/app/models/CartModel.php"
    click PaymentM "https://github.com/huuhau235/gleamcraft/blob/main/app/models/PaymentModel.php"
    click ProductsM "https://github.com/huuhau235/gleamcraft/blob/main/app/models/ProductsModel.php"
    click ReviewsM "https://github.com/huuhau235/gleamcraft/blob/main/app/models/Reviews.php"
    click UserM "https://github.com/huuhau235/gleamcraft/blob/main/app/models/UserModel.php"
    click AboutV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/aboutUs/index.php"
    click AdminV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/admin/index.php"
    click BrandsV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/brands/index.php"
    click CartV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/cart/index.php"
    click CollectionV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/collection/index.php"
    click DetailVw "https://github.com/huuhau235/gleamcraft/blob/main/app/views/detail/index.php"
    click HomeV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/homepage/index.php"
    click PaymentV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/payment/index.php"
    click ProductV "https://github.com/huuhau235/gleamcraft/blob/main/app/views/product/index.php"
    click SharedV "https://github.com/huuhau235/gleamcraft/tree/main/app/views/shared/"
    click UserV "https://github.com/huuhau235/gleamcraft/tree/main/app/views/user/"
    click Schema "https://github.com/huuhau235/gleamcraft/blob/main/database/jewelry_store.sql"
    click Migrations "https://github.com/huuhau235/gleamcraft/tree/main/database/migrations/"

    classDef client fill:#f9f,stroke:#333,stroke-width:1px
    classDef server fill:#bbf,stroke:#333,stroke-width:1px
    classDef storage fill:#bfb,stroke:#333,stroke-width:1px
    classDef external fill:#fbb,stroke:#333,stroke-width:1px
```
