# ahmadmnsur/42_webserv architecture

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

- Interactive diagram: https://gitdiagram.com/ahmadmnsur/42_webserv
- Repository: https://github.com/ahmadmnsur/42_webserv

## Overview

WebServ is a C++ HTTP server. The principal workflow is configuration loading, listening for connections, parsing and routing requests, then producing HTTP responses through method-specific handlers and file/CGI services. Separate branches provide session and cookie APIs. The README documents the broader protocol and file-serving capabilities; source excerpts are partial, so edges are limited to documented or indexed relationships rather than inferred runtime calls.

Main entry points: [`src/config/ConfigParser.cpp`](https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigParser.cpp) (Config parser), [`src/network/ConnectionHandler.cpp`](https://github.com/ahmadmnsur/42_webserv/blob/main/src/network/ConnectionHandler.cpp) (Connection handler), [`src/core/WebServer.cpp`](https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/WebServer.cpp) (Web server), [`src/http/RequestProcessor.cpp`](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/RequestProcessor.cpp) (Request processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_config["Configuration"]
  node_parser["Config parser<br/>[ConfigParser.cpp]"]
  node_tokenizer["Config tokenizer"]
  node_validator["Config validator"]
  node_serverconfig["Server settings<br/>[ServerConfig.cpp]"]
  node_location["Location rules<br/>[Location.cpp]"]
end

subgraph group_server["Server Runtime"]
  node_entry["Server entry<br/>[main.cpp]"]
  node_webserver["Web server<br/>[WebServer.cpp]"]
  node_signals["Signal handling<br/>[SignalHandler.cpp]"]
  node_sockets["Socket manager<br/>[SocketManager.cpp]"]
  node_connections["Connection handler"]
  node_clientdata["Client state<br/>[ClientData.cpp]"]
end

subgraph group_http["HTTP Processing"]
  node_request["Request processing"]
  node_factory["Processor factory"]
  node_httprequest["HTTP request<br/>[HttpRequest.cpp]"]
  node_httpresponse["HTTP response<br/>[HttpResponse.cpp]"]
end

subgraph group_files["File and CGI"]
  node_get["GET handler"]
  node_post["POST handler"]
  node_delete["DELETE handler"]
  node_cgi["CGI execution<br/>[IHttpProcessor.cpp]"]
  node_filehandler["File operations<br/>[FileHandler.cpp]"]
end

subgraph group_state["Sessions and Cookies"]
  node_sessionapi["Session API"]
  node_sessionhandler["Session handling<br/>[SessionHandler.cpp]"]
  node_sessions[("Session store<br/>[SessionManager.cpp]")]
  node_cookieapi["Cookie API"]
  node_cookies["Cookie handling<br/>[CookieManager.cpp]"]
end

node_client(("HTTP client"))

node_client -->|"sends requests"| node_entry
node_entry -->|"parses config"| node_parser
node_entry -->|"starts server"| node_webserver
node_parser -->|"uses tokens"| node_tokenizer
node_parser -->|"validates config"| node_validator
node_parser -->|"builds settings"| node_serverconfig
node_parser -->|"builds locations"| node_location
node_webserver -->|"handles shutdown"| node_signals
node_webserver -->|"manages sockets"| node_sockets
node_webserver -->|"dispatches connections"| node_connections
node_connections -->|"tracks clients"| node_clientdata
node_connections -->|"processes requests"| node_request
node_connections -->|"parses requests"| node_httprequest
node_connections -->|"sends responses"| node_httpresponse
node_request -->|"selects handler"| node_factory
node_factory -->|"selects GET"| node_get
node_factory -->|"selects POST"| node_post
node_factory -->|"selects DELETE"| node_delete
node_get -->|"serves files"| node_filehandler
node_get -->|"runs CGI"| node_cgi
node_post -->|"handles uploads"| node_filehandler
node_request -->|"routes API"| node_sessionapi
node_request -->|"routes API"| node_cookieapi
node_sessionapi -->|"manages sessions"| node_sessions
node_sessionhandler -->|"manages sessions"| node_sessions
node_sessionhandler -->|"uses cookies"| node_cookies
node_cookieapi -->|"manages cookies"| node_cookies
node_sessionapi -->|"uses cookies"| node_cookies

click node_entry "https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/main.cpp"
click node_parser "https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigParser.cpp"
click node_tokenizer "https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigTokenizer.cpp"
click node_validator "https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigValidator.cpp"
click node_serverconfig "https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ServerConfig.cpp"
click node_location "https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/Location.cpp"
click node_webserver "https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/WebServer.cpp"
click node_signals "https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/SignalHandler.cpp"
click node_sockets "https://github.com/ahmadmnsur/42_webserv/blob/main/src/network/SocketManager.cpp"
click node_connections "https://github.com/ahmadmnsur/42_webserv/blob/main/src/network/ConnectionHandler.cpp"
click node_clientdata "https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/ClientData.cpp"
click node_request "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/RequestProcessor.cpp"
click node_factory "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/HttpProcessorFactory.cpp"
click node_httprequest "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/HttpRequest.cpp"
click node_httpresponse "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/HttpResponse.cpp"
click node_get "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/GetHttpProcessor.cpp"
click node_post "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/PostHttpProcessor.cpp"
click node_delete "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/DeleteHttpProcessor.cpp"
click node_cgi "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/IHttpProcessor.cpp"
click node_filehandler "https://github.com/ahmadmnsur/42_webserv/blob/main/src/utils/FileHandler.cpp"
click node_sessionapi "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/SessionApiHandler.cpp"
click node_sessionhandler "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/SessionHandler.cpp"
click node_sessions "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/SessionManager.cpp"
click node_cookieapi "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/CookieApiHandler.cpp"
click node_cookies "https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/CookieManager.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_parser,node_tokenizer,node_validator,node_serverconfig,node_location,node_client toneBlue
class node_entry,node_webserver,node_signals,node_sockets,node_connections,node_clientdata toneAmber
class node_request,node_factory,node_httprequest,node_httpresponse toneMint
class node_get,node_post,node_delete,node_cgi,node_filehandler toneRose
class node_sessionapi,node_sessionhandler,node_sessions,node_cookieapi,node_cookies toneIndigo
```

## Components

### Configuration

- [Config parser](https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigParser.cpp): `src/config/ConfigParser.cpp`
- [Config tokenizer](https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigTokenizer.cpp): `src/config/ConfigTokenizer.cpp`
- [Config validator](https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ConfigValidator.cpp): `src/config/ConfigValidator.cpp`
- [Server settings](https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/ServerConfig.cpp): `src/config/ServerConfig.cpp`
- [Location rules](https://github.com/ahmadmnsur/42_webserv/blob/main/src/config/Location.cpp): `src/config/Location.cpp`

### Server Runtime

- [Server entry](https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/main.cpp): `src/core/main.cpp`
- [Web server](https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/WebServer.cpp): `src/core/WebServer.cpp`
- [Signal handling](https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/SignalHandler.cpp): `src/core/SignalHandler.cpp`
- [Socket manager](https://github.com/ahmadmnsur/42_webserv/blob/main/src/network/SocketManager.cpp): `src/network/SocketManager.cpp`
- [Connection handler](https://github.com/ahmadmnsur/42_webserv/blob/main/src/network/ConnectionHandler.cpp): `src/network/ConnectionHandler.cpp`
- [Client state](https://github.com/ahmadmnsur/42_webserv/blob/main/src/core/ClientData.cpp): `src/core/ClientData.cpp`

### HTTP Processing

- [Request processing](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/RequestProcessor.cpp): `src/http/RequestProcessor.cpp`
- [Processor factory](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/HttpProcessorFactory.cpp): `src/http/HttpProcessorFactory.cpp`
- [HTTP request](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/HttpRequest.cpp): `src/http/HttpRequest.cpp`
- [HTTP response](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/HttpResponse.cpp): `src/http/HttpResponse.cpp`

### File and CGI

- [GET handler](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/GetHttpProcessor.cpp): `src/http/GetHttpProcessor.cpp`
- [POST handler](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/PostHttpProcessor.cpp): `src/http/PostHttpProcessor.cpp`
- [DELETE handler](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/DeleteHttpProcessor.cpp): `src/http/DeleteHttpProcessor.cpp`
- [CGI execution](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/IHttpProcessor.cpp): `src/http/IHttpProcessor.cpp`
- [File operations](https://github.com/ahmadmnsur/42_webserv/blob/main/src/utils/FileHandler.cpp): `src/utils/FileHandler.cpp`

### Sessions and Cookies

- [Session API](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/SessionApiHandler.cpp): `src/http/SessionApiHandler.cpp`
- [Session handling](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/SessionHandler.cpp): `src/http/SessionHandler.cpp`
- [Session store](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/SessionManager.cpp): `src/http/SessionManager.cpp`
- [Cookie API](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/CookieApiHandler.cpp): `src/http/CookieApiHandler.cpp`
- [Cookie handling](https://github.com/ahmadmnsur/42_webserv/blob/main/src/http/CookieManager.cpp): `src/http/CookieManager.cpp`

### Other components

- **HTTP client**

## Connections

- HTTP client → Server entry: sends requests (evidence: `README.md`)
- Server entry → Config parser: parses config (evidence: `src/core/main.cpp`)
- Server entry → Web server: starts server (evidence: `src/core/main.cpp`)
- Config parser → Config tokenizer: uses tokens
- Config parser → Config validator: validates config
- Config parser → Server settings: builds settings
- Config parser → Location rules: builds locations
- Web server → Signal handling: handles shutdown
- Web server → Socket manager: manages sockets
- Web server → Connection handler: dispatches connections
- Connection handler → Client state: tracks clients
- Connection handler → Request processing: processes requests
- Connection handler → HTTP request: parses requests
- Connection handler → HTTP response: sends responses
- Request processing → Processor factory: selects handler
- Processor factory → GET handler: selects GET (evidence: `README.md`)
- Processor factory → POST handler: selects POST (evidence: `README.md`)
- Processor factory → DELETE handler: selects DELETE (evidence: `README.md`)
- GET handler → File operations: serves files (evidence: `README.md`)
- GET handler → CGI execution: runs CGI (evidence: `README.md`)
- POST handler → File operations: handles uploads (evidence: `README.md`)
- Request processing → Session API: routes API
- Request processing → Cookie API: routes API
- Session API → Session store: manages sessions
- Session handling → Session store: manages sessions (evidence: `src/http/SessionHandler.cpp`)
- Session handling → Cookie handling: uses cookies (evidence: `src/http/SessionHandler.cpp`)
- Cookie API → Cookie handling: manages cookies
- Session API → Cookie handling: uses cookies
