# lanqi1796-eng/cpp-reactor-http-server architecture

> Architecture diagram of the GitHub repository lanqi1796-eng/cpp-reactor-http-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lanqi1796-eng/cpp-reactor-http-server
- Repository: https://github.com/lanqi1796-eng/cpp-reactor-http-server

## Overview

This is a learning-oriented C++17 HTTP/1.1 server. A client connection enters through the server’s listening socket; the EventLoop and Connection handle nonblocking I/O, the server parses and routes requests, then returns serialized responses. GET requests use static files; POST /echo is processed by a worker and handed back to the EventLoop for sending. The graph preserves the reactor, parsing, response, static-file, and worker-pool layers. Some links rely on README documentation because source excerpts omit wiring details.

Main entry points: [`TcpServer.cpp`](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TcpServer.cpp) (TCP server), [`Connection.cpp`](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/Connection.cpp) (Connection I/O), [`EventLoop.cpp`](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/EventLoop.cpp) (Event loop), [`StaticFileHandler.cpp`](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/StaticFileHandler.cpp) (Static files)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server and routing"]
  node_tcp_server["TCP server<br/>[TcpServer.cpp]"]
  node_echo_logic["Echo processing<br/>[TcpServer.cpp]"]
end

subgraph group_reactor["Reactor and sockets"]
  node_event_loop["Event loop<br/>[EventLoop.cpp]"]
  node_channel["FD channel<br/>[Channel.cpp]"]
  node_connection["Connection I/O<br/>[Connection.cpp]"]
  node_socket_wrappers["Socket wrappers<br/>[wrap.cpp]"]
end

subgraph group_http["HTTP handling"]
  node_http_request["Request parser<br/>[HttpRequest.cpp]"]
  node_http_response["Response serializer<br/>[HttpResponse.cpp]"]
  node_static_handler["Static files"]
  node_www_assets["Web assets<br/>[index.html]"]
end

subgraph group_workers["Async workers"]
  node_thread_pool["Thread pool<br/>[ThreadPool.h]"]
  node_task_queue["Task queue<br/>[TaskQueue.h]"]
end

node_client(("HTTP client"))

node_client -->|"opens connection"| node_tcp_server
node_tcp_server -->|"creates listener"| node_socket_wrappers
node_tcp_server -->|"registers listener"| node_event_loop
node_event_loop -->|"dispatches events"| node_channel
node_tcp_server -->|"creates connection"| node_connection
node_connection -->|"configures events"| node_channel
node_connection -->|"uses socket I/O"| node_socket_wrappers
node_connection -->|"queues callbacks"| node_event_loop
node_tcp_server -->|"parses requests"| node_http_request
node_tcp_server -->|"routes GET"| node_static_handler
node_static_handler -->|"reads files"| node_www_assets
node_static_handler -->|"sets response"| node_http_response
node_tcp_server -->|"serializes replies"| node_http_response
node_tcp_server -->|"submits echo task"| node_thread_pool
node_thread_pool -->|"queues tasks"| node_task_queue
node_thread_pool -->|"runs task"| node_echo_logic
node_echo_logic -->|"queues result"| node_event_loop
node_connection -->|"sends response"| node_client

click node_tcp_server "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TcpServer.cpp"
click node_echo_logic "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TcpServer.cpp"
click node_event_loop "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/EventLoop.cpp"
click node_channel "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/Channel.cpp"
click node_connection "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/Connection.cpp"
click node_socket_wrappers "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/wrap.cpp"
click node_http_request "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/HttpRequest.cpp"
click node_http_response "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/HttpResponse.cpp"
click node_static_handler "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/StaticFileHandler.cpp"
click node_www_assets "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/www/index.html"
click node_thread_pool "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/ThreadPool.h"
click node_task_queue "https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TaskQueue.h"

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_tcp_server,node_echo_logic,node_client toneBlue
class node_event_loop,node_channel,node_connection,node_socket_wrappers toneAmber
class node_http_request,node_http_response,node_static_handler,node_www_assets toneMint
class node_thread_pool,node_task_queue toneRose
```

## Components

### Server and routing

- [TCP server](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TcpServer.cpp): `TcpServer.cpp`
- [Echo processing](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TcpServer.cpp): `TcpServer.cpp`

### Reactor and sockets

- [Event loop](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/EventLoop.cpp): `EventLoop.cpp`
- [FD channel](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/Channel.cpp): `Channel.cpp`
- [Connection I/O](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/Connection.cpp): `Connection.cpp`
- [Socket wrappers](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/wrap.cpp): `wrap.cpp`

### HTTP handling

- [Request parser](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/HttpRequest.cpp): `HttpRequest.cpp`
- [Response serializer](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/HttpResponse.cpp): `HttpResponse.cpp`
- [Static files](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/StaticFileHandler.cpp): `StaticFileHandler.cpp`
- [Web assets](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/www/index.html): `www/index.html`

### Async workers

- [Thread pool](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/ThreadPool.h): `ThreadPool.h`
- [Task queue](https://github.com/lanqi1796-eng/cpp-reactor-http-server/blob/main/TaskQueue.h): `TaskQueue.h`

### Other components

- **HTTP client**

## Connections

- HTTP client → TCP server: opens connection (evidence: `README.md`)
- TCP server → Socket wrappers: creates listener (evidence: `TcpServer.cpp`)
- TCP server → Event loop: registers listener (evidence: `TcpServer.cpp`)
- Event loop → FD channel: dispatches events (evidence: `README.md`)
- TCP server → Connection I/O: creates connection (evidence: `TcpServer.cpp`)
- Connection I/O → FD channel: configures events
- Connection I/O → Socket wrappers: uses socket I/O
- Connection I/O → Event loop: queues callbacks (evidence: `README.md`)
- TCP server → Request parser: parses requests (evidence: `TcpServer.cpp`)
- TCP server → Static files: routes GET (evidence: `TcpServer.cpp`)
- Static files → Web assets: reads files (evidence: `README.md`)
- Static files → Response serializer: sets response
- TCP server → Response serializer: serializes replies (evidence: `TcpServer.cpp`)
- TCP server → Thread pool: submits echo task (evidence: `TcpServer.cpp`)
- Thread pool → Task queue: queues tasks (evidence: `ThreadPool.h`)
- Thread pool → Echo processing: runs task (evidence: `README.md`)
- Echo processing → Event loop: queues result (evidence: `TcpServer.cpp`)
- Connection I/O → HTTP client: sends response (evidence: `README.md`)
