# icydrae/router architecture

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

- Interactive diagram: https://gitdiagram.com/icydrae/router
- Repository: https://github.com/icydrae/router

## Overview

##### Component Relationships

a. Primary Flow:
- HTTP Request → Router → RouteCollector → Dispatcher → Handler (Controller/Closure)

b. Supporting Components:
- RouteCollector ←→ RouteParser
- RouteCollector ←→ DataGenerator

##### Key Features
- Route registration flow
- Route matching process
- Exception handling paths
- Controller resolution path
- HTTP method handling (GET, POST, PUT, etc.)

##### Detailed Component Breakdown

- Exception Handling:
- ClassNotFoundException
- InvalidRouteException
- MethodNotAllowedException
- MethodNotCalledException

##### Important Elements to Highlight

a. Router Features:
- Static routing
- Dynamic routing (with parameters)
- Subrouting (groups)
- Controller@method resolution
- HEAD request handling

b. Data Flow:
- Route registration
- Route parsing
- Route matching
- Handler dispatch

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    Request(("HTTP Request")):::input
    Router["Router"]:::core
    RouteCollector["RouteCollector"]:::core
    RouteParser["RouteParser"]:::core
    DataGenerator["DataGenerator"]:::core
    Dispatcher["Dispatcher"]:::core
    Handler["Controller/Closure"]:::handler

    %% Interfaces
    subgraph Interfaces
        direction TB
        DGI["DataGeneratorInterface"]:::interface
        DI["DispatcherInterface"]:::interface
        RPI["RouteParserInterface"]:::interface
    end

    %% Exception Handling
    subgraph Exceptions
        direction TB
        CNF["ClassNotFoundException"]:::error
        IRE["InvalidRouteException"]:::error
        MNA["MethodNotAllowedException"]:::error
        MNC["MethodNotCalledException"]:::error
    end

    %% Relationships
    Request --> Router
    Router --> RouteCollector
    RouteCollector --> RouteParser
    RouteCollector --> DataGenerator
    RouteCollector --> Dispatcher
    Dispatcher --> Handler

    %% Interface Implementations
    DataGenerator -.-> DGI
    Dispatcher -.-> DI
    RouteParser -.-> RPI

    %% Error Handling
    Router -.-> Exceptions

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef interface fill:#90EE90,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef error fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef input fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef handler fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Click Events
    click Router "https://github.com/icydrae/router/blob/master/src/Router.php"
    click RouteCollector "https://github.com/icydrae/router/blob/master/src/RouteCollector.php"
    click RouteParser "https://github.com/icydrae/router/blob/master/src/RouteParser.php"
    click DataGenerator "https://github.com/icydrae/router/blob/master/src/DataGenerator.php"
    click Dispatcher "https://github.com/icydrae/router/blob/master/src/Dispatcher.php"
    click DGI "https://github.com/icydrae/router/blob/master/src/Interfaces/DataGeneratorInterface.php"
    click DI "https://github.com/icydrae/router/blob/master/src/Interfaces/DispatcherInterface.php"
    click RPI "https://github.com/icydrae/router/blob/master/src/Interfaces/RouteParserInterface.php"
    click CNF "https://github.com/icydrae/router/blob/master/src/Exception/ClassNotFoundException.php"
    click IRE "https://github.com/icydrae/router/blob/master/src/Exception/InvalidRouteException.php"
    click MNA "https://github.com/icydrae/router/blob/master/src/Exception/MethodNotAllowedException.php"
    click MNC "https://github.com/icydrae/router/blob/master/src/Exception/MethodNotCalledException.php"
```
