# jwf-520/webserver architecture

> Architecture diagram of the GitHub repository jwf-520/webserver, 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/jwf-520/webserver
- Repository: https://github.com/jwf-520/webserver

## Overview

This is a lightweight Linux C++ HTTP/1.1 web server. A client connects to the epoll-based server, which dispatches socket work through the configured Reactor or Proactor model; worker threads process requests and return static-file or registration/login responses. The server also expires inactive connections and records logs, while request workers borrow database connections as needed. The README documents these capabilities; sampled source confirms the dispatch, worker, timer, and connection-pool mechanisms. HTTP and server excerpts are partial, so uncertain internal call details are not expanded.

Main entry points: [`webfile/webserver.cpp`](https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp) (Event Server), [`http/http_conn.cpp`](https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp) (HTTP Connection), [`threadpool/threadpool.h`](https://github.com/jwf-520/webserver/blob/master/threadpool/threadpool.h) (Worker Pool), [`log/log.cpp`](https://github.com/jwf-520/webserver/blob/master/log/log.cpp) (Logging)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server Runtime"]
  node_main["Startup Entry<br/>[main.cpp]"]
  node_config["Runtime Options<br/>[config.cpp]"]
  node_webserver["Event Server<br/>[webserver.cpp]"]
  node_epoll["Epoll Dispatch<br/>[webserver.cpp]"]
  node_threadpool["Worker Pool<br/>[threadpool.h]"]
end

subgraph group_http["HTTP Handling"]
  node_httpconn["HTTP Connection<br/>[http_conn.cpp]"]
  node_parser["Request Parser<br/>[http_conn.cpp]"]
  node_auth["Login And Registration<br/>[http_conn.cpp]"]
  node_response["Response Builder<br/>[http_conn.cpp]"]
  node_staticfiles["Static Web Content"]
end

subgraph group_data["Data Services"]
  node_pool["SQL Connection Pool"]
  node_mysql[("MySQL Database")]
end

subgraph group_operations["Runtime Support"]
  node_sync["Locks And Signals<br/>[locker.h]"]
  node_timer["Idle Connection Timers<br/>[lst_timer.cpp]"]
  node_signalpipe["Signal Pipe<br/>[webserver.cpp]"]
  node_logapi["Logging<br/>[log.cpp]"]
  node_logqueue["Async Log Queue<br/>[block_queue.h]"]
  node_logfile["Log Files<br/>[log.cpp]"]
end

node_client(("Browser Client"))

node_client -->|"connects"| node_webserver
node_main -->|"parses options"| node_config
node_main -->|"initializes and runs"| node_webserver
node_webserver -->|"registers and waits"| node_epoll
node_epoll -->|"delivers events"| node_webserver
node_webserver -->|"queues socket work"| node_threadpool
node_threadpool -->|"coordinates workers"| node_sync
node_threadpool -->|"runs request processing"| node_httpconn
node_httpconn -->|"parses request"| node_parser
node_httpconn -->|"handles POST credentials"| node_auth
node_httpconn -->|"builds response"| node_response
node_response -->|"reads requested resource"| node_staticfiles
node_httpconn -->|"sends HTTP response"| node_client
node_threadpool -->|"borrows connection"| node_pool
node_pool -->|"opens and reuses connections"| node_mysql
node_auth -->|"checks or stores credentials"| node_mysql
node_webserver -->|"adds and adjusts timers"| node_timer
node_webserver -->|"registers signal events"| node_signalpipe
node_signalpipe -->|"notifies event loop"| node_webserver
node_timer -->|"removes expired sockets"| node_epoll
node_webserver -->|"initializes logging"| node_logapi
node_httpconn -->|"records request events"| node_logapi
node_logapi -.->|"queues log entries"| node_logqueue
node_logapi -->|"writes log entries"| node_logfile

click node_main "https://github.com/jwf-520/webserver/blob/master/main.cpp"
click node_config "https://github.com/jwf-520/webserver/blob/master/config/config.cpp"
click node_webserver "https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp"
click node_epoll "https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp"
click node_threadpool "https://github.com/jwf-520/webserver/blob/master/threadpool/threadpool.h"
click node_sync "https://github.com/jwf-520/webserver/blob/master/lock/locker.h"
click node_httpconn "https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp"
click node_parser "https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp"
click node_auth "https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp"
click node_response "https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp"
click node_staticfiles "https://github.com/jwf-520/webserver/tree/master/root"
click node_pool "https://github.com/jwf-520/webserver/blob/master/CGImysql/sql_connection_pool.cpp"
click node_timer "https://github.com/jwf-520/webserver/blob/master/timer/lst_timer.cpp"
click node_signalpipe "https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp"
click node_logapi "https://github.com/jwf-520/webserver/blob/master/log/log.cpp"
click node_logqueue "https://github.com/jwf-520/webserver/blob/master/log/block_queue.h"
click node_logfile "https://github.com/jwf-520/webserver/blob/master/log/log.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_main,node_config,node_webserver,node_epoll,node_threadpool,node_client toneBlue
class node_httpconn,node_parser,node_auth,node_response,node_staticfiles toneAmber
class node_pool,node_mysql toneMint
class node_sync,node_timer,node_signalpipe,node_logapi,node_logqueue,node_logfile toneRose
```

## Components

### Server Runtime

- [Startup Entry](https://github.com/jwf-520/webserver/blob/master/main.cpp): `main.cpp`
- [Runtime Options](https://github.com/jwf-520/webserver/blob/master/config/config.cpp): `config/config.cpp`
- [Event Server](https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp): `webfile/webserver.cpp`
- [Epoll Dispatch](https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp): `webfile/webserver.cpp`
- [Worker Pool](https://github.com/jwf-520/webserver/blob/master/threadpool/threadpool.h): `threadpool/threadpool.h`

### HTTP Handling

- [HTTP Connection](https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp): `http/http_conn.cpp`
- [Request Parser](https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp): `http/http_conn.cpp`
- [Login And Registration](https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp): `http/http_conn.cpp`
- [Response Builder](https://github.com/jwf-520/webserver/blob/master/http/http_conn.cpp): `http/http_conn.cpp`
- [Static Web Content](https://github.com/jwf-520/webserver/tree/master/root): `root`

### Data Services

- [SQL Connection Pool](https://github.com/jwf-520/webserver/blob/master/CGImysql/sql_connection_pool.cpp): `CGImysql/sql_connection_pool.cpp`
- **MySQL Database**

### Runtime Support

- [Locks And Signals](https://github.com/jwf-520/webserver/blob/master/lock/locker.h): `lock/locker.h`
- [Idle Connection Timers](https://github.com/jwf-520/webserver/blob/master/timer/lst_timer.cpp): `timer/lst_timer.cpp`
- [Signal Pipe](https://github.com/jwf-520/webserver/blob/master/webfile/webserver.cpp): `webfile/webserver.cpp`
- [Logging](https://github.com/jwf-520/webserver/blob/master/log/log.cpp): `log/log.cpp`
- [Async Log Queue](https://github.com/jwf-520/webserver/blob/master/log/block_queue.h): `log/block_queue.h`
- [Log Files](https://github.com/jwf-520/webserver/blob/master/log/log.cpp): `log/log.cpp`

### Other components

- **Browser Client**

## Connections

- Browser Client → Event Server: connects
- Startup Entry → Runtime Options: parses options
- Startup Entry → Event Server: initializes and runs
- Event Server → Epoll Dispatch: registers and waits
- Epoll Dispatch → Event Server: delivers events
- Event Server → Worker Pool: queues socket work
- Worker Pool → Locks And Signals: coordinates workers
- Worker Pool → HTTP Connection: runs request processing
- HTTP Connection → Request Parser: parses request
- HTTP Connection → Login And Registration: handles POST credentials
- HTTP Connection → Response Builder: builds response
- Response Builder → Static Web Content: reads requested resource
- HTTP Connection → Browser Client: sends HTTP response
- Worker Pool → SQL Connection Pool: borrows connection
- SQL Connection Pool → MySQL Database: opens and reuses connections
- Login And Registration → MySQL Database: checks or stores credentials
- Event Server → Idle Connection Timers: adds and adjusts timers
- Event Server → Signal Pipe: registers signal events
- Signal Pipe → Event Server: notifies event loop
- Idle Connection Timers → Epoll Dispatch: removes expired sockets
- Event Server → Logging: initializes logging
- HTTP Connection → Logging: records request events
- Logging → Async Log Queue: queues log entries
- Logging → Log Files: writes log entries
