# syloe1/reactornet architecture

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

- Interactive diagram: https://gitdiagram.com/syloe1/reactornet
- Repository: https://github.com/syloe1/reactornet

## Overview

ReactorNet is a Linux C++ networking library. Its principal workflow accepts a client connection on a base reactor, assigns it to a worker loop, processes socket events and buffered data there, and invokes application callbacks to produce a response. The README also documents timer scheduling and an HTTP/1.1 static-file server with URL decoding and traversal protection. Core reactor and server wiring is supported by sampled source; HTTP handler details are based on README capabilities and the example path, whose source was not sampled.

Main entry points: [`src/EventLoop.cpp`](https://github.com/syloe1/reactornet/blob/dev/src/EventLoop.cpp) (Event loop), [`src/TcpServer.cpp`](https://github.com/syloe1/reactornet/blob/dev/src/TcpServer.cpp) (TCP server), [`src/TcpConnection.cpp`](https://github.com/syloe1/reactornet/blob/dev/src/TcpConnection.cpp) (TCP connection), [`example/http_server.cpp`](https://github.com/syloe1/reactornet/blob/dev/example/http_server.cpp) (HTTP server example)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server lifecycle"]
  node_tcpserver["TCP server<br/>[TcpServer.cpp]"]
  node_acceptor["Acceptor<br/>[Acceptor.cpp]"]
  node_thread["Loop threads"]
end

subgraph group_reactor["Reactor core"]
  node_loop["Event loop<br/>[EventLoop.cpp]"]
  node_poller["Epoll poller<br/>[EPollPoller.cpp]"]
  node_channel["Event channel<br/>[Channel.cpp]"]
  node_timerqueue["Timer queue<br/>[TimerQueue.cpp]"]
  node_timer["Timer callbacks<br/>[Timer.h]"]
end

subgraph group_connection["TCP connection"]
  node_connection["TCP connection<br/>[TcpConnection.cpp]"]
  node_buffer["I/O buffer<br/>[Buffer.cpp]"]
  node_socket["Socket wrapper<br/>[Socket.cpp]"]
  node_address["IP address<br/>[InetAddress.cpp]"]
end

subgraph group_http["HTTP serving"]
  node_http_example["HTTP server example<br/>[http_server.cpp]"]
  node_request["HTTP request parser<br/>[HttpRequest.cpp]"]
  node_response["HTTP response builder<br/>[HttpResponse.cpp]"]
  node_www["Static documents<br/>[index.html]"]
end

node_client(("TCP client"))

node_client -->|"opens connection"| node_acceptor
node_tcpserver -->|"configures accept"| node_acceptor
node_acceptor -->|"reports accepted socket"| node_tcpserver
node_tcpserver -->|"starts workers"| node_thread
node_tcpserver -->|"creates connection"| node_connection
node_tcpserver -->|"dispatches connection"| node_loop
node_connection -->|"registers events"| node_loop
node_loop -->|"polls events"| node_poller
node_poller -->|"returns ready channels"| node_loop
node_loop -->|"dispatches events"| node_channel
node_channel -->|"updates interests"| node_loop
node_connection -->|"reads and writes"| node_buffer
node_connection -->|"owns socket"| node_socket
node_connection -->|"stores endpoints"| node_address
node_loop -->|"drives timers"| node_timerqueue
node_timerqueue -->|"runs callbacks"| node_timer
node_timerqueue -->|"registers timerfd"| node_channel
node_http_example -->|"configures server"| node_tcpserver
node_http_example -->|"parses requests"| node_request
node_http_example -->|"builds responses"| node_response
node_http_example -->|"serves documents"| node_www
node_client -->|"requests content"| node_http_example

click node_tcpserver "https://github.com/syloe1/reactornet/blob/dev/src/TcpServer.cpp"
click node_acceptor "https://github.com/syloe1/reactornet/blob/dev/src/Acceptor.cpp"
click node_thread "https://github.com/syloe1/reactornet/blob/dev/src/EventLoopThread.cpp"
click node_loop "https://github.com/syloe1/reactornet/blob/dev/src/EventLoop.cpp"
click node_poller "https://github.com/syloe1/reactornet/blob/dev/src/EPollPoller.cpp"
click node_channel "https://github.com/syloe1/reactornet/blob/dev/src/Channel.cpp"
click node_timerqueue "https://github.com/syloe1/reactornet/blob/dev/src/TimerQueue.cpp"
click node_timer "https://github.com/syloe1/reactornet/blob/dev/include/Timer.h"
click node_connection "https://github.com/syloe1/reactornet/blob/dev/src/TcpConnection.cpp"
click node_buffer "https://github.com/syloe1/reactornet/blob/dev/src/Buffer.cpp"
click node_socket "https://github.com/syloe1/reactornet/blob/dev/src/Socket.cpp"
click node_address "https://github.com/syloe1/reactornet/blob/dev/src/InetAddress.cpp"
click node_http_example "https://github.com/syloe1/reactornet/blob/dev/example/http_server.cpp"
click node_request "https://github.com/syloe1/reactornet/blob/dev/src/HttpRequest.cpp"
click node_response "https://github.com/syloe1/reactornet/blob/dev/src/HttpResponse.cpp"
click node_www "https://github.com/syloe1/reactornet/blob/dev/www/index.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_tcpserver,node_acceptor,node_thread,node_client toneBlue
class node_loop,node_poller,node_channel,node_timerqueue,node_timer toneAmber
class node_connection,node_buffer,node_socket,node_address toneMint
class node_http_example,node_request,node_response,node_www toneRose
```

## Components

### Server lifecycle

- [TCP server](https://github.com/syloe1/reactornet/blob/dev/src/TcpServer.cpp): `src/TcpServer.cpp`
- [Acceptor](https://github.com/syloe1/reactornet/blob/dev/src/Acceptor.cpp): `src/Acceptor.cpp`
- [Loop threads](https://github.com/syloe1/reactornet/blob/dev/src/EventLoopThread.cpp): `src/EventLoopThread.cpp`

### Reactor core

- [Event loop](https://github.com/syloe1/reactornet/blob/dev/src/EventLoop.cpp): `src/EventLoop.cpp`
- [Epoll poller](https://github.com/syloe1/reactornet/blob/dev/src/EPollPoller.cpp): `src/EPollPoller.cpp`
- [Event channel](https://github.com/syloe1/reactornet/blob/dev/src/Channel.cpp): `src/Channel.cpp`
- [Timer queue](https://github.com/syloe1/reactornet/blob/dev/src/TimerQueue.cpp): `src/TimerQueue.cpp`
- [Timer callbacks](https://github.com/syloe1/reactornet/blob/dev/include/Timer.h): `include/Timer.h`

### TCP connection

- [TCP connection](https://github.com/syloe1/reactornet/blob/dev/src/TcpConnection.cpp): `src/TcpConnection.cpp`
- [I/O buffer](https://github.com/syloe1/reactornet/blob/dev/src/Buffer.cpp): `src/Buffer.cpp`
- [Socket wrapper](https://github.com/syloe1/reactornet/blob/dev/src/Socket.cpp): `src/Socket.cpp`
- [IP address](https://github.com/syloe1/reactornet/blob/dev/src/InetAddress.cpp): `src/InetAddress.cpp`

### HTTP serving

- [HTTP server example](https://github.com/syloe1/reactornet/blob/dev/example/http_server.cpp): `example/http_server.cpp`
- [HTTP request parser](https://github.com/syloe1/reactornet/blob/dev/src/HttpRequest.cpp): `src/HttpRequest.cpp`
- [HTTP response builder](https://github.com/syloe1/reactornet/blob/dev/src/HttpResponse.cpp): `src/HttpResponse.cpp`
- [Static documents](https://github.com/syloe1/reactornet/blob/dev/www/index.html): `www/index.html`

### Other components

- **TCP client**

## Connections

- TCP client → Acceptor: opens connection
- TCP server → Acceptor: configures accept
- Acceptor → TCP server: reports accepted socket
- TCP server → Loop threads: starts workers
- TCP server → TCP connection: creates connection
- TCP server → Event loop: dispatches connection
- TCP connection → Event loop: registers events
- Event loop → Epoll poller: polls events
- Epoll poller → Event loop: returns ready channels
- Event loop → Event channel: dispatches events
- Event channel → Event loop: updates interests
- TCP connection → I/O buffer: reads and writes
- TCP connection → Socket wrapper: owns socket
- TCP connection → IP address: stores endpoints
- Event loop → Timer queue: drives timers
- Timer queue → Timer callbacks: runs callbacks
- Timer queue → Event channel: registers timerfd
- HTTP server example → TCP server: configures server
- HTTP server example → HTTP request parser: parses requests
- HTTP server example → HTTP response builder: builds responses
- HTTP server example → Static documents: serves documents
- TCP client → HTTP server example: requests content
