# erabareta/webserv architecture

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

- Interactive diagram: https://gitdiagram.com/erabareta/webserv
- Repository: https://github.com/erabareta/webserv

## Overview

WebServ is a C++98 HTTP/1.0 server. Its main workflow parses configuration, accepts concurrent client connections, incrementally parses and validates requests, then serves files or builds method-specific responses; configured CGI requests instead run a program and return its output through the client connection. Response handling also covers uploads, deletion, directory listing, error pages, redirects, cookies, and sessions. The graph reflects the README’s documented capabilities, but some subsystem links rely on that documentation because implementation excerpts are incomplete.

Main entry points: [`Client/Client.cpp`](https://github.com/erabareta/webserv/blob/main/Client/Client.cpp) (Client state and I/O), [`Server/Multiplexing.cpp`](https://github.com/erabareta/webserv/blob/main/Server/Multiplexing.cpp) (Event loop), [`main.cpp`](https://github.com/erabareta/webserv/blob/main/main.cpp) (Startup), [`Client/Response/build_response.cpp`](https://github.com/erabareta/webserv/blob/main/Client/Response/build_response.cpp) (Response builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and configuration"]
  node_main["Startup<br/>[main.cpp]"]
  node_config_parser["Config parser"]
  node_config["Server settings<br/>[parser.hpp]"]
end

subgraph group_network["Connection handling"]
  node_multiplex["Event loop<br/>[Multiplexing.cpp]"]
  node_timeout["Timeout tracker<br/>[TimeoutTracker.cpp]"]
  node_client["Client state and I/O<br/>[Client.cpp]"]
end

subgraph group_http["HTTP processing"]
  node_request["Request parser<br/>[request.cpp]"]
  node_response["Response builder<br/>[build_response.cpp]"]
  node_sessions["Cookie sessions<br/>[session_cookie.cpp]"]
end

subgraph group_integrations["External resources"]
  node_webroot["Site files"]
  node_cgi_programs["CGI programs"]
  node_cgi_runtime["CGI runtime"]
end

node_operator(("Server operator"))
node_browser(("HTTP client"))

node_operator -->|"starts"| node_main
node_main -->|"loads config"| node_config_parser
node_config_parser -->|"builds settings"| node_config
node_main -->|"starts loop"| node_multiplex
node_multiplex -->|"uses settings"| node_config
node_browser -->|"sends requests"| node_multiplex
node_multiplex -->|"accepts connection"| node_client
node_multiplex -->|"dispatches I/O"| node_client
node_client -->|"parses request"| node_request
node_client -->|"builds response"| node_response
node_multiplex -->|"tracks deadlines"| node_timeout
node_response -->|"reads or writes files"| node_webroot
node_response -->|"checks session"| node_sessions
node_client -->|"launches CGI"| node_cgi_runtime
node_client -->|"executes configured script"| node_cgi_programs
node_cgi_runtime -->|"runs script"| node_cgi_programs
node_cgi_runtime -->|"returns output"| node_client
node_client -->|"sends response"| node_browser

click node_main "https://github.com/erabareta/webserv/blob/main/main.cpp"
click node_config_parser "https://github.com/erabareta/webserv/tree/main/Parser"
click node_config "https://github.com/erabareta/webserv/blob/main/Includes/parser.hpp"
click node_multiplex "https://github.com/erabareta/webserv/blob/main/Server/Multiplexing.cpp"
click node_timeout "https://github.com/erabareta/webserv/blob/main/Server/TimeoutTracker.cpp"
click node_client "https://github.com/erabareta/webserv/blob/main/Client/Client.cpp"
click node_request "https://github.com/erabareta/webserv/blob/main/Client/Request/request.cpp"
click node_response "https://github.com/erabareta/webserv/blob/main/Client/Response/build_response.cpp"
click node_sessions "https://github.com/erabareta/webserv/blob/main/Client/Response/session_cookie.cpp"
click node_webroot "https://github.com/erabareta/webserv/tree/main/web"
click node_cgi_programs "https://github.com/erabareta/webserv/tree/main/web/Cgi/programs"

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_main,node_config_parser,node_config,node_browser toneBlue
class node_multiplex,node_timeout,node_client toneAmber
class node_request,node_response,node_sessions,node_operator toneMint
class node_webroot,node_cgi_programs,node_cgi_runtime toneRose
```

## Components

### Startup and configuration

- [Startup](https://github.com/erabareta/webserv/blob/main/main.cpp): `main.cpp`
- [Config parser](https://github.com/erabareta/webserv/tree/main/Parser): `Parser`
- [Server settings](https://github.com/erabareta/webserv/blob/main/Includes/parser.hpp): `Includes/parser.hpp`

### Connection handling

- [Event loop](https://github.com/erabareta/webserv/blob/main/Server/Multiplexing.cpp): `Server/Multiplexing.cpp`
- [Timeout tracker](https://github.com/erabareta/webserv/blob/main/Server/TimeoutTracker.cpp): `Server/TimeoutTracker.cpp`
- [Client state and I/O](https://github.com/erabareta/webserv/blob/main/Client/Client.cpp): `Client/Client.cpp`

### HTTP processing

- [Request parser](https://github.com/erabareta/webserv/blob/main/Client/Request/request.cpp): `Client/Request/request.cpp`
- [Response builder](https://github.com/erabareta/webserv/blob/main/Client/Response/build_response.cpp): `Client/Response/build_response.cpp`
- [Cookie sessions](https://github.com/erabareta/webserv/blob/main/Client/Response/session_cookie.cpp): `Client/Response/session_cookie.cpp`

### External resources

- [Site files](https://github.com/erabareta/webserv/tree/main/web): `web`
- [CGI programs](https://github.com/erabareta/webserv/tree/main/web/Cgi/programs): `web/Cgi/programs`
- **CGI runtime**

### Other components

- **Server operator**
- **HTTP client**

## Connections

- Server operator → Startup: starts
- Startup → Config parser: loads config
- Config parser → Server settings: builds settings
- Startup → Event loop: starts loop
- Event loop → Server settings: uses settings
- HTTP client → Event loop: sends requests
- Event loop → Client state and I/O: accepts connection
- Event loop → Client state and I/O: dispatches I/O
- Client state and I/O → Request parser: parses request
- Client state and I/O → Response builder: builds response
- Event loop → Timeout tracker: tracks deadlines
- Response builder → Site files: reads or writes files
- Response builder → Cookie sessions: checks session
- Client state and I/O → CGI runtime: launches CGI
- Client state and I/O → CGI programs: executes configured script
- CGI runtime → CGI programs: runs script
- CGI runtime → Client state and I/O: returns output
- Client state and I/O → HTTP client: sends response
