# johnreginald/mini-web-framework architecture

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

- Interactive diagram: https://gitdiagram.com/johnreginald/mini-web-framework
- Repository: https://github.com/johnreginald/mini-web-framework

## Overview

##### Project type and purpose
- The README reveals that this is a small e-commerce API built as a learning or demonstration project using Symfony Components.
- Its objective is to manage user registration, authentication (JWT token based), product listing, cart management, and checkout processes.
- The project uses Docker and Postman, indicating containerized deployment and external API testing.

##### File structure and map its components
- Entry Point: The public directory contains index.php which acts as the front controller. This is the main entry point for HTTP requests.
- Routing and Configuration:
- The config/ directory holds different configurations for routes (both PHP and YAML formats) as well as service definitions.
- The container.php file likely defines how dependencies are wired.
- The bootstrap.php file is used for setting up the runtime environment.
- Application Logic:
- The src/ folder contains a Kernel (src/Kernel.php), which likely kick-starts the application.
- Controllers are housed in src/Controller (with ProductController, CartController, etc.), handling API endpoints for different aspects of the e-commerce system.
- Models in src/Models represent the data layer (for User, Cart, CartItem, Product).
- Support/Utility Layer:
- The infrastructure folder, which hosts Auth.php, Database.php, and Migration.php, shows that database connectivity, authentication, and migrations are managed separately.
- Deployment:
- Docker-related files (Dockerfile, docker-compose.yml, docker/nginx/nginx.conf) indicate that the system is containerized and deployed via Docker. The nginx configuration suggests that there is a reverse-proxy or web server setup.
- The environment file (.env) and other configuration files further set up runtime variables.

##### Core components and interactions to capture
- Client Interaction:
- Web Server/Gateway:
- Dockerized Nginx (as per docker/nginx) that serves as a reverse proxy, receiving requests and forwarding them to the PHP application.
- Application Entry:
- Public/index.php as the front controller that receives these requests.
- Bootstrap process that likely initializes the application environment via bootstrap.php and container.php.
- Routing Layer:
- Role of configuration files (config/routes.php, routes.yaml) in mapping URLs to specific controllers.
- Controllers:
- Controllers (UserController, ProductController, CartController, HomeController, and the AbstractController base class) that handle distinct API endpoints.
- Business Logic and Models:
- Communication paths from controllers to models (e.g., User, Product, Cart, CartItem) which represent the core business entities.
- Infrastructure Services:
- Persistence Layer:
- Although not visually explicit from file names, include the database (MariaDB, as per README prerequisites) as a component that persists data. Connect infrastructure/database components to this external database.
- Dependency Injection Container:
- Optionally, include a component representing the service container (likely configured via container.php and config/services.yaml) that wires dependencies for controllers and infrastructure services.
- Docker/Deployment Environment:
- That the entire application is deployed inside Docker containers with separate images/containers for the web server (nginx) and application environments.

