# nassim-hmdii/http_server architecture

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

- Interactive diagram: https://gitdiagram.com/nassim-hmdii/http_server
- Repository: https://github.com/nassim-hmdii/http_server

## Overview

This is a minimal POSIX-socket HTTP server. A client connects to the listener; the server receives and parses one request line, calls the response builder, sends its HTTP response, and closes that client connection. The builder selects the 200, 404, or 405 page and constructs status and headers, with a 500 fallback if a page cannot be opened. The graph reflects the README and shown source; it omits low-level socket calls as separate nodes and does not infer relationships beyond those documented or excerpted.

Main entry points: [`src/http.cpp`](https://github.com/nassim-hmdii/http_server/blob/main/src/http.cpp) (Response builder), [`src/server.cpp`](https://github.com/nassim-hmdii/http_server/blob/main/src/server.cpp) (Socket listener), [`public/200-OK.html`](https://github.com/nassim-hmdii/http_server/blob/main/public/200-OK.html) (200 page), [`public/404-NotFound.html`](https://github.com/nassim-hmdii/http_server/blob/main/public/404-NotFound.html) (404 page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_network["TCP server"]
  node_listener["Socket listener<br/>[server.cpp]"]
  node_parser["Request-line parsing<br/>[server.cpp]"]
end

subgraph group_http["HTTP handling"]
  node_builder["Response builder<br/>[http.cpp]"]
  node_response["HTTP response<br/>[http.cpp]"]
end

subgraph group_pages["Response pages"]
  node_ok["200 page<br/>[200-OK.html]"]
  node_notfound["404 page<br/>[404-NotFound.html]"]
  node_method["405 page"]
end

node_client(("HTTP client"))

node_client -->|"opens connection"| node_listener
node_listener -->|"parses request"| node_parser
node_listener -->|"calls builder"| node_builder
node_builder -->|"reads for GET /"| node_ok
node_builder -->|"reads for other paths"| node_notfound
node_builder -->|"reads for non-GET"| node_method
node_builder -->|"constructs response"| node_response
node_listener -->|"sends response"| node_client

click node_listener "https://github.com/nassim-hmdii/http_server/blob/main/src/server.cpp"
click node_parser "https://github.com/nassim-hmdii/http_server/blob/main/src/server.cpp"
click node_builder "https://github.com/nassim-hmdii/http_server/blob/main/src/http.cpp"
click node_response "https://github.com/nassim-hmdii/http_server/blob/main/src/http.cpp"
click node_ok "https://github.com/nassim-hmdii/http_server/blob/main/public/200-OK.html"
click node_notfound "https://github.com/nassim-hmdii/http_server/blob/main/public/404-NotFound.html"
click node_method "https://github.com/nassim-hmdii/http_server/blob/main/public/405-MethodNotAllowed.html"

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_listener,node_parser,node_client toneBlue
class node_builder,node_response toneAmber
class node_ok,node_notfound,node_method toneMint
```

## Components

### TCP server

- [Socket listener](https://github.com/nassim-hmdii/http_server/blob/main/src/server.cpp): `src/server.cpp`
- [Request-line parsing](https://github.com/nassim-hmdii/http_server/blob/main/src/server.cpp): `src/server.cpp`

### HTTP handling

- [Response builder](https://github.com/nassim-hmdii/http_server/blob/main/src/http.cpp): `src/http.cpp`
- [HTTP response](https://github.com/nassim-hmdii/http_server/blob/main/src/http.cpp): `src/http.cpp`

### Response pages

- [200 page](https://github.com/nassim-hmdii/http_server/blob/main/public/200-OK.html): `public/200-OK.html`
- [404 page](https://github.com/nassim-hmdii/http_server/blob/main/public/404-NotFound.html): `public/404-NotFound.html`
- [405 page](https://github.com/nassim-hmdii/http_server/blob/main/public/405-MethodNotAllowed.html): `public/405-MethodNotAllowed.html`

### Other components

- **HTTP client**

## Connections

- HTTP client → Socket listener: opens connection (evidence: `README.md`)
- Socket listener → Request-line parsing: parses request (evidence: `src/server.cpp`)
- Socket listener → Response builder: calls builder (evidence: `src/server.cpp`)
- Response builder → 200 page: reads for GET / (evidence: `README.md`)
- Response builder → 404 page: reads for other paths (evidence: `README.md`)
- Response builder → 405 page: reads for non-GET (evidence: `README.md`)
- Response builder → HTTP response: constructs response (evidence: `src/http.cpp`)
- Socket listener → HTTP client: sends response (evidence: `README.md`)
