# sukalen/mytinywebserver architecture

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

## Overview

myTinyWebserver is a multithreaded, epoll-based HTTP server with static pages, authentication, and a cat-finding game API. The main workflow accepts a client request, parses and routes it, then serves a file or invokes the relevant service; game requests generate or update a session and return a JSON snapshot. The README documents reactor handling, worker threads, connection timeouts, and logging. Sampled sources establish game and authentication behavior; some HTTP dispatch and runtime wiring are inferred from the documented decomposition and partial main excerpt, so uncertain links are omitted.

Main entry points: [`http/http_conn.cpp`](https://github.com/sukalen/mytinywebserver/blob/main/http/http_conn.cpp) (HTTP connection), [`main.cpp`](https://github.com/sukalen/mytinywebserver/blob/main/main.cpp) (Server event loop), [`service/game_service.cpp`](https://github.com/sukalen/mytinywebserver/blob/main/service/game_service.cpp) (Game service), [`service/auth_service.cpp`](https://github.com/sukalen/mytinywebserver/blob/main/service/auth_service.cpp) (Auth service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server runtime"]
  node_main["Server event loop<br/>[main.cpp]"]
  node_workers["Worker pool<br/>[threadpool.h]"]
  node_timers["Connection timers<br/>[lst_timer.h]"]
  node_logging["Logging<br/>[log.cpp]"]
end

subgraph group_http["HTTP handling"]
  node_connection["HTTP connection<br/>[http_conn.cpp]"]
  node_request["Request parser<br/>[http_request.cpp]"]
  node_router["Router<br/>[router.cpp]"]
  node_response["HTTP response<br/>[http_response.cpp]"]
  node_static["Static files"]
  node_authhandler["Auth handling<br/>[http_conn.cpp]"]
  node_gameapi["Game API"]
end

subgraph group_game["Game domain"]
  node_gameservice["Game service<br/>[game_service.cpp]"]
  node_sessions[("Session registry<br/>[game_service.cpp]")]
  node_session["Game session<br/>[game_session.cpp]"]
  node_generator["Level generator"]
  node_rules["Game rules<br/>[game_rule.cpp]"]
end

subgraph group_auth["Authentication and storage"]
  node_authservice["Auth service<br/>[auth_service.cpp]"]
  node_pool["SQL connection pool"]
end

node_client(("Web client"))
node_filesystem["Document root"]
node_mysql[("MySQL database")]

node_client -->|"sends request"| node_main
node_main -->|"initializes connections"| node_connection
node_main -->|"dispatches work"| node_workers
node_main -->|"manages timeouts"| node_timers
node_main -->|"loads users"| node_authservice
node_connection -->|"parses bytes"| node_request
node_connection -->|"resolves route"| node_router
node_connection -->|"loads file"| node_static
node_connection -->|"handles auth"| node_authhandler
node_connection -->|"dispatches API"| node_gameapi
node_connection -->|"builds response"| node_response
node_static -->|"reads file"| node_filesystem
node_gameapi -->|"invokes operation"| node_gameservice
node_gameservice -->|"generates level"| node_generator
node_gameservice -->|"stores and finds"| node_sessions
node_gameservice -->|"updates or reads"| node_session
node_session -->|"validates level"| node_rules
node_authservice -->|"acquires connection"| node_pool
node_pool -->|"queries"| node_mysql
node_authservice -->|"reads and writes users"| node_mysql
node_main -->|"records events"| node_logging

click node_main "https://github.com/sukalen/mytinywebserver/blob/main/main.cpp"
click node_workers "https://github.com/sukalen/mytinywebserver/blob/main/threadpool/threadpool.h"
click node_timers "https://github.com/sukalen/mytinywebserver/blob/main/timer/lst_timer.h"
click node_logging "https://github.com/sukalen/mytinywebserver/blob/main/log/log.cpp"
click node_connection "https://github.com/sukalen/mytinywebserver/blob/main/http/http_conn.cpp"
click node_request "https://github.com/sukalen/mytinywebserver/blob/main/http/http_request.cpp"
click node_router "https://github.com/sukalen/mytinywebserver/blob/main/http/router.cpp"
click node_response "https://github.com/sukalen/mytinywebserver/blob/main/http/http_response.cpp"
click node_static "https://github.com/sukalen/mytinywebserver/blob/main/http/static_file_handler.cpp"
click node_authhandler "https://github.com/sukalen/mytinywebserver/blob/main/http/http_conn.cpp"
click node_gameapi "https://github.com/sukalen/mytinywebserver/blob/main/http/game_api_handler.cpp"
click node_gameservice "https://github.com/sukalen/mytinywebserver/blob/main/service/game_service.cpp"
click node_sessions "https://github.com/sukalen/mytinywebserver/blob/main/service/game_service.cpp"
click node_session "https://github.com/sukalen/mytinywebserver/blob/main/game/game_session.cpp"
click node_generator "https://github.com/sukalen/mytinywebserver/blob/main/game/level_generator.cpp"
click node_rules "https://github.com/sukalen/mytinywebserver/blob/main/game/game_rule.cpp"
click node_authservice "https://github.com/sukalen/mytinywebserver/blob/main/service/auth_service.cpp"
click node_pool "https://github.com/sukalen/mytinywebserver/blob/main/CGImysql/sql_connection_pool.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_workers,node_timers,node_logging,node_client toneBlue
class node_connection,node_request,node_router,node_response,node_static,node_authhandler,node_gameapi,node_mysql toneAmber
class node_gameservice,node_sessions,node_session,node_generator,node_rules toneMint
class node_authservice,node_pool toneRose
class node_filesystem toneIndigo
```

## Components

### Server runtime

- [Server event loop](https://github.com/sukalen/mytinywebserver/blob/main/main.cpp): `main.cpp`
- [Worker pool](https://github.com/sukalen/mytinywebserver/blob/main/threadpool/threadpool.h): `threadpool/threadpool.h`
- [Connection timers](https://github.com/sukalen/mytinywebserver/blob/main/timer/lst_timer.h): `timer/lst_timer.h`
- [Logging](https://github.com/sukalen/mytinywebserver/blob/main/log/log.cpp): `log/log.cpp`

### HTTP handling

- [HTTP connection](https://github.com/sukalen/mytinywebserver/blob/main/http/http_conn.cpp): `http/http_conn.cpp`
- [Request parser](https://github.com/sukalen/mytinywebserver/blob/main/http/http_request.cpp): `http/http_request.cpp`
- [Router](https://github.com/sukalen/mytinywebserver/blob/main/http/router.cpp): `http/router.cpp`
- [HTTP response](https://github.com/sukalen/mytinywebserver/blob/main/http/http_response.cpp): `http/http_response.cpp`
- [Static files](https://github.com/sukalen/mytinywebserver/blob/main/http/static_file_handler.cpp): `http/static_file_handler.cpp`
- [Auth handling](https://github.com/sukalen/mytinywebserver/blob/main/http/http_conn.cpp): `http/http_conn.cpp`
- [Game API](https://github.com/sukalen/mytinywebserver/blob/main/http/game_api_handler.cpp): `http/game_api_handler.cpp`

### Game domain

- [Game service](https://github.com/sukalen/mytinywebserver/blob/main/service/game_service.cpp): `service/game_service.cpp`
- [Session registry](https://github.com/sukalen/mytinywebserver/blob/main/service/game_service.cpp): `service/game_service.cpp`
- [Game session](https://github.com/sukalen/mytinywebserver/blob/main/game/game_session.cpp): `game/game_session.cpp`
- [Level generator](https://github.com/sukalen/mytinywebserver/blob/main/game/level_generator.cpp): `game/level_generator.cpp`
- [Game rules](https://github.com/sukalen/mytinywebserver/blob/main/game/game_rule.cpp): `game/game_rule.cpp`

### Authentication and storage

- [Auth service](https://github.com/sukalen/mytinywebserver/blob/main/service/auth_service.cpp): `service/auth_service.cpp`
- [SQL connection pool](https://github.com/sukalen/mytinywebserver/blob/main/CGImysql/sql_connection_pool.cpp): `CGImysql/sql_connection_pool.cpp`

### Other components

- **Web client**
- **Document root**
- **MySQL database**

## Connections

- Web client → Server event loop: sends request
- Server event loop → HTTP connection: initializes connections
- Server event loop → Worker pool: dispatches work
- Server event loop → Connection timers: manages timeouts
- Server event loop → Auth service: loads users
- HTTP connection → Request parser: parses bytes
- HTTP connection → Router: resolves route
- HTTP connection → Static files: loads file
- HTTP connection → Auth handling: handles auth
- HTTP connection → Game API: dispatches API
- HTTP connection → HTTP response: builds response
- Static files → Document root: reads file
- Game API → Game service: invokes operation
- Game service → Level generator: generates level
- Game service → Session registry: stores and finds
- Game service → Game session: updates or reads
- Game session → Game rules: validates level
- Auth service → SQL connection pool: acquires connection
- SQL connection pool → MySQL database: queries
- Auth service → MySQL database: reads and writes users
- Server event loop → Logging: records events
