# robsonvleite/router architecture

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

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

## Overview

CoffeeCode Router is a small PHP routing component. An incoming request reaches the application’s Router, which registers RESTful routes and dispatches by HTTP method and path; matching routes can apply middleware before invoking a callable or controller action with route data. The library also supports method spoofing, named-route URL generation, and redirects. Example controllers and middleware illustrate these features. The graph follows the sampled core sources and README; example controller implementations not excerpted are included only where the source index or README identifies their use.

Main entry points: [`exemple/controller/index.php`](https://github.com/robsonvleite/router/blob/master/exemple/controller/index.php) (Example entry point), [`src/RouterTrait.php`](https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php) (Middleware gate), [`exemple/controller/Http/Middlewares.php`](https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Middlewares.php) (Middleware examples), [`src/Router.php`](https://github.com/robsonvleite/router/blob/master/src/Router.php) (Router API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_router_core["Routing core"]
  node_router_api["Router API<br/>[Router.php]"]
  node_dispatch_state["Dispatch state<br/>[Dispatch.php]"]
  node_route_registry["Route registration<br/>[RouterTrait.php]"]
  node_named_urls["Named URLs<br/>[RouterTrait.php]"]
  node_redirects["Redirects<br/>[Dispatch.php]"]
end

subgraph group_request_execution["Request execution"]
  node_route_match["Route matching<br/>[Dispatch.php]"]
  node_method_spoofing["Method spoofing<br/>[RouterTrait.php]"]
  node_middleware_gate["Middleware gate<br/>[RouterTrait.php]"]
  node_handler_execution["Handler execution<br/>[RouterTrait.php]"]
end

subgraph group_example_app["Example application"]
  node_example_entry["Example entry point<br/>[index.php]"]
  node_coffee_controller["Coffee controller<br/>[Coffee.php]"]
  node_name_controller["Name controller<br/>[Name.php]"]
  node_middleware_examples["Middleware examples<br/>[Middlewares.php]"]
  node_guest_middleware["Guest middleware<br/>[Guest.php]"]
  node_user_middleware["User middleware<br/>[User.php]"]
  node_group_middleware["Group middleware<br/>[Group.php]"]
  node_spoofing_example["Spoofing example<br/>[index.php]"]
end

node_http_request(("HTTP request"))
node_response(("HTTP response"))

node_http_request -.->|"enters"| node_example_entry
node_example_entry -->|"configures"| node_router_api
node_router_api -->|"extends"| node_dispatch_state
node_router_api -->|"registers routes"| node_route_registry
node_route_registry -->|"reads form data"| node_method_spoofing
node_example_entry -->|"dispatches"| node_dispatch_state
node_dispatch_state -->|"matches request"| node_route_match
node_route_match -->|"executes match"| node_handler_execution
node_handler_execution -->|"checks middleware"| node_middleware_gate
node_handler_execution -.->|"invokes action"| node_coffee_controller
node_handler_execution -.->|"invokes action"| node_name_controller
node_example_entry -->|"uses middleware constants"| node_middleware_examples
node_middleware_examples -->|"references"| node_guest_middleware
node_middleware_examples -->|"references"| node_user_middleware
node_middleware_examples -->|"references"| node_group_middleware
node_middleware_gate -.->|"runs middleware"| node_guest_middleware
node_middleware_gate -.->|"runs middleware"| node_user_middleware
node_middleware_gate -.->|"runs middleware"| node_group_middleware
node_example_entry -->|"uses named routes"| node_named_urls
node_example_entry -->|"redirects errors"| node_redirects
node_named_urls -->|"resolves route"| node_redirects
node_example_entry -.->|"serves result"| node_response
node_spoofing_example -->|"registers verbs"| node_router_api
node_spoofing_example -->|"dispatches"| node_dispatch_state

click node_router_api "https://github.com/robsonvleite/router/blob/master/src/Router.php"
click node_dispatch_state "https://github.com/robsonvleite/router/blob/master/src/Dispatch.php"
click node_route_registry "https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php"
click node_route_match "https://github.com/robsonvleite/router/blob/master/src/Dispatch.php"
click node_method_spoofing "https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php"
click node_middleware_gate "https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php"
click node_handler_execution "https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php"
click node_named_urls "https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php"
click node_redirects "https://github.com/robsonvleite/router/blob/master/src/Dispatch.php"
click node_example_entry "https://github.com/robsonvleite/router/blob/master/exemple/controller/index.php"
click node_coffee_controller "https://github.com/robsonvleite/router/blob/master/exemple/controller/Test/Coffee.php"
click node_name_controller "https://github.com/robsonvleite/router/blob/master/exemple/controller/Test/Name.php"
click node_middleware_examples "https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Middlewares.php"
click node_guest_middleware "https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Guest.php"
click node_user_middleware "https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/User.php"
click node_group_middleware "https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Group.php"
click node_spoofing_example "https://github.com/robsonvleite/router/blob/master/exemple/spoofing/index.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_router_api,node_dispatch_state,node_route_registry,node_named_urls,node_redirects toneBlue
class node_route_match,node_method_spoofing,node_middleware_gate,node_handler_execution toneAmber
class node_example_entry,node_coffee_controller,node_name_controller,node_middleware_examples,node_guest_middleware,node_user_middleware,node_group_middleware,node_spoofing_example,node_http_request toneMint
class node_response toneIndigo
```

## Components

### Routing core

- [Router API](https://github.com/robsonvleite/router/blob/master/src/Router.php): `src/Router.php`
- [Dispatch state](https://github.com/robsonvleite/router/blob/master/src/Dispatch.php): `src/Dispatch.php`
- [Route registration](https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php): `src/RouterTrait.php`
- [Named URLs](https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php): `src/RouterTrait.php`
- [Redirects](https://github.com/robsonvleite/router/blob/master/src/Dispatch.php): `src/Dispatch.php`

### Request execution

- [Route matching](https://github.com/robsonvleite/router/blob/master/src/Dispatch.php): `src/Dispatch.php`
- [Method spoofing](https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php): `src/RouterTrait.php`
- [Middleware gate](https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php): `src/RouterTrait.php`
- [Handler execution](https://github.com/robsonvleite/router/blob/master/src/RouterTrait.php): `src/RouterTrait.php`

### Example application

- [Example entry point](https://github.com/robsonvleite/router/blob/master/exemple/controller/index.php): `exemple/controller/index.php`
- [Coffee controller](https://github.com/robsonvleite/router/blob/master/exemple/controller/Test/Coffee.php): `exemple/controller/Test/Coffee.php`
- [Name controller](https://github.com/robsonvleite/router/blob/master/exemple/controller/Test/Name.php): `exemple/controller/Test/Name.php`
- [Middleware examples](https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Middlewares.php): `exemple/controller/Http/Middlewares.php`
- [Guest middleware](https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Guest.php): `exemple/controller/Http/Guest.php`
- [User middleware](https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/User.php): `exemple/controller/Http/User.php`
- [Group middleware](https://github.com/robsonvleite/router/blob/master/exemple/controller/Http/Group.php): `exemple/controller/Http/Group.php`
- [Spoofing example](https://github.com/robsonvleite/router/blob/master/exemple/spoofing/index.php): `exemple/spoofing/index.php`

### Other components

- **HTTP request**
- **HTTP response**

## Connections

- HTTP request → Example entry point: enters (evidence: `README.md`)
- Example entry point → Router API: configures (evidence: `exemple/controller/index.php`)
- Router API → Dispatch state: extends (evidence: `src/Router.php`)
- Router API → Route registration: registers routes (evidence: `src/Router.php`)
- Route registration → Method spoofing: reads form data (evidence: `src/RouterTrait.php`)
- Example entry point → Dispatch state: dispatches (evidence: `exemple/controller/index.php`)
- Dispatch state → Route matching: matches request (evidence: `src/Dispatch.php`)
- Route matching → Handler execution: executes match (evidence: `src/Dispatch.php`)
- Handler execution → Middleware gate: checks middleware (evidence: `src/RouterTrait.php`)
- Handler execution → Coffee controller: invokes action
- Handler execution → Name controller: invokes action
- Example entry point → Middleware examples: uses middleware constants (evidence: `exemple/controller/index.php`)
- Middleware examples → Guest middleware: references (evidence: `exemple/controller/Http/Middlewares.php`)
- Middleware examples → User middleware: references (evidence: `exemple/controller/Http/Middlewares.php`)
- Middleware examples → Group middleware: references (evidence: `exemple/controller/Http/Middlewares.php`)
- Middleware gate → Guest middleware: runs middleware
- Middleware gate → User middleware: runs middleware
- Middleware gate → Group middleware: runs middleware
- Example entry point → Named URLs: uses named routes (evidence: `exemple/controller/index.php`)
- Example entry point → Redirects: redirects errors (evidence: `exemple/controller/index.php`)
- Named URLs → Redirects: resolves route (evidence: `src/Dispatch.php`)
- Example entry point → HTTP response: serves result
- Spoofing example → Router API: registers verbs (evidence: `exemple/spoofing/index.php`)
- Spoofing example → Dispatch state: dispatches (evidence: `exemple/spoofing/index.php`)
