# oladesoftware/httpcrafter architecture

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

- Interactive diagram: https://gitdiagram.com/oladesoftware/httpcrafter
- Repository: https://github.com/oladesoftware/httpcrafter

## Overview

##### Project Type and Purpose
- HTTPCrafter is a lightweight PHP toolbox/library that provides core HTTP message abstractions (Request/Response), a middleware pipeline, routing facilities, and security/authentication helpers.
- It’s distributed via Composer, intended for integration into other PHP applications or frameworks.

##### File Structure Analysis
- Top-level files:
- composer.json / .gitignore / LICENSE / README.md – standard package metadata and docs
- docs/ – installation & usage guides
- src/ – core library code
- tests/ – unit tests for each module
- src sub-directories:
- Http – Request/Response implementations and PSR-style interfaces
- Middleware – pipeline components (e.g., Authorization)
- Router – Router core plus a Facade for easy integration
- Security – Authenticator class

##### Key Architectural Insights from README & Code
- No external service dependencies; everything runs in-process.
- Follows common PHP package conventions: PSR-4 autoloading, PSR-7-style HTTP messages, middleware pattern, facade for simplified API.
- Core use case: Application receives a Request, passes it through middleware (Authorization, custom middleware), hands off to Router, and returns a Response.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    Client["Client / Framework"]:::external

    %% Core Entry
    Composer["Composer Autoloader"]:::external
    HttpRequest["RequestInterface / Request"]:::httpcore
    HttpResponse["ResponseInterface / Response"]:::httpcore

    %% Middleware & Security
    subgraph "Middleware Pipeline" 
        direction TB
        AuthZ["Authorization Middleware"]:::middleware
        Custom["Custom Middleware"]:::middleware
    end
    Authenticator["Security\\Authenticator"]:::middleware

    %% Routing Layer
    RouterFacade["RouterFacade (Public API)"]:::routing
    RouterCore["Router Core"]:::routing

    %% Application Handlers
    Handlers["Application Handlers"]:::external

    %% Flow: Request
    Client -->|"autoload via Composer"| Composer
    Composer -->|"create Request()"| HttpRequest
    HttpRequest -->|"handle(Request)"| AuthZ
    AuthZ -->|"authorize -> uses Authenticator"| Authenticator
    Authenticator -->|"returns principal"| AuthZ
    AuthZ -->|"pass to next"| Custom
    Custom -->|"pass to facade"| RouterFacade
    RouterFacade -->|"delegates to"| RouterCore
    RouterCore -->|"dispatch(Request)"| Handlers

    %% Flow: Response
    Handlers -->|"returns Response"| RouterCore
    RouterCore -->|"pipeline returns"| Custom
    Custom -->|"pipeline returns"| AuthZ
    AuthZ -->|"pipeline returns"| HttpResponse
    HttpResponse -->|"return via Composer"| Composer
    Composer -->|"respond"| Client

    %% File Structure Annotation
    subgraph "Project Files"
        direction TB
        DocsInstall["00-installation.md"]:::docs
        DocsUsage["01-usage.md"]:::docs
    end

    %% Click Events
    click Composer "https://github.com/oladesoftware/httpcrafter/blob/main/composer.json"
    click HttpRequest "https://github.com/oladesoftware/httpcrafter/blob/main/src/Http/RequestInterface.php"
    click HttpRequest "https://github.com/oladesoftware/httpcrafter/blob/main/src/Http/Request.php"
    click HttpResponse "https://github.com/oladesoftware/httpcrafter/blob/main/src/Http/ResponseInterface.php"
    click HttpResponse "https://github.com/oladesoftware/httpcrafter/blob/main/src/Http/Response.php"
    click AuthZ "https://github.com/oladesoftware/httpcrafter/blob/main/src/Middleware/Authorization.php"
    click Authenticator "https://github.com/oladesoftware/httpcrafter/blob/main/src/Security/Authenticator.php"
    click RouterCore "https://github.com/oladesoftware/httpcrafter/blob/main/src/Router/Router.php"
    click RouterFacade "https://github.com/oladesoftware/httpcrafter/blob/main/src/Router/RouterFacade.php"
    click DocsInstall "https://github.com/oladesoftware/httpcrafter/blob/main/docs/00-installation.md"
    click DocsUsage "https://github.com/oladesoftware/httpcrafter/blob/main/docs/01-usage.md"

    %% Unit Tests (optional clicks)
    click TestsRequest "https://github.com/oladesoftware/httpcrafter/blob/main/tests/Http/RequestTest.php"
    click TestsResponse "https://github.com/oladesoftware/httpcrafter/blob/main/tests/Http/ResponseTest.php"
    click TestsRouter "https://github.com/oladesoftware/httpcrafter/blob/main/tests/Router/RouterTest.php"

    %% Styles
    classDef external fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef httpcore fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef middleware fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef routing fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef docs fill:#FFFACD,stroke:#333,stroke-width:1px;
```
