# tgomez-f/webserver-http architecture

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

- Interactive diagram: https://gitdiagram.com/tgomez-f/webserver-http
- Repository: https://github.com/tgomez-f/webserver-http

## Overview

WebServe is a configurable HTTP web server. Its principal workflow is accepting a client connection, receiving and parsing an HTTP request, selecting configured server/location behavior, then producing and sending a response; routes can also dispatch CGI requests. Configuration parsing, static-file handling, redirects, autoindexing, error pages, and CGI are represented as distinct product capabilities. The README contains references rather than an architectural description, and sampled source is incomplete; dashed, uncited edges mark relationships that are plausible but not verified as calls.

Main entry points: [`src/core/WebServ.cpp`](https://github.com/tgomez-f/webserver-http/blob/main/src/core/WebServ.cpp) (Event loop), [`src/http/StaticHandler.cpp`](https://github.com/tgomez-f/webserver-http/blob/main/src/http/StaticHandler.cpp) (Resource handler), [`src/config/Parser.cpp`](https://github.com/tgomez-f/webserver-http/blob/main/src/config/Parser.cpp) (Config parser), [`src/core/Socket.cpp`](https://github.com/tgomez-f/webserver-http/blob/main/src/core/Socket.cpp) (Listening sockets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Configuration"]
  node_lexer["Config lexer<br/>[Lexer.cpp]"]
  node_parser["Config parser<br/>[Parser.cpp]"]
  node_server_config["Virtual servers<br/>[Server.cpp]"]
  node_location_config["Route settings<br/>[Location.cpp]"]
end

subgraph group_network["Network Runtime"]
  node_socket["Listening sockets<br/>[Socket.cpp]"]
  node_event_loop["Event loop<br/>[WebServ.cpp]"]
  node_client_state["Connection state<br/>[Client.cpp]"]
end

subgraph group_http["HTTP Handling"]
  node_request["HTTP request<br/>[Request.cpp]"]
  node_static_handler["Resource handler<br/>[StaticHandler.cpp]"]
  node_response["HTTP response<br/>[Response.cpp]"]
end

subgraph group_integrations["Request Features"]
  node_cgi["CGI execution<br/>[Cgi.cpp]"]
  node_error_support["Error responses<br/>[utils.cpp]"]
end

node_operator(("Server operator"))
node_browser(("HTTP client"))
node_config_input["Config file"]
node_filesystem[("Served files")]
node_cgi_program["CGI program"]

node_operator -.->|"configures"| node_config_input
node_config_input -.->|"tokenizes"| node_lexer
node_lexer -.->|"provides tokens"| node_parser
node_parser -.->|"builds"| node_server_config
node_parser -.->|"sets routes"| node_location_config
node_server_config -.->|"defines listeners"| node_socket
node_browser -.->|"connects"| node_socket
node_socket -.->|"serves events"| node_event_loop
node_event_loop -.->|"tracks connections"| node_client_state
node_client_state -.->|"parses request"| node_request
node_event_loop -.->|"dispatches request"| node_request
node_event_loop -.->|"dispatches handling"| node_static_handler
node_static_handler -.->|"uses route settings"| node_location_config
node_static_handler -.->|"reads resources"| node_filesystem
node_static_handler -.->|"builds response"| node_response
node_event_loop -.->|"dispatches CGI"| node_cgi
node_cgi -.->|"executes"| node_cgi_program
node_event_loop -.->|"builds error response"| node_error_support
node_response -.->|"sends response"| node_client_state

click node_lexer "https://github.com/tgomez-f/webserver-http/blob/main/src/config/Lexer.cpp"
click node_parser "https://github.com/tgomez-f/webserver-http/blob/main/src/config/Parser.cpp"
click node_server_config "https://github.com/tgomez-f/webserver-http/blob/main/src/core/Server.cpp"
click node_location_config "https://github.com/tgomez-f/webserver-http/blob/main/src/core/Location.cpp"
click node_socket "https://github.com/tgomez-f/webserver-http/blob/main/src/core/Socket.cpp"
click node_event_loop "https://github.com/tgomez-f/webserver-http/blob/main/src/core/WebServ.cpp"
click node_client_state "https://github.com/tgomez-f/webserver-http/blob/main/src/client/Client.cpp"
click node_request "https://github.com/tgomez-f/webserver-http/blob/main/src/http/Request.cpp"
click node_static_handler "https://github.com/tgomez-f/webserver-http/blob/main/src/http/StaticHandler.cpp"
click node_response "https://github.com/tgomez-f/webserver-http/blob/main/src/http/Response.cpp"
click node_cgi "https://github.com/tgomez-f/webserver-http/blob/main/src/cgi/Cgi.cpp"
click node_error_support "https://github.com/tgomez-f/webserver-http/blob/main/src/utils/utils.cpp"

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_lexer,node_parser,node_server_config,node_location_config,node_browser toneBlue
class node_socket,node_event_loop,node_client_state,node_filesystem toneAmber
class node_request,node_static_handler,node_response,node_operator toneMint
class node_cgi,node_error_support toneRose
class node_config_input,node_cgi_program toneIndigo
```

## Components

### Configuration

- [Config lexer](https://github.com/tgomez-f/webserver-http/blob/main/src/config/Lexer.cpp): `src/config/Lexer.cpp`
- [Config parser](https://github.com/tgomez-f/webserver-http/blob/main/src/config/Parser.cpp): `src/config/Parser.cpp`
- [Virtual servers](https://github.com/tgomez-f/webserver-http/blob/main/src/core/Server.cpp): `src/core/Server.cpp`
- [Route settings](https://github.com/tgomez-f/webserver-http/blob/main/src/core/Location.cpp): `src/core/Location.cpp`

### Network Runtime

- [Listening sockets](https://github.com/tgomez-f/webserver-http/blob/main/src/core/Socket.cpp): `src/core/Socket.cpp`
- [Event loop](https://github.com/tgomez-f/webserver-http/blob/main/src/core/WebServ.cpp): `src/core/WebServ.cpp`
- [Connection state](https://github.com/tgomez-f/webserver-http/blob/main/src/client/Client.cpp): `src/client/Client.cpp`

### HTTP Handling

- [HTTP request](https://github.com/tgomez-f/webserver-http/blob/main/src/http/Request.cpp): `src/http/Request.cpp`
- [Resource handler](https://github.com/tgomez-f/webserver-http/blob/main/src/http/StaticHandler.cpp): `src/http/StaticHandler.cpp`
- [HTTP response](https://github.com/tgomez-f/webserver-http/blob/main/src/http/Response.cpp): `src/http/Response.cpp`

### Request Features

- [CGI execution](https://github.com/tgomez-f/webserver-http/blob/main/src/cgi/Cgi.cpp): `src/cgi/Cgi.cpp`
- [Error responses](https://github.com/tgomez-f/webserver-http/blob/main/src/utils/utils.cpp): `src/utils/utils.cpp`

### Other components

- **Server operator**
- **HTTP client**
- **Config file**
- **Served files**
- **CGI program**

## Connections

- Server operator → Config file: configures
- Config file → Config lexer: tokenizes
- Config lexer → Config parser: provides tokens
- Config parser → Virtual servers: builds
- Config parser → Route settings: sets routes
- Virtual servers → Listening sockets: defines listeners
- HTTP client → Listening sockets: connects
- Listening sockets → Event loop: serves events
- Event loop → Connection state: tracks connections
- Connection state → HTTP request: parses request
- Event loop → HTTP request: dispatches request
- Event loop → Resource handler: dispatches handling
- Resource handler → Route settings: uses route settings
- Resource handler → Served files: reads resources
- Resource handler → HTTP response: builds response
- Event loop → CGI execution: dispatches CGI
- CGI execution → CGI program: executes
- Event loop → Error responses: builds error response
- HTTP response → Connection state: sends response
