# table-en4/webserv architecture

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

- Interactive diagram: https://gitdiagram.com/table-en4/webserv
- Repository: https://github.com/table-en4/webserv
- Video tour (about a minute): https://gitdiagram.com/table-en4/webserv/video

## Overview

Webserv is a lightweight, non-blocking C++ HTTP server. The principal workflow is: load server and location configuration, accept a client request, parse and route it, then produce and send an HTTP response. Its documented capabilities also include static files, directory listings, uploads, redirects, error pages, and CGI execution with timeout handling. The graph reflects the sampled event loop and CGI calls; some response-building and routing details are documented but not fully excerpted, so those links use README evidence. CGI script files are runtime assets, not proof of specific dispatch targets.

Main entry points: [`srcs/ServerManager.cpp`](https://github.com/table-en4/webserv/blob/main/srcs/ServerManager.cpp) (Event loop), [`srcs/HttpRespons.cpp`](https://github.com/table-en4/webserv/blob/main/srcs/HttpRespons.cpp) (Response handling), [`srcs/CgiHandler.cpp`](https://github.com/table-en4/webserv/blob/main/srcs/CgiHandler.cpp) (CGI handler), [`srcs/main.cpp`](https://github.com/table-en4/webserv/blob/main/srcs/main.cpp) (Program entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and configuration"]
  node_configfile["Server config<br/>[configure.conf]"]
  node_entry["Program entry<br/>[main.cpp]"]
  node_parser["Config parser<br/>[Parser.cpp]"]
  node_serverconfig["Server settings<br/>[ServerConfig.cpp]"]
  node_locationconfig["Location settings<br/>[LocationConfig.cpp]"]
end

subgraph group_network["Connection handling"]
  node_manager["Event loop<br/>[ServerManager.cpp]"]
end

subgraph group_http["HTTP processing"]
  node_request["Request parser<br/>[HttpRequest.cpp]"]
  node_response["Response handling<br/>[HttpRespons.cpp]"]
  node_webroot["Static content<br/>[index.html]"]
  node_upload["Upload content<br/>[index.html]"]
end

subgraph group_cgi["CGI execution"]
  node_cgi_handler["CGI handler<br/>[CgiHandler.cpp]"]
  node_cgi_runtime["CGI interpreter"]
  node_cgi_sample["CGI script<br/>[me.py]"]
end

node_client(("HTTP client"))

node_client -->|"sends requests"| node_manager
node_configfile -->|"loads settings"| node_parser
node_entry -->|"parses config"| node_parser
node_entry -->|"starts servers"| node_manager
node_manager -->|"parses request"| node_request
node_manager -->|"resolves path"| node_response
node_response -.->|"serves files"| node_webroot
node_response -.->|"stores uploads"| node_upload
node_manager -->|"launches CGI"| node_cgi_handler
node_cgi_handler -->|"executes script"| node_cgi_runtime
node_manager -->|"parses CGI output"| node_cgi_handler
node_cgi_sample -.->|"runs as script"| node_cgi_runtime
node_manager -.->|"sends response"| node_client

click node_configfile "https://github.com/table-en4/webserv/blob/main/configure.conf"
click node_entry "https://github.com/table-en4/webserv/blob/main/srcs/main.cpp"
click node_parser "https://github.com/table-en4/webserv/blob/main/srcs/Parser.cpp"
click node_serverconfig "https://github.com/table-en4/webserv/blob/main/srcs/ServerConfig.cpp"
click node_locationconfig "https://github.com/table-en4/webserv/blob/main/srcs/LocationConfig.cpp"
click node_manager "https://github.com/table-en4/webserv/blob/main/srcs/ServerManager.cpp"
click node_request "https://github.com/table-en4/webserv/blob/main/srcs/HttpRequest.cpp"
click node_response "https://github.com/table-en4/webserv/blob/main/srcs/HttpRespons.cpp"
click node_webroot "https://github.com/table-en4/webserv/blob/main/www/index.html"
click node_upload "https://github.com/table-en4/webserv/blob/main/www/upload_file/index.html"
click node_cgi_handler "https://github.com/table-en4/webserv/blob/main/srcs/CgiHandler.cpp"
click node_cgi_sample "https://github.com/table-en4/webserv/blob/main/scripts/me.py"

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_configfile,node_entry,node_parser,node_serverconfig,node_locationconfig,node_client toneBlue
class node_manager toneAmber
class node_request,node_response,node_webroot,node_upload toneMint
class node_cgi_handler,node_cgi_runtime,node_cgi_sample toneRose
```

## Components

### Startup and configuration

- [Server config](https://github.com/table-en4/webserv/blob/main/configure.conf): `configure.conf`
- [Program entry](https://github.com/table-en4/webserv/blob/main/srcs/main.cpp): `srcs/main.cpp`
- [Config parser](https://github.com/table-en4/webserv/blob/main/srcs/Parser.cpp): `srcs/Parser.cpp`
- [Server settings](https://github.com/table-en4/webserv/blob/main/srcs/ServerConfig.cpp): `srcs/ServerConfig.cpp`
- [Location settings](https://github.com/table-en4/webserv/blob/main/srcs/LocationConfig.cpp): `srcs/LocationConfig.cpp`

### Connection handling

- [Event loop](https://github.com/table-en4/webserv/blob/main/srcs/ServerManager.cpp): `srcs/ServerManager.cpp`

### HTTP processing

- [Request parser](https://github.com/table-en4/webserv/blob/main/srcs/HttpRequest.cpp): `srcs/HttpRequest.cpp`
- [Response handling](https://github.com/table-en4/webserv/blob/main/srcs/HttpRespons.cpp): `srcs/HttpRespons.cpp`
- [Static content](https://github.com/table-en4/webserv/blob/main/www/index.html): `www/index.html`
- [Upload content](https://github.com/table-en4/webserv/blob/main/www/upload_file/index.html): `www/upload_file/index.html`

### CGI execution

- [CGI handler](https://github.com/table-en4/webserv/blob/main/srcs/CgiHandler.cpp): `srcs/CgiHandler.cpp`
- **CGI interpreter**
- [CGI script](https://github.com/table-en4/webserv/blob/main/scripts/me.py): `scripts/me.py`

### Other components

- **HTTP client**

## Connections

- HTTP client → Event loop: sends requests (evidence: `README.md`)
- Server config → Config parser: loads settings
- Program entry → Config parser: parses config (evidence: `srcs/main.cpp`)
- Program entry → Event loop: starts servers (evidence: `srcs/main.cpp`)
- Event loop → Request parser: parses request (evidence: `srcs/ServerManager.cpp`)
- Event loop → Response handling: resolves path (evidence: `srcs/ServerManager.cpp`)
- Response handling → Static content: serves files (evidence: `README.md`)
- Response handling → Upload content: stores uploads (evidence: `README.md`)
- Event loop → CGI handler: launches CGI (evidence: `srcs/ServerManager.cpp`)
- CGI handler → CGI interpreter: executes script (evidence: `srcs/CgiHandler.cpp`)
- Event loop → CGI handler: parses CGI output (evidence: `srcs/ServerManager.cpp`)
- CGI script → CGI interpreter: runs as script
- Event loop → HTTP client: sends response (evidence: `README.md`)
