# nhmikami/42-webserv architecture

> Architecture diagram of the GitHub repository nhmikami/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/nhmikami/42-webserv
- Repository: https://github.com/nhmikami/42-webserv

## Overview

Webserv is a C++98 HTTP/1.1 server. Its principal workflow is to load server configuration, accept non-blocking client connections through a poll-based loop, parse and validate requests, route them to method handling or CGI, build responses, and write them back. The graph also preserves documented static-file, directory-listing, upload, error-page, virtual-server, and session/cookie capabilities. Relationships are based on the README’s architecture and feature descriptions plus the sampled declarations; implementation-level wiring is not fully shown.

Main entry points: [`src/server/Server.cpp`](https://github.com/nhmikami/42-webserv/blob/main/src/server/Server.cpp) (Poll server), [`src/parse/ParseHttp.cpp`](https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseHttp.cpp) (HTTP parser), [`src/server/Client.cpp`](https://github.com/nhmikami/42-webserv/blob/main/src/server/Client.cpp) (Client connection), [`src/http/AMethod.cpp`](https://github.com/nhmikami/42-webserv/blob/main/src/http/AMethod.cpp) (GET POST DELETE)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["Poll server<br/>[Server.cpp]"]
  node_client["Client connection<br/>[Client.cpp]"]
end

subgraph group_http["HTTP handling"]
  node_request_parser["HTTP parser<br/>[ParseHttp.cpp]"]
  node_header_validator["Header validation"]
  node_uri_parser["URI parsing<br/>[ParseUri.cpp]"]
  node_cookie_parser["Cookie parsing<br/>[ParseCookie.cpp]"]
  node_request["HTTP request<br/>[Request.cpp]"]
  node_method_handlers["GET POST DELETE<br/>[AMethod.cpp]"]
  node_response["HTTP response<br/>[Response.cpp]"]
end

subgraph group_config["Configuration"]
  node_config_parser["Config parser<br/>[ParseConfig.cpp]"]
  node_server_config["Virtual server config<br/>[ServerConfig.cpp]"]
  node_location_config["Location config<br/>[LocationConfig.cpp]"]
end

subgraph group_features["Response features"]
  node_file_serving["Files and listings<br/>[FileUtils.cpp]"]
  node_cgi["CGI execution<br/>[CgiHandler.cpp]"]
  node_session_manager[("Session manager<br/>[SessionManager.cpp]")]
  node_session[("Session state<br/>[Session.cpp]")]
end

node_operator(("Server operator"))
node_external_scripts["CGI scripts"]

node_operator -->|"provides config"| node_config_parser
node_config_parser -->|"configures"| node_server
node_server -->|"accepts clients"| node_client
node_client -->|"feeds request data"| node_request_parser
node_request_parser -.->|"validates headers"| node_header_validator
node_request_parser -.->|"parses target"| node_uri_parser
node_request_parser -.->|"parses cookies"| node_cookie_parser
node_request_parser -.->|"builds request"| node_request
node_server -.->|"selects config"| node_server_config
node_server_config -->|"defines locations"| node_location_config
node_server -->|"routes methods"| node_method_handlers
node_server -->|"dispatches CGI"| node_cgi
node_cgi -->|"executes scripts"| node_external_scripts
node_server -->|"builds response"| node_response
node_method_handlers -.->|"serves files"| node_file_serving
node_response -->|"writes to socket"| node_client
node_server -->|"manages sessions"| node_session_manager
node_session_manager -->|"stores sessions"| node_session

click node_config_parser "https://github.com/nhmikami/42-webserv/blob/main/src/config/ParseConfig.cpp"
click node_server_config "https://github.com/nhmikami/42-webserv/blob/main/src/config/ServerConfig.cpp"
click node_location_config "https://github.com/nhmikami/42-webserv/blob/main/src/config/LocationConfig.cpp"
click node_server "https://github.com/nhmikami/42-webserv/blob/main/src/server/Server.cpp"
click node_client "https://github.com/nhmikami/42-webserv/blob/main/src/server/Client.cpp"
click node_request_parser "https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseHttp.cpp"
click node_header_validator "https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseHttpValidator.cpp"
click node_uri_parser "https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseUri.cpp"
click node_cookie_parser "https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseCookie.cpp"
click node_request "https://github.com/nhmikami/42-webserv/blob/main/src/http/Request.cpp"
click node_method_handlers "https://github.com/nhmikami/42-webserv/blob/main/src/http/AMethod.cpp"
click node_response "https://github.com/nhmikami/42-webserv/blob/main/src/http/Response.cpp"
click node_file_serving "https://github.com/nhmikami/42-webserv/blob/main/src/utils/FileUtils.cpp"
click node_cgi "https://github.com/nhmikami/42-webserv/blob/main/src/server/CgiHandler.cpp"
click node_session_manager "https://github.com/nhmikami/42-webserv/blob/main/src/server/SessionManager.cpp"
click node_session "https://github.com/nhmikami/42-webserv/blob/main/src/server/Session.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_server,node_client toneBlue
class node_request_parser,node_header_validator,node_uri_parser,node_cookie_parser,node_request,node_method_handlers,node_response toneAmber
class node_config_parser,node_server_config,node_location_config,node_operator toneMint
class node_file_serving,node_cgi,node_session_manager,node_session toneRose
class node_external_scripts toneIndigo
```

## Components

### Server runtime

- [Poll server](https://github.com/nhmikami/42-webserv/blob/main/src/server/Server.cpp): `src/server/Server.cpp`
- [Client connection](https://github.com/nhmikami/42-webserv/blob/main/src/server/Client.cpp): `src/server/Client.cpp`

### HTTP handling

- [HTTP parser](https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseHttp.cpp): `src/parse/ParseHttp.cpp`
- [Header validation](https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseHttpValidator.cpp): `src/parse/ParseHttpValidator.cpp`
- [URI parsing](https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseUri.cpp): `src/parse/ParseUri.cpp`
- [Cookie parsing](https://github.com/nhmikami/42-webserv/blob/main/src/parse/ParseCookie.cpp): `src/parse/ParseCookie.cpp`
- [HTTP request](https://github.com/nhmikami/42-webserv/blob/main/src/http/Request.cpp): `src/http/Request.cpp`
- [GET POST DELETE](https://github.com/nhmikami/42-webserv/blob/main/src/http/AMethod.cpp): `src/http/AMethod.cpp`
- [HTTP response](https://github.com/nhmikami/42-webserv/blob/main/src/http/Response.cpp): `src/http/Response.cpp`

### Configuration

- [Config parser](https://github.com/nhmikami/42-webserv/blob/main/src/config/ParseConfig.cpp): `src/config/ParseConfig.cpp`
- [Virtual server config](https://github.com/nhmikami/42-webserv/blob/main/src/config/ServerConfig.cpp): `src/config/ServerConfig.cpp`
- [Location config](https://github.com/nhmikami/42-webserv/blob/main/src/config/LocationConfig.cpp): `src/config/LocationConfig.cpp`

### Response features

- [Files and listings](https://github.com/nhmikami/42-webserv/blob/main/src/utils/FileUtils.cpp): `src/utils/FileUtils.cpp`
- [CGI execution](https://github.com/nhmikami/42-webserv/blob/main/src/server/CgiHandler.cpp): `src/server/CgiHandler.cpp`
- [Session manager](https://github.com/nhmikami/42-webserv/blob/main/src/server/SessionManager.cpp): `src/server/SessionManager.cpp`
- [Session state](https://github.com/nhmikami/42-webserv/blob/main/src/server/Session.cpp): `src/server/Session.cpp`

### Other components

- **Server operator**
- **CGI scripts**

## Connections

- Server operator → Config parser: provides config
- Config parser → Poll server: configures
- Poll server → Client connection: accepts clients
- Client connection → HTTP parser: feeds request data
- HTTP parser → Header validation: validates headers
- HTTP parser → URI parsing: parses target
- HTTP parser → Cookie parsing: parses cookies
- HTTP parser → HTTP request: builds request
- Poll server → Virtual server config: selects config
- Virtual server config → Location config: defines locations
- Poll server → GET POST DELETE: routes methods
- Poll server → CGI execution: dispatches CGI
- CGI execution → CGI scripts: executes scripts
- Poll server → HTTP response: builds response
- GET POST DELETE → Files and listings: serves files
- HTTP response → Client connection: writes to socket
- Poll server → Session manager: manages sessions
- Session manager → Session state: stores sessions
