# ezlippi/tinyhttpd architecture

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

- Interactive diagram: https://gitdiagram.com/ezlippi/tinyhttpd
- Repository: https://github.com/ezlippi/tinyhttpd

## Overview

This repository is a small educational HTTP server. Its main workflow accepts HTTP requests, parses and routes them to either static-file serving or CGI execution, then returns a response to the client. The README documents additional error responses and CGI behavior; the source excerpt is partial, so uncertain lower-level call wiring is omitted.

Main entry points: [`httpd.c`](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c) (Request routing), [`htdocs`](https://github.com/ezlippi/tinyhttpd/tree/master/htdocs) (Document root)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["HTTP server"]
  node_main["Server main loop<br/>[httpd.c]"]
  node_startup["Socket startup<br/>[httpd.c]"]
  node_request["Request routing<br/>[httpd.c]"]
  node_line["Socket line reader<br/>[httpd.c]"]
end

subgraph group_responses["Response handling"]
  node_static["Static file handler<br/>[httpd.c]"]
  node_cat["File output<br/>[httpd.c]"]
  node_errors["HTTP error responses<br/>[httpd.c]"]
  node_content["Document root"]
end

subgraph group_cgi["CGI execution"]
  node_cgi_exec["CGI process runner<br/>[httpd.c]"]
  node_scripts["CGI examples"]
end

node_browser(("HTTP client"))
node_perl["Perl CGI runtime"]

node_main -->|"starts listener"| node_startup
node_browser -->|"sends request"| node_main
node_main -->|"dispatches request"| node_request
node_request -->|"reads request lines"| node_line
node_request -->|"serves static request"| node_static
node_request -->|"runs CGI request"| node_cgi_exec
node_request -->|"reports request errors"| node_errors
node_static -->|"opens requested file"| node_content
node_static -->|"writes file contents"| node_cat
node_cat -->|"sends file response"| node_browser
node_cgi_exec -->|"executes script"| node_scripts
node_cgi_exec -.->|"invokes CGI runtime"| node_perl
node_cgi_exec -->|"forwards CGI output"| node_browser
node_errors -->|"sends error response"| node_browser

click node_main "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_startup "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_request "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_line "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_static "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_cat "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_errors "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_cgi_exec "https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c"
click node_scripts "https://github.com/ezlippi/tinyhttpd/tree/master/htdocs"
click node_content "https://github.com/ezlippi/tinyhttpd/tree/master/htdocs"

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_startup,node_request,node_line,node_browser toneBlue
class node_static,node_cat,node_errors,node_content toneAmber
class node_cgi_exec,node_scripts toneMint
class node_perl toneIndigo
```

## Components

### HTTP server

- [Server main loop](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [Socket startup](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [Request routing](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [Socket line reader](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`

### Response handling

- [Static file handler](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [File output](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [HTTP error responses](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [Document root](https://github.com/ezlippi/tinyhttpd/tree/master/htdocs): `htdocs`

### CGI execution

- [CGI process runner](https://github.com/ezlippi/tinyhttpd/blob/master/httpd.c): `httpd.c`
- [CGI examples](https://github.com/ezlippi/tinyhttpd/tree/master/htdocs): `htdocs`

### Other components

- **HTTP client**
- **Perl CGI runtime**

## Connections

- Server main loop → Socket startup: starts listener
- HTTP client → Server main loop: sends request
- Server main loop → Request routing: dispatches request
- Request routing → Socket line reader: reads request lines
- Request routing → Static file handler: serves static request
- Request routing → CGI process runner: runs CGI request
- Request routing → HTTP error responses: reports request errors
- Static file handler → Document root: opens requested file
- Static file handler → File output: writes file contents
- File output → HTTP client: sends file response
- CGI process runner → CGI examples: executes script
- CGI process runner → Perl CGI runtime: invokes CGI runtime
- CGI process runner → HTTP client: forwards CGI output
- HTTP error responses → HTTP client: sends error response
