# hjagar/tpofinalpwd architecture

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

- Interactive diagram: https://gitdiagram.com/hjagar/tpofinalpwd
- Repository: https://github.com/hjagar/tpofinalpwd

## Overview

##### Project Type and Purpose
- This is a full-stack web application: an online shopping cart with both a public storefront and an admin back-office.
- It’s built on a custom PHP MVC framework (under the `framework/` folder) and uses MySQL for persistence.

##### High-Level Architectural Components
a. Clients and Entry Point
- Browser Clients (Customers & Admins)
- HTTP Server (Apache/Nginx + PHP-FPM)
- Front Controller (`serve.php` / `src/public/index.php`)
b. Framework Core
- HTTP Kernel & Router (`framework/Http/Kernel.php`, `Router.php`)
- Middleware Pipeline (Auth, CSRF, Session under `framework/Http/Middleware/`)
- Configuration Loader (Environment, ApplicationBuilder in `framework/Configuration/`)
c. Application Logic
- Controllers (`src/Controllers/*Controller.php`)
- Business Services (`src/Bussiness/Cart.php`, `Product.php`)
- Models & Data Layer (`framework/Data/` + `src/Models/*.php`)
- Query Builder, Database Connection (`framework/Data/Database.php`)
d. View & Asset Management
- View Engine (`framework/View/Compiler.php`, `View.php`) with layouts & partials (`src/Views/`)
- Asset Manager (`framework/Assets/`) serves JS/CSS from `src/public/css`
e. External Services
- MySQL Database (schemas in `src/sql/`)
- SMTP Mailer via PHPMailer wrapper (`framework/Mail/EmailSender.php`)

##### Core Data Flows & Interactions
- HTTP Request → Front Controller → Kernel → Middleware Chain → Router → Controller
- Controller invokes Business Service → Data Layer queries/updates MySQL
- Controller produces either:
– HTML View (via View Engine + injected assets)
– JSON Response for AJAX (via `JsonResponse`/`JsonResult`)
- Response travels back up middleware → Kernel → HTTP Response to Client
- Mail-related actions call EmailSender (SMTP) asynchronously

