# rgrmra/webserv architecture

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

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

## Overview

Webserv is a non-blocking C++98 HTTP/1.1 server. Its principal workflow accepts a client request, parses it against configured servers and routes, resolves the target resource, handles the requested method (including static delivery, uploads, deletion, or CGI), and returns an HTTP response. Configuration parsing, URL/resource resolution, and CGI environment setup are distinct domain stages. The README documents major capabilities not fully evidenced by the excerpts; edges for those documented behaviors cite it, while uncertain internal wiring is omitted.

Main entry points: [`src/file/Cgi.cpp`](https://github.com/rgrmra/webserv/blob/develop/src/file/Cgi.cpp) (CGI execution), [`src/connection/Connection.cpp`](https://github.com/rgrmra/webserv/blob/develop/src/connection/Connection.cpp) (Client connection), [`src/connection/WebServ.cpp`](https://github.com/rgrmra/webserv/blob/develop/src/connection/WebServ.cpp) (Socket event loop), [`src/parser/configuration/Http.cpp`](https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Http.cpp) (HTTP config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_main["Server startup<br/>[main.cpp]"]
  node_event_loop["Socket event loop<br/>[WebServ.cpp]"]
  node_connection["Client connection<br/>[Connection.cpp]"]
end

subgraph group_config["Configuration"]
  node_http_config["HTTP config<br/>[Http.cpp]"]
  node_server_config["Server config<br/>[Server.cpp]"]
  node_location_config["Route config<br/>[Location.cpp]"]
  node_config_parser["Config directives<br/>[directive.cpp]"]
end

subgraph group_http["HTTP handling"]
  node_request_parser["Request parsing<br/>[request.cpp]"]
  node_url["URL resolution<br/>[URL.cpp]"]
  node_response["Response builder<br/>[response.cpp]"]
  node_get["GET handling<br/>[get.cpp]"]
  node_post["POST handling<br/>[post.cpp]"]
  node_delete["DELETE handling<br/>[delete.cpp]"]
end

subgraph group_resources["Resources and CGI"]
  node_resource["Resource access<br/>[Resource.cpp]"]
  node_file["File delivery<br/>[File.cpp]"]
  node_directory["Directory listing<br/>[Directory.cpp]"]
  node_cgi["CGI execution<br/>[Cgi.cpp]"]
  node_cgi_env["CGI environment<br/>[Environment.cpp]"]
end

node_client(("HTTP client"))
node_filesystem[("Website files")]
node_cgi_service["CGI interpreter"]

node_client -->|"sends requests"| node_event_loop
node_main -->|"loads config"| node_http_config
node_event_loop -->|"reads listeners"| node_http_config
node_event_loop -->|"accepts clients"| node_connection
node_event_loop -->|"dispatches I/O"| node_connection
node_http_config -->|"holds servers"| node_server_config
node_server_config -->|"holds routes"| node_location_config
node_config_parser -->|"parses directives"| node_http_config
node_config_parser -->|"parses directives"| node_server_config
node_config_parser -->|"parses directives"| node_location_config
node_connection -->|"parses request"| node_request_parser
node_connection -->|"resolves target"| node_url
node_connection -->|"builds response"| node_response
node_get -->|"serves files"| node_file
node_get -->|"lists directories"| node_directory
node_get -->|"starts CGI"| node_cgi
node_post -->|"accepts uploads"| node_filesystem
node_delete -->|"deletes resources"| node_filesystem
node_file -.->|"reads content"| node_filesystem
node_directory -.->|"lists contents"| node_filesystem
node_cgi -->|"builds environment"| node_cgi_env
node_cgi -->|"executes script"| node_cgi_service
node_cgi -->|"builds response"| node_response
node_cgi -.->|"returns output"| node_client

click node_main "https://github.com/rgrmra/webserv/blob/develop/src/main.cpp"
click node_event_loop "https://github.com/rgrmra/webserv/blob/develop/src/connection/WebServ.cpp"
click node_connection "https://github.com/rgrmra/webserv/blob/develop/src/connection/Connection.cpp"
click node_http_config "https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Http.cpp"
click node_server_config "https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Server.cpp"
click node_location_config "https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Location.cpp"
click node_config_parser "https://github.com/rgrmra/webserv/blob/develop/src/parser/directive.cpp"
click node_request_parser "https://github.com/rgrmra/webserv/blob/develop/src/parser/request/request.cpp"
click node_url "https://github.com/rgrmra/webserv/blob/develop/src/response/URL.cpp"
click node_response "https://github.com/rgrmra/webserv/blob/develop/src/response/response.cpp"
click node_get "https://github.com/rgrmra/webserv/blob/develop/src/response/methods/get.cpp"
click node_post "https://github.com/rgrmra/webserv/blob/develop/src/response/methods/post.cpp"
click node_delete "https://github.com/rgrmra/webserv/blob/develop/src/response/methods/delete.cpp"
click node_resource "https://github.com/rgrmra/webserv/blob/develop/src/file/Resource.cpp"
click node_file "https://github.com/rgrmra/webserv/blob/develop/src/file/File.cpp"
click node_directory "https://github.com/rgrmra/webserv/blob/develop/src/file/Directory.cpp"
click node_cgi "https://github.com/rgrmra/webserv/blob/develop/src/file/Cgi.cpp"
click node_cgi_env "https://github.com/rgrmra/webserv/blob/develop/src/file/Environment.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_main,node_event_loop,node_connection,node_client toneBlue
class node_http_config,node_server_config,node_location_config,node_config_parser,node_filesystem toneAmber
class node_request_parser,node_url,node_response,node_get,node_post,node_delete toneMint
class node_resource,node_file,node_directory,node_cgi,node_cgi_env toneRose
class node_cgi_service toneIndigo
```

## Components

### Server runtime

- [Server startup](https://github.com/rgrmra/webserv/blob/develop/src/main.cpp): `src/main.cpp`
- [Socket event loop](https://github.com/rgrmra/webserv/blob/develop/src/connection/WebServ.cpp): `src/connection/WebServ.cpp`
- [Client connection](https://github.com/rgrmra/webserv/blob/develop/src/connection/Connection.cpp): `src/connection/Connection.cpp`

### Configuration

- [HTTP config](https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Http.cpp): `src/parser/configuration/Http.cpp`
- [Server config](https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Server.cpp): `src/parser/configuration/Server.cpp`
- [Route config](https://github.com/rgrmra/webserv/blob/develop/src/parser/configuration/Location.cpp): `src/parser/configuration/Location.cpp`
- [Config directives](https://github.com/rgrmra/webserv/blob/develop/src/parser/directive.cpp): `src/parser/directive.cpp`

### HTTP handling

- [Request parsing](https://github.com/rgrmra/webserv/blob/develop/src/parser/request/request.cpp): `src/parser/request/request.cpp`
- [URL resolution](https://github.com/rgrmra/webserv/blob/develop/src/response/URL.cpp): `src/response/URL.cpp`
- [Response builder](https://github.com/rgrmra/webserv/blob/develop/src/response/response.cpp): `src/response/response.cpp`
- [GET handling](https://github.com/rgrmra/webserv/blob/develop/src/response/methods/get.cpp): `src/response/methods/get.cpp`
- [POST handling](https://github.com/rgrmra/webserv/blob/develop/src/response/methods/post.cpp): `src/response/methods/post.cpp`
- [DELETE handling](https://github.com/rgrmra/webserv/blob/develop/src/response/methods/delete.cpp): `src/response/methods/delete.cpp`

### Resources and CGI

- [Resource access](https://github.com/rgrmra/webserv/blob/develop/src/file/Resource.cpp): `src/file/Resource.cpp`
- [File delivery](https://github.com/rgrmra/webserv/blob/develop/src/file/File.cpp): `src/file/File.cpp`
- [Directory listing](https://github.com/rgrmra/webserv/blob/develop/src/file/Directory.cpp): `src/file/Directory.cpp`
- [CGI execution](https://github.com/rgrmra/webserv/blob/develop/src/file/Cgi.cpp): `src/file/Cgi.cpp`
- [CGI environment](https://github.com/rgrmra/webserv/blob/develop/src/file/Environment.cpp): `src/file/Environment.cpp`

### Other components

- **HTTP client**
- **Website files**
- **CGI interpreter**

## Connections

- HTTP client → Socket event loop: sends requests
- Server startup → HTTP config: loads config (evidence: `src/main.cpp`)
- Socket event loop → HTTP config: reads listeners (evidence: `src/connection/WebServ.cpp`)
- Socket event loop → Client connection: accepts clients (evidence: `src/connection/WebServ.cpp`)
- Socket event loop → Client connection: dispatches I/O (evidence: `src/connection/WebServ.cpp`)
- HTTP config → Server config: holds servers
- Server config → Route config: holds routes
- Config directives → HTTP config: parses directives
- Config directives → Server config: parses directives (evidence: `src/parser/configuration/Server.cpp`)
- Config directives → Route config: parses directives
- Client connection → Request parsing: parses request (evidence: `src/connection/Connection.cpp`)
- Client connection → URL resolution: resolves target (evidence: `src/connection/Connection.cpp`)
- Client connection → Response builder: builds response (evidence: `src/connection/Connection.cpp`)
- GET handling → File delivery: serves files (evidence: `src/response/methods/get.cpp`)
- GET handling → Directory listing: lists directories (evidence: `src/response/methods/get.cpp`)
- GET handling → CGI execution: starts CGI (evidence: `src/response/methods/get.cpp`)
- POST handling → Website files: accepts uploads
- DELETE handling → Website files: deletes resources
- File delivery → Website files: reads content
- Directory listing → Website files: lists contents
- CGI execution → CGI environment: builds environment (evidence: `src/file/Cgi.cpp`)
- CGI execution → CGI interpreter: executes script (evidence: `src/file/Cgi.cpp`)
- CGI execution → Response builder: builds response (evidence: `src/file/Cgi.cpp`)
- CGI execution → HTTP client: returns output
