# kj-rollin/httpserver architecture

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

- Interactive diagram: https://gitdiagram.com/kj-rollin/httpserver
- Repository: https://github.com/kj-rollin/httpserver

## Overview

This is a multithreaded C++ HTTP/1.1 server for user registration, login, and job-application file submissions and management. The main workflow accepts a browser request, applies per-IP limiting, dispatches it to a route or static-file handler, and returns a response. Handlers implement authentication, session/CSRF checks, uploads, and application operations, using SQLite for persistent records. The README documents compression, caching, and security features; sampled code supports the cache/compression and session paths, but the handler excerpts are incomplete, so uncertain route wiring is omitted.

Main entry points: [`handlers.h`](https://github.com/kj-rollin/httpserver/blob/main/handlers.h) (Route handlers), [`main.cpp`](https://github.com/kj-rollin/httpserver/blob/main/main.cpp) (Socket server), [`router.h`](https://github.com/kj-rollin/httpserver/blob/main/router.h) (Router), [`cache.h`](https://github.com/kj-rollin/httpserver/blob/main/cache.h) (Static file cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server runtime"]
  node_main["Socket server<br/>[main.cpp]"]
  node_pool["Worker pool<br/>[threadpool.h]"]
  node_limiter["IP rate limiter<br/>[rate_limiter.h]"]
end

subgraph group_web["HTTP handling"]
  node_router["Router<br/>[router.h]"]
  node_handlers["Route handlers<br/>[handlers.h]"]
  node_utils["HTTP utilities<br/>[utils.h]"]
  node_multipart["Multipart parser<br/>[multipart.h]"]
  node_cache["Static file cache<br/>[cache.h]"]
  node_gzip["Gzip compression<br/>[gzip.h]"]
  node_pages["Web pages"]
end

subgraph group_identity["Identity and security"]
  node_sessions["Session manager<br/>[session.h]"]
  node_crypto["Password and tokens<br/>[crypto.h]"]
end

subgraph group_data["Application data"]
  node_database_api["Database wrapper<br/>[database.h]"]
  node_sqlite[("SQLite database")]
  node_uploads[("Uploaded files")]
end

node_browser(("Browser"))

node_browser -->|"sends HTTP"| node_main
node_main -->|"queues request"| node_pool
node_pool -->|"runs client task"| node_main
node_main -->|"parses request"| node_utils
node_main -->|"checks IP"| node_limiter
node_main -->|"dispatches request"| node_router
node_router -->|"dispatches route"| node_handlers
node_router -->|"serves static files"| node_cache
node_cache -->|"compresses content"| node_gzip
node_cache -->|"reads files"| node_pages
node_handlers -->|"parses and formats"| node_utils
node_handlers -->|"validates and creates"| node_sessions
node_handlers -->|"reads and updates"| node_database_api
node_handlers -->|"parses uploads"| node_multipart
node_handlers -->|"writes files"| node_uploads
node_handlers -->|"renders pages"| node_pages
node_database_api -->|"queries"| node_sqlite
node_database_api -->|"hashes passwords"| node_crypto
node_browser -->|"views pages"| node_pages

click node_main "https://github.com/kj-rollin/httpserver/blob/main/main.cpp"
click node_pool "https://github.com/kj-rollin/httpserver/blob/main/threadpool.h"
click node_limiter "https://github.com/kj-rollin/httpserver/blob/main/rate_limiter.h"
click node_router "https://github.com/kj-rollin/httpserver/blob/main/router.h"
click node_handlers "https://github.com/kj-rollin/httpserver/blob/main/handlers.h"
click node_utils "https://github.com/kj-rollin/httpserver/blob/main/utils.h"
click node_multipart "https://github.com/kj-rollin/httpserver/blob/main/multipart.h"
click node_cache "https://github.com/kj-rollin/httpserver/blob/main/cache.h"
click node_gzip "https://github.com/kj-rollin/httpserver/blob/main/gzip.h"
click node_pages "https://github.com/kj-rollin/httpserver/tree/main/www"
click node_sessions "https://github.com/kj-rollin/httpserver/blob/main/session.h"
click node_crypto "https://github.com/kj-rollin/httpserver/blob/main/crypto.h"
click node_database_api "https://github.com/kj-rollin/httpserver/blob/main/database.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_main,node_pool,node_limiter,node_browser toneBlue
class node_router,node_handlers,node_utils,node_multipart,node_cache,node_gzip,node_pages toneAmber
class node_sessions,node_crypto toneMint
class node_database_api,node_sqlite,node_uploads toneRose
```

## Components

### Server runtime

- [Socket server](https://github.com/kj-rollin/httpserver/blob/main/main.cpp): `main.cpp`
- [Worker pool](https://github.com/kj-rollin/httpserver/blob/main/threadpool.h): `threadpool.h`
- [IP rate limiter](https://github.com/kj-rollin/httpserver/blob/main/rate_limiter.h): `rate_limiter.h`

### HTTP handling

- [Router](https://github.com/kj-rollin/httpserver/blob/main/router.h): `router.h`
- [Route handlers](https://github.com/kj-rollin/httpserver/blob/main/handlers.h): `handlers.h`
- [HTTP utilities](https://github.com/kj-rollin/httpserver/blob/main/utils.h): `utils.h`
- [Multipart parser](https://github.com/kj-rollin/httpserver/blob/main/multipart.h): `multipart.h`
- [Static file cache](https://github.com/kj-rollin/httpserver/blob/main/cache.h): `cache.h`
- [Gzip compression](https://github.com/kj-rollin/httpserver/blob/main/gzip.h): `gzip.h`
- [Web pages](https://github.com/kj-rollin/httpserver/tree/main/www): `www`

### Identity and security

- [Session manager](https://github.com/kj-rollin/httpserver/blob/main/session.h): `session.h`
- [Password and tokens](https://github.com/kj-rollin/httpserver/blob/main/crypto.h): `crypto.h`

### Application data

- [Database wrapper](https://github.com/kj-rollin/httpserver/blob/main/database.h): `database.h`
- **SQLite database**
- **Uploaded files**

### Other components

- **Browser**

## Connections

- Browser → Socket server: sends HTTP
- Socket server → Worker pool: queues request
- Worker pool → Socket server: runs client task
- Socket server → HTTP utilities: parses request
- Socket server → IP rate limiter: checks IP
- Socket server → Router: dispatches request
- Router → Route handlers: dispatches route
- Router → Static file cache: serves static files
- Static file cache → Gzip compression: compresses content
- Static file cache → Web pages: reads files
- Route handlers → HTTP utilities: parses and formats
- Route handlers → Session manager: validates and creates
- Route handlers → Database wrapper: reads and updates
- Route handlers → Multipart parser: parses uploads
- Route handlers → Uploaded files: writes files
- Route handlers → Web pages: renders pages
- Database wrapper → SQLite database: queries
- Database wrapper → Password and tokens: hashes passwords
- Browser → Web pages: views pages