##### Architectural Patterns & Principles
- MVC (Model-View-Controller) separation
- Layered Architecture: Presentation → Application → Domain → Infrastructure
- Middleware Pipeline for cross-cutting concerns
- Dependency Injection & Bootstrapping via ApplicationBuilder
- Single Front Controller entry point

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Clients"
        Browser("Browser (Customer/Admin)"):::client
    end

    subgraph "HTTP Layer"
        HTTPServer("HTTP Server<br>(Apache/Nginx + PHP-FPM)"):::server
        Index("Public Front Controller<br>src/public/index.php"):::entry
        click Index "https://github.com/hjagar/tpofinalpwd/blob/main/src/public/index.php"
    end

    Browser -->|HTTP GET/POST| HTTPServer
    HTTPServer --> Index

    subgraph "Framework" 
        Kernel("HTTP Kernel"):::frameworkComp
        click Kernel "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/Kernel.php"
        Router("Router"):::frameworkComp
        click Router "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/Router.php"
        RouteDef("Route Definition"):::frameworkComp
        click RouteDef "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/Route.php"
        subgraph "Middleware Pipeline"
            SM("StartSessionMiddleware"):::middleware
            click SM "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/Middleware/StartSessionMiddleware.php"
            CS("CsrfMiddleware"):::middleware
            click CS "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/Middleware/CsrfMiddleware.php"
            AM("AuthMiddleware"):::middleware
            click AM "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/Middleware/AuthMiddleware.php"
        end
        Config("ApplicationBuilder"):::frameworkComp
        click Config "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Configuration/ApplicationBuilder.php"
        EnvLoad("DotEnv Loader"):::frameworkComp
        click EnvLoad "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Configuration/DotEnv.php"
    end

    Index --> Kernel --> SM --> CS --> AM --> Router

    subgraph "Application"
        subgraph "Controllers"
            CartCtrl("CartController"):::controller
            click CartCtrl "https://github.com/hjagar/tpofinalpwd/blob/main/src/Controllers/CartController.php"
            ProductCtrl("ProductController"):::controller
            click ProductCtrl "https://github.com/hjagar/tpofinalpwd/blob/main/src/Controllers/ProductController.php"
            AdminCtrl("AdminController"):::controller
            click AdminCtrl "https://github.com/hjagar/tpofinalpwd/blob/main/src/Controllers/AdminController.php"
        end

        subgraph "Business Services"
            CartService("Cart Service"):::service
            click CartService "https://github.com/hjagar/tpofinalpwd/blob/main/src/Bussiness/Cart.php"
            ProductService("Product Service"):::service
            click ProductService "https://github.com/hjagar/tpofinalpwd/blob/main/src/Bussiness/Product.php"
        end

        subgraph "Data Layer & Models"
            DBConn("Database Connection"):::infra
            click DBConn "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Data/Database.php"
            QB("Query Builder"):::infra
            click QB "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Data/QueryBuilder.php"
            BaseModel("Base Model"):::infra
            click BaseModel "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Data/Model.php"
            AppModels("App Models<br>(Producto, Usuario, Compra)"):::model
            click AppModels "https://github.com/hjagar/tpofinalpwd/blob/main/src/Models/Producto.php"
        end

        subgraph "View Engine & Templating"
            Compiler("View Compiler"):::infra
            click Compiler "https://github.com/hjagar/tpofinalpwd/blob/main/framework/View/Compiler.php"
            ViewClass("View Class"):::infra
            click ViewClass "https://github.com/hjagar/tpofinalpwd/blob/main/framework/View/View.php"
            ViewEnv("View Environment"):::infra
            click ViewEnv "https://github.com/hjagar/tpofinalpwd/blob/main/framework/View/Environment.php"
        end
    end

    Router --> CartCtrl
    Router --> ProductCtrl
    Router --> AdminCtrl

    CartCtrl --> CartService
    ProductCtrl --> ProductService
    AdminCtrl --> CartService

    CartService --> DBConn
    ProductService --> DBConn

    DBConn -->|SELECT/INSERT/UPDATE| MySQL

    subgraph "Response Types"
        JsonResp("JSON Response"):::response
        click JsonResp "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/JsonResponse.php"
        Redirect("Redirect Response"):::response
        click Redirect "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Http/RedirectResponse.php"
    end

    CartCtrl -->|HTML View| ViewClass
    ProductCtrl -->|HTML View| ViewClass
    AdminCtrl -->|HTML View| ViewClass
    CartCtrl -->|AJAX JSON| JsonResp

    subgraph "Assets"
        AssetsMgr("Assets Manager"):::infra
        click AssetsMgr "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Assets/AssetsManager.php"
        AssetsMap("Asset Definitions"):::infra
        click AssetsMap "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Assets/assets-map.json"
        PublicCSS("Public CSS"):::asset
        click PublicCSS "https://github.com/hjagar/tpofinalpwd/blob/main/src/public/css/styles.css"
        FrameworkJS("Framework JS"):::asset
        click FrameworkJS "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Assets/Javascript/app.js"
    end

    HTTPServer -->|GET /css,/js| AssetsMgr
    AssetsMgr --> PublicCSS
    AssetsMgr --> FrameworkJS

    subgraph "Data Store"
        MySQL("MySQL Database"):::database
    end

    subgraph "External Services"
        Mailer("Email Service (SMTP)"):::external
        click Mailer "https://github.com/hjagar/tpofinalpwd/blob/main/framework/Mail/EmailSender.php"
    end

    CartService -->|SMTP send| Mailer

    classDef client fill:#FFE5B4,stroke:#E69A00,color:#000
    classDef server fill:#E0F7FA,stroke:#006064,color:#000
    classDef entry fill:#B3E5FC,stroke:#0288D1,color:#000
    classDef frameworkComp fill:#BBDEFB,stroke:#1976D2,color:#000
    classDef middleware fill:#C5CAE9,stroke:#303F9F,color:#000
    classDef controller fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef service fill:#DCEDC8,stroke:#558B2F,color:#000
    classDef infra fill:#CFD8DC,stroke:#455A64,color:#000
    classDef model fill:#F0F4C3,stroke:#827717,color:#000
    classDef response fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef asset fill:#F3E5F5,stroke:#6A1B9A,color:#000
    classDef database fill:#FFCCBC,stroke:#D84315,color:#000
    classDef external fill:#E0E0E0,stroke:#616161,color:#000
```