##### Architectural patterns and design principles
- MVC/Layered Architecture:
- That the project uses an MVC-like structure, with clear separation between controllers (interface), models (business data), and supportive infrastructure components.
- Service-Orientation:
- The use of Symfony Components along with dependency injection hints at a service-based design.
- Containerization:
- Role of Docker in deploying an isolated, reproducible environment.
- Adherence to PSR Standards:
- Although not drawn explicitly, mention that the architecture adheres to PHP Standard Recommendations (PSRs), ensuring modular and maintainable code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client and Gateway
    Client["Client (Postman/Browser)"]:::external
    Nginx["Nginx Reverse Proxy"]:::gateway

    %% Entry Point and Bootstrap
    Index["Front Controller (index.php)"]:::entry
    Bootstrap["Bootstrap (bootstrap.php)"]:::entry
    Container["Container Setup (container.php)"]:::entry

    %% Core Application
    Kernel["Kernel (Kernel.php)"]:::kernel

    %% Routing and Service Configurations
    RoutesPHP["Routing Config (routes.php)"]:::config
    RoutesYAML["Routing Config (routes.yaml)"]:::config
    ServiceCfg["Service Config (services.yaml)"]:::config

    %% Controllers Subgraph
    subgraph Controllers["Controllers"]
        AbstractCtrl["Abstract Controller (AbstractController.php)"]:::controller
        UserCtrl["User Controller (UserController.php)"]:::controller
        ProductCtrl["Product Controller (ProductController.php)"]:::controller
        CartCtrl["Cart Controller (CartController.php)"]:::controller
        HomeCtrl["Home Controller (HomeController.php)"]:::controller
    end

    %% Models Subgraph
    subgraph Models["Models"]
        UserModel["User Model (User.php)"]:::model
        ProductModel["Product Model (Product.php)"]:::model
        CartModel["Cart Model (Cart.php)"]:::model
        CartItemModel["CartItem Model (CartItem.php)"]:::model
    end

    %% Infrastructure Services Subgraph
    subgraph Infra["Infrastructure Services"]
        Auth["Authentication (Auth.php)"]:::infrastructure
        DBConn["Database Connectivity (Database.php)"]:::infrastructure
        Migrations["Migrations (Migration.php)"]:::infrastructure
    end

    %% Persistence Layer
    Database["Database (MariaDB)"]:::database

    %% Deployment/Containerization Subgraph
    subgraph Deployment["Deployment & Containerization"]
        DockerFile["Dockerfile"]:::deployment
        DockerCompose["Docker Compose (docker-compose.yml)"]:::deployment
        NginxConfig["Nginx Config (nginx.conf)"]:::deployment
        EnvConfig["Environment Config (.env)"]:::deployment
    end

    %% Connections - Vertical Flow
    Client -->|"sends request"| Nginx
    Nginx -->|"forwards"| Index
    Index --> Bootstrap
    Bootstrap --> Container
    Container --> Kernel

    %% Kernel loads configurations
    Kernel -->|"loads"| RoutesPHP
    Kernel -->|"loads"| RoutesYAML
    Kernel -->|"loads"| ServiceCfg

    %% Routing leads to Controllers
    RoutesPHP -->|"maps to"| AbstractCtrl
    RoutesYAML -->|"maps to"| AbstractCtrl
    ServiceCfg --- AbstractCtrl

    %% Controllers processing
    AbstractCtrl --> UserCtrl
    AbstractCtrl --> ProductCtrl
    AbstractCtrl --> CartCtrl
    AbstractCtrl --> HomeCtrl

    %% Controllers interact with Models and Infra
    UserCtrl -->|"handles user data"| UserModel
    ProductCtrl -->|"handles product data"| ProductModel
    CartCtrl -->|"handles cart data"| CartModel
    CartCtrl -->|"handles cart items"| CartItemModel

    %% Controllers use infrastructure services for operations
    UserCtrl -->|"authenticates via"| Auth
    CartCtrl -->|"queries via"| DBConn
    ProductCtrl -->|"may trigger"| Migrations

    %% Infrastructure connects to Database
    DBConn -->|"reads/writes"| Database

    %% Deployment connections (orchestration relation)
    DockerCompose -->|"orchestrates"| Nginx
    DockerCompose -->|"orchestrates"| Index

    %% Styling Definitions
    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
    classDef gateway fill:#bbf,stroke:#333,stroke-width:2px;
    classDef entry fill:#cfe,stroke:#333,stroke-width:2px;
    classDef kernel fill:#fc9,stroke:#333,stroke-width:2px;
    classDef config fill:#ffeb99,stroke:#333,stroke-width:2px;
    classDef controller fill:#d0e1f9,stroke:#333,stroke-width:2px;
    classDef model fill:#e6ffe6,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#ffd9b3,stroke:#333,stroke-width:2px;
    classDef database fill:#fdd,stroke:#333,stroke-width:2px;
    classDef deployment fill:#e0bbe4,stroke:#333,stroke-width:2px;

    %% Click Events for Entry Point and Bootstrap/Container
    click Index "https://github.com/johnreginald/mini-web-framework/blob/main/public/index.php"
    click Bootstrap "https://github.com/johnreginald/mini-web-framework/blob/main/bootstrap.php"
    click Container "https://github.com/johnreginald/mini-web-framework/blob/main/container.php"

    %% Click Events for Configurations
    click RoutesPHP "https://github.com/johnreginald/mini-web-framework/blob/main/config/routes.php"
    click RoutesYAML "https://github.com/johnreginald/mini-web-framework/blob/main/config/routes.yaml"
    click ServiceCfg "https://github.com/johnreginald/mini-web-framework/blob/main/config/services.yaml"

    %% Click Event for Kernel
    click Kernel "https://github.com/johnreginald/mini-web-framework/blob/main/src/Kernel.php"

    %% Click Events for Controllers
    click AbstractCtrl "https://github.com/johnreginald/mini-web-framework/blob/main/src/Controller/AbstractController.php"
    click UserCtrl "https://github.com/johnreginald/mini-web-framework/blob/main/src/Controller/UserController.php"
    click ProductCtrl "https://github.com/johnreginald/mini-web-framework/blob/main/src/Controller/ProductController.php"
    click CartCtrl "https://github.com/johnreginald/mini-web-framework/blob/main/src/Controller/CartController.php"
    click HomeCtrl "https://github.com/johnreginald/mini-web-framework/blob/main/src/Controller/HomeController.php"

    %% Click Events for Models
    click UserModel "https://github.com/johnreginald/mini-web-framework/blob/main/src/Models/User.php"
    click ProductModel "https://github.com/johnreginald/mini-web-framework/blob/main/src/Models/Product.php"
    click CartModel "https://github.com/johnreginald/mini-web-framework/blob/main/src/Models/Cart.php"
    click CartItemModel "https://github.com/johnreginald/mini-web-framework/blob/main/src/Models/CartItem.php"

    %% Click Events for Infrastructure Services
    click Auth "https://github.com/johnreginald/mini-web-framework/blob/main/infrastructure/Auth.php"
    click DBConn "https://github.com/johnreginald/mini-web-framework/blob/main/infrastructure/Database.php"
    click Migrations "https://github.com/johnreginald/mini-web-framework/blob/main/infrastructure/Migration.php"

    %% Click Events for Deployment
    click DockerFile "https://github.com/johnreginald/mini-web-framework/tree/main/Dockerfile"
    click DockerCompose "https://github.com/johnreginald/mini-web-framework/blob/main/docker-compose.yml"
    click NginxConfig "https://github.com/johnreginald/mini-web-framework/blob/main/docker/nginx/nginx.conf"
    click EnvConfig "https://github.com/johnreginald/mini-web-framework/blob/main/.env"
```
