# dunneeee/dunnserver architecture

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

- Interactive diagram: https://gitdiagram.com/dunneeee/dunnserver
- Repository: https://github.com/dunneeee/dunnserver

## Overview

##### Main Components
- DunnServer Core: Represented by DunnServer.php and the base setup in src/Base (e.g., the Dunn class). This is the central hub where requests enter.
- HTTP Layer: Found under src/Http, these modules (Request, Response, HttpAction, FileUpload) handle request parsing, response formatting, and actions on HTTP data.
- Middleware: Located under src/Middlewares, this includes various filters (CorsFilter, DoFilter, Filter, etc.) and the FilterChain which intercepts and manages request/response processing.
- Routing: Contained in src/Router (Route, RouteStore, and Router), which determines which controller should process the request based on URL mapping.
- MVC Components: Under src/MVC, including Controller, ControllerAction, and View. These classes allow the separation of concerns by handling business logic and presentation.
- Utility Modules: In src/Utils with helper classes like DunnArray, DunnFile, and DunnMap that support reusable functions across the project.

##### Out Relationships and Interactions
- The HTTP Layer (Request and Response objects) encapsulates the request details.
- Next, the request flows through the Middleware chain (using FilterChain and its associated filters), ensuring cross-cutting concerns like CORS and file handling are applied.
- The request is then passed to the Router, which uses its RouteStore to match the URL against registered routes.
- Once a route is determined, the appropriate controller from the MVC layer (using Controller and ControllerAction) will be invoked. The controller ultimately uses a View to generate the response.
- Utility classes support operations in various components, providing common data structures or file operations.

##### Important Architectural Details and Patterns
- Emphasis on separation of concerns: HTTP handling, middleware processing, routing, and MVC segments are clearly distinguished.
- OOP principles: Inheritance and modular design are visible through well-organized namespaces (Base, Http, MVC, Middlewares, Router, Utils).
- Inspired by HttpServlet: The design follows a clear request lifecycle similar to Java’s servlet model with emphasis on filters (middlewares) and controllers.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Node
    IR["Incoming HTTP Request"]:::external

    %% HTTP Handling Layer
    subgraph "HTTP Handling"
        DS["DunnServer.php"]:::dunncore
        DBase["Dunn (Base)"]:::dunncore
        Req["Request"]:::httplayer
        Res["Response"]:::httplayer
        HA["HttpAction"]:::httplayer
        FU["FileUpload"]:::httplayer
    end

    %% Middleware Layer
    subgraph "Middleware"
        FC["FilterChain"]:::middleware
        Cors["CorsFilter"]:::middleware
        DoF["DoFilter"]:::middleware
        Filt["Filter"]:::middleware
        HFF["HandleFileFilter"]:::middleware
    end

    %% Routing Layer
    subgraph "Routing"
        Router["Router"]:::routing
        RS["RouteStore"]:::routing
        Route["Route"]:::routing
    end

    %% MVC Layer
    subgraph "MVC"
        Controller["Controller"]:::mvc
        ControllerAction["ControllerAction"]:::mvc
        View["View"]:::mvc
    end

    %% Utilities Layer
    subgraph "Utilities"
        DunnArray["DunnArray"]:::utility
        DunnFile["DunnFile"]:::utility
        DunnMap["DunnMap"]:::utility
    end

    %% Flow Connections
    IR --> DS
    DS --> DBase
    DBase --> Req
    Req --> FC
    FC --> Cors
    Cors --> DoF
    DoF --> Filt
    Filt --> HFF
    HFF --> Router
    Router --> RS
    RS --> Route
    Route --> Controller
    Controller --> ControllerAction
    ControllerAction --> View
    View --> Res

    %% Optional support connections
    DS -.-> HA
    DS -.-> FU
    DBase -.-> DunnArray
    DBase -.-> DunnFile
    DBase -.-> DunnMap

    %% Styling Classes
    classDef external fill:#ffffff,stroke:#000000,stroke-width:1px;
    classDef dunncore fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef httplayer fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef middleware fill:#e6ffe6,stroke:#339933,stroke-width:2px;
    classDef routing fill:#fff0b3,stroke:#ff9900,stroke-width:2px;
    classDef mvc fill:#f0e68c,stroke:#daa520,stroke-width:2px;
    classDef utility fill:#e6e6fa,stroke:#8a2be2,stroke-width:2px;

    %% Click Events for DunnServer Core
    click DS "https://github.com/dunneeee/dunnserver/blob/main/src/DunnServer.php"
    click DBase "https://github.com/dunneeee/dunnserver/blob/main/src/Base/Dunn.php"

    %% Click Events for HTTP Layer
    click Req "https://github.com/dunneeee/dunnserver/blob/main/src/Http/Request.php"
    click Res "https://github.com/dunneeee/dunnserver/blob/main/src/Http/Response.php"
    click HA "https://github.com/dunneeee/dunnserver/blob/main/src/Http/HttpAction.php"
    click FU "https://github.com/dunneeee/dunnserver/blob/main/src/Http/FileUpload.php"

    %% Click Events for Middleware
    click FC "https://github.com/dunneeee/dunnserver/blob/main/src/Middlewares/FilterChain.php"
    click Cors "https://github.com/dunneeee/dunnserver/blob/main/src/Middlewares/CorsFilter.php"
    click DoF "https://github.com/dunneeee/dunnserver/blob/main/src/Middlewares/DoFilter.php"
    click Filt "https://github.com/dunneeee/dunnserver/blob/main/src/Middlewares/Filter.php"
    click HFF "https://github.com/dunneeee/dunnserver/blob/main/src/Middlewares/HandleFileFilter.php"

    %% Click Events for Routing
    click Router "https://github.com/dunneeee/dunnserver/blob/main/src/Router/Router.php"
    click RS "https://github.com/dunneeee/dunnserver/blob/main/src/Router/RouteStore.php"
    click Route "https://github.com/dunneeee/dunnserver/blob/main/src/Router/Route.php"

    %% Click Events for MVC
    click Controller "https://github.com/dunneeee/dunnserver/blob/main/src/MVC/Controller.php"
    click ControllerAction "https://github.com/dunneeee/dunnserver/blob/main/src/MVC/ControllerAction.php"
    click View "https://github.com/dunneeee/dunnserver/blob/main/src/MVC/View.php"

    %% Click Events for Utilities
    click DunnArray "https://github.com/dunneeee/dunnserver/blob/main/src/Utils/DunnArray.php"
    click DunnFile "https://github.com/dunneeee/dunnserver/blob/main/src/Utils/DunnFile.php"
    click DunnMap "https://github.com/dunneeee/dunnserver/blob/main/src/Utils/DunnMap.php"
```
