# joewalnes/websocketd architecture

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

- Interactive diagram: https://gitdiagram.com/joewalnes/websocketd
- Repository: https://github.com/joewalnes/websocketd

## Overview

websocketd wraps command-line programs as WebSocket services. Its main workflow is: an operator configures and starts the server; a client connects; the server maps the request to a process, exposes request details through CGI environment variables, and relays messages between WebSocket frames and the process’s standard streams. Separate capabilities include static-file and classic CGI serving, Unix sockets, and the developer console. The README documents the overall workflow; sampled code clarifies configuration, request handling, environment construction, and stream relay, but not every internal dispatch.

Main entry points: [`libwebsocketd/handler.go`](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/handler.go) (WebSocket Handler), [`libwebsocketd/http.go`](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go) (HTTP Server), [`main.go`](https://github.com/joewalnes/websocketd/blob/main/main.go) (Server Runtime), [`config.go`](https://github.com/joewalnes/websocketd/blob/main/config.go) (CLI Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and Configuration"]
  node_config["CLI Configuration<br/>[config.go]"]
  node_flags["Flag Definitions<br/>[cliflags.go]"]
  node_runtime["Server Runtime<br/>[main.go]"]
end

subgraph group_serving["HTTP Serving"]
  node_httpserver["HTTP Server<br/>[http.go]"]
  node_static["Static Files<br/>[http.go]"]
  node_cgi["Classic CGI<br/>[http.go]"]
  node_console["Developer Console<br/>[console.go]"]
end

subgraph group_websocket["WebSocket Sessions"]
  node_wsrequest["WebSocket Handler<br/>[handler.go]"]
  node_mapping["Endpoint Mapping<br/>[handler.go]"]
  node_env["CGI Environment<br/>[env.go]"]
  node_wsendpoint["WebSocket Endpoint"]
end

subgraph group_process["Process Integration"]
  node_launcher["Process Launcher<br/>[launcher.go]"]
  node_processendpoint["Process Endpoint"]
end

node_operator(("Operator"))
node_client(("WebSocket Client"))
node_command["Command Process"]

node_operator -->|"sets options"| node_config
node_config -->|"registers flags"| node_flags
node_operator -->|"starts server"| node_runtime
node_runtime -->|"parses options"| node_config
node_runtime -->|"serves requests"| node_httpserver
node_client -->|"connects"| node_httpserver
node_httpserver -.->|"routes upgrades"| node_wsrequest
node_httpserver -->|"serves files"| node_static
node_httpserver -->|"serves scripts"| node_cgi
node_httpserver -->|"serves console"| node_console
node_wsrequest -->|"maps request"| node_mapping
node_wsrequest -->|"builds variables"| node_env
node_wsrequest -.->|"handles session"| node_wsendpoint
node_wsrequest -->|"starts process"| node_launcher
node_launcher -->|"launches"| node_command
node_wsrequest -.->|"relays session"| node_processendpoint
node_client -->|"sends frames"| node_processendpoint
node_processendpoint -->|"pipes stdin/stdout"| node_command

click node_config "https://github.com/joewalnes/websocketd/blob/main/config.go"
click node_flags "https://github.com/joewalnes/websocketd/blob/main/internal/cliflags/cliflags.go"
click node_runtime "https://github.com/joewalnes/websocketd/blob/main/main.go"
click node_httpserver "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go"
click node_static "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go"
click node_cgi "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go"
click node_console "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/console.go"
click node_wsrequest "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/handler.go"
click node_mapping "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/handler.go"
click node_env "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/env.go"
click node_wsendpoint "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/websocket_endpoint.go"
click node_launcher "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/launcher.go"
click node_processendpoint "https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/process_endpoint.go"

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_config,node_flags,node_runtime,node_client toneBlue
class node_httpserver,node_static,node_cgi,node_console toneAmber
class node_wsrequest,node_mapping,node_env,node_wsendpoint toneMint
class node_launcher,node_processendpoint toneRose
class node_operator,node_command toneIndigo
```

## Components

### Startup and Configuration

- [CLI Configuration](https://github.com/joewalnes/websocketd/blob/main/config.go): `config.go`
- [Flag Definitions](https://github.com/joewalnes/websocketd/blob/main/internal/cliflags/cliflags.go): `internal/cliflags/cliflags.go`
- [Server Runtime](https://github.com/joewalnes/websocketd/blob/main/main.go): `main.go`

### HTTP Serving

- [HTTP Server](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go): `libwebsocketd/http.go`
- [Static Files](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go): `libwebsocketd/http.go`
- [Classic CGI](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/http.go): `libwebsocketd/http.go`
- [Developer Console](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/console.go): `libwebsocketd/console.go`

### WebSocket Sessions

- [WebSocket Handler](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/handler.go): `libwebsocketd/handler.go`
- [Endpoint Mapping](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/handler.go): `libwebsocketd/handler.go`
- [CGI Environment](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/env.go): `libwebsocketd/env.go`
- [WebSocket Endpoint](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/websocket_endpoint.go): `libwebsocketd/websocket_endpoint.go`

### Process Integration

- [Process Launcher](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/launcher.go): `libwebsocketd/launcher.go`
- [Process Endpoint](https://github.com/joewalnes/websocketd/blob/main/libwebsocketd/process_endpoint.go): `libwebsocketd/process_endpoint.go`

### Other components

- **Operator**
- **WebSocket Client**
- **Command Process**

## Connections

- Operator → CLI Configuration: sets options (evidence: `README.md`)
- CLI Configuration → Flag Definitions: registers flags (evidence: `config.go`)
- Operator → Server Runtime: starts server (evidence: `README.md`)
- Server Runtime → CLI Configuration: parses options (evidence: `main.go`)
- Server Runtime → HTTP Server: serves requests (evidence: `README.md`)
- WebSocket Client → HTTP Server: connects (evidence: `README.md`)
- HTTP Server → WebSocket Handler: routes upgrades
- HTTP Server → Static Files: serves files (evidence: `README.md`)
- HTTP Server → Classic CGI: serves scripts (evidence: `README.md`)
- HTTP Server → Developer Console: serves console (evidence: `README.md`)
- WebSocket Handler → Endpoint Mapping: maps request (evidence: `libwebsocketd/handler.go`)
- WebSocket Handler → CGI Environment: builds variables (evidence: `libwebsocketd/env.go`)
- WebSocket Handler → WebSocket Endpoint: handles session
- WebSocket Handler → Process Launcher: starts process (evidence: `README.md`)
- Process Launcher → Command Process: launches (evidence: `README.md`)
- WebSocket Handler → Process Endpoint: relays session
- WebSocket Client → Process Endpoint: sends frames (evidence: `README.md`)
- Process Endpoint → Command Process: pipes stdin/stdout (evidence: `README.md`)
