# pietroagazzi/mechanic architecture

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

- Interactive diagram: https://gitdiagram.com/pietroagazzi/mechanic
- Repository: https://github.com/pietroagazzi/mechanic

## Overview

##### Component Relationships

a. External Connections:
- Client requests → Nginx
- Nginx → PHP-FPM
- PHP-FPM → public/index.php

b. Internal Flow:
- public/index.php → Mechanic class
- Mechanic → Router
- Router → RouteCollection
- All components → DI Container

##### Detailed Component Breakdown

HTTP Components:
- Request (handles incoming HTTP requests)
- Response (base HTTP response)
- JsonResponse (specialized JSON response)

Core Components:
- AbstractKernel (base framework kernel)
- Mechanic (main application class)
- Router (URL routing system)
- DI Container (dependency injection)

##### Specific Implementation Notes

- The lightweight nature of the framework
- The educational purpose (clear component separation)
- The inspiration from Symfony and Laravel (noted in README)
- The request handling flow from entry point to response

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        Client(("Client"))
        Nginx["Nginx Web Server"]:::infra
        PHPFPM["PHP-FPM"]:::infra
    end

    subgraph "HTTP Layer"
        EntryPoint["Entry Point"]:::http
        Request["Request Handler"]:::http
        Response["Response Handler"]:::http
        JsonResponse["JSON Response"]:::http
    end

    subgraph "Core Framework"
        Mechanic["Mechanic"]:::core
        AbstractKernel["Abstract Kernel"]:::core
        
        subgraph "Routing System"
            Router["Router"]:::core
            RouteCollection["Route Collection"]:::core
            Route["Route"]:::core
        end
        
        Container["DI Container"]:::core
    end

    %% Infrastructure Flow
    Client --> Nginx
    Nginx --> PHPFPM
    PHPFPM --> EntryPoint

    %% HTTP Layer Flow
    EntryPoint --> Mechanic
    Mechanic --> Request
    Mechanic --> Response
    Response --> JsonResponse

    %% Core Framework Flow
    Mechanic --> Router
    Router --> RouteCollection
    RouteCollection --> Route
    
    %% DI Container Dependencies
    Container --> Mechanic
    Container --> Router
    Container --> Request
    Container --> Response

    %% Component Mappings
    click EntryPoint "https://github.com/pietroagazzi/mechanic/blob/main/public/index.php"
    click Request "https://github.com/pietroagazzi/mechanic/blob/main/src/Http/Request.php"
    click Response "https://github.com/pietroagazzi/mechanic/blob/main/src/Http/Response.php"
    click JsonResponse "https://github.com/pietroagazzi/mechanic/blob/main/src/Http/JsonResponse.php"
    click Mechanic "https://github.com/pietroagazzi/mechanic/blob/main/src/Mechanic.php"
    click AbstractKernel "https://github.com/pietroagazzi/mechanic/blob/main/src/AbstractKernel.php"
    click Router "https://github.com/pietroagazzi/mechanic/blob/main/src/Router/Router.php"
    click RouteCollection "https://github.com/pietroagazzi/mechanic/blob/main/src/Router/RouteCollection.php"
    click Route "https://github.com/pietroagazzi/mechanic/blob/main/src/Router/Route.php"
    click Container "https://github.com/pietroagazzi/mechanic/blob/main/src/DI/Container.php"
    click Nginx "https://github.com/pietroagazzi/mechanic/blob/main/docker/nginx/nginx.conf"
    click PHPFPM "https://github.com/pietroagazzi/mechanic/tree/main/docker/php-fpm/Dockerfile"

    %% Styling
    classDef http fill:#2196F3,color:white
    classDef core fill:#4CAF50,color:white
    classDef infra fill:#9E9E9E,color:white

    %% Legend
    subgraph Legend
        L1["HTTP Component"]:::http
        L2["Core Component"]:::core
        L3["Infrastructure"]:::infra
    end
```
