# zr-jb/graphite-meter architecture

> Architecture diagram of the GitHub repository zr-jb/graphite-meter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zr-jb/graphite-meter
- Repository: https://github.com/zr-jb/graphite-meter

## Overview

#### Purpose and Entry Points
Graphite Meter is a self-hosted internet speed-test system: a static Go server embeds a Svelte browser client, while a separate Go terminal client runs the same measurement protocol. Server entry point: `go/cmd/graphite-meter/main.go`; TUI entry point: `go/cmd/graphite-meter-client/main.go`; browser bootstrap: `client/src/main.ts` and `client/src/App.svelte`.

#### Server Composition and Admission
The Go server configures native HTTP/1.1, HTTP/2, HTTP/3/QUIC listeners, routing, TLS, connection admission, and protocol-aware access control. It is the authoritative boundary for advertised endpoint capabilities and load limits.
- `go/internal/server/listeners.go`
- `go/internal/server/admission.go`
- `go/internal/config/config.go`

#### Measurement Endpoint Layer
Server endpoints implement preflight/probe discovery, download byte production, upload receipt/progress accounting, ping, and WebTransport sessions. Upload results deliberately originate from server-observed bytes rather than client-side sent-byte estimates.
- `go/internal/endpoint/registry.go`
- `go/internal/endpoint/meter.go`
- `go/internal/endpoint/upload.go`

#### Transport and Wire-Protocol Boundary
HTTP streaming, WebSocket, QUIC, and WebTransport are normalized behind session/transport abstractions. A shared framed wire protocol supports transport-independent control and measurement traffic, particularly WebTransport operation.
- `go/internal/transport/session.go`
- `go/internal/transport/webtransport_session.go`
- `go/internal/wire/frame.go`

The contract is externally specified under `api/`, including route and preflight/probe schemas: `api/wire.md`, `api/preflight.schema.json`, `api/routes.txt`.

#### Authentication and Static Delivery
Optional password and OIDC authentication wraps assets and all measurement transports, with sessions, authorization policy, device/CLI approval flows, and WebTransport-specific enforcement. The browser distribution is built separately then embedded in the server binary.
- `go/internal/auth/service.go`
- `go/internal/auth/oidc.go`
- `go/internal/static/embed.go`

#### Browser Measurement Engine
The Svelte client owns setup, stage state, persistence, adaptive stopping, rate/latency aggregation, and presentation state. `engine.svelte.ts` coordinates the runner lifecycle; real and dummy runners satisfy the runner contract. Workers isolate concurrent download/upload/ping operations and provide rolling progress/RTT estimates.
- `client/src/lib/runner/engine.svelte.ts`
- `client/src/lib/runner/RealRunner.ts`
- `client/src/lib/runner/workers/download-worker.ts`

Flow: UI settings and selected paths → preflight/probe APIs → runner schedules latency, download, upload, and bidirectional stages → transport workers emit samples/progress → stats/evaluation decide stability/completion → state and visualization update. Browser API adapters live at `client/src/lib/api/preflight.ts` and `client/src/lib/api/probe.ts`.

#### Client UI and Visualization
The application presents endpoint/path availability, live transport status, results, latency-under-load, and canvas-based throughput/gauge rendering. UI components consume runner/state outputs rather than owning transport logic.
- `client/src/lib/state/store.svelte.ts`
- `client/src/lib/canvas/ChartEngine.ts`
- `client/src/lib/components/ThroughputChart.svelte`

#### Native TUI and Deployment
The native client uses `go/internal/goclient` to execute the same server contract and transports, then renders an interactive terminal lifecycle. Builds target a static binary and `scratch` OCI image; Compose and Quadlet support direct, TLS, authenticated, Let’s Encrypt/Cloudflare, and Tailscale deployments.
- `go/internal/goclient/runner.go`
- `go/cmd/graphite-meter-client/runlifecycle.go`
- `container/Dockerfile`

Main entry points: [`go/internal/endpoint/registry.go`](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/registry.go) (Measurement endpoints), [`go/internal/server/listeners.go`](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/server/listeners.go) (Listeners and admission), [`go/internal/goclient/runner.go`](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/goclient/runner.go) (Native measurement runner), [`api/wire.md`](https://github.com/zr-jb/graphite-meter/blob/main/api/wire.md) (Public API contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Go Server"]
  node_server_entry["Server entry point<br/>Go command<br/>[main.go]"]
  node_server_runtime{{"Listeners and admission<br/>server runtime<br/>[listeners.go]"}}
  node_admission["Connection admission<br/>load control<br/>[admission.go]"]
  node_server_config["Server configuration<br/>configuration model<br/>[config.go]"]
  node_endpoint_registry["Measurement endpoints<br/>endpoint registry<br/>[registry.go]"]
  node_meter["Meter handlers<br/>measurement handlers<br/>[meter.go]"]
  node_upload_accounting["Upload accounting<br/>upload handler<br/>[upload.go]"]
  node_transport_sessions{{"Transport sessions<br/>transport abstraction<br/>[session.go]"}}
  node_wire_protocol["Framed wire protocol<br/>protocol framing<br/>[frame.go]"]
  node_auth{{"Authentication service<br/>auth boundary<br/>[service.go]"}}
  node_static_embed["Embedded browser assets<br/>static delivery<br/>[embed.go]"]
end

subgraph group_browser["Browser Client"]
  node_browser_bootstrap["Svelte application<br/>browser entry<br/>[main.ts]"]
  node_browser_engine{{"Measurement engine<br/>runner orchestration<br/>[engine.svelte.ts]"}}
  node_browser_runner["Real browser runner<br/>runner implementation<br/>[RealRunner.ts]"]
  node_browser_workers["Transport workers<br/>web workers<br/>[download-worker.ts]"]
  node_browser_state_ui["State and visualization<br/>Svelte UI<br/>[store.svelte.ts]"]
end

subgraph group_native["Native Client"]
  node_native_entry["TUI entry point<br/>Go command<br/>[main.go]"]
  node_native_runner{{"Native measurement runner<br/>Go client runner<br/>[runner.go]"}}
  node_tui_lifecycle["Terminal lifecycle<br/>TUI rendering<br/>[runlifecycle.go]"]
end

node_api_contract["Public API contract<br/>API specification<br/>[wire.md]"]
node_container_image["Static OCI image<br/>deployment artifact"]

node_server_entry -->|"starts"| node_server_runtime
node_server_config -->|"configures"| node_server_runtime
node_admission -->|"limits connections"| node_server_runtime
node_server_runtime -->|"routes requests"| node_endpoint_registry
node_endpoint_registry -->|"serves measurement stages"| node_meter
node_endpoint_registry -->|"receives uploads"| node_upload_accounting
node_endpoint_registry -->|"uses transports"| node_transport_sessions
node_transport_sessions -->|"exchanges frames"| node_wire_protocol
node_auth -->|"protects assets and transports"| node_server_runtime
node_static_embed -->|"serves browser app"| node_server_runtime
node_browser_bootstrap -->|"initializes"| node_browser_engine
node_browser_engine -->|"controls"| node_browser_runner
node_browser_runner -->|"runs stages"| node_browser_workers
node_browser_workers -->|"preflight, probe, and measurement"| node_endpoint_registry
node_browser_engine -->|"publishes state"| node_browser_state_ui
node_browser_state_ui -->|"renders in app"| node_browser_bootstrap
node_native_entry -->|"starts"| node_native_runner
node_native_runner -->|"reports lifecycle"| node_tui_lifecycle
node_native_runner -->|"uses shared API"| node_endpoint_registry
node_native_runner -->|"uses shared transports"| node_transport_sessions
node_api_contract -.->|"specifies"| node_endpoint_registry
node_api_contract -.->|"implements"| node_browser_runner
node_api_contract -.->|"implements"| node_native_runner
node_container_image -->|"packages"| node_server_entry

click node_server_entry "https://github.com/zr-jb/graphite-meter/blob/main/go/cmd/graphite-meter/main.go"
click node_server_runtime "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/server/listeners.go"
click node_admission "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/server/admission.go"
click node_server_config "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/config/config.go"
click node_endpoint_registry "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/registry.go"
click node_meter "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/meter.go"
click node_upload_accounting "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/upload.go"
click node_transport_sessions "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/transport/session.go"
click node_wire_protocol "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/wire/frame.go"
click node_auth "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/auth/service.go"
click node_static_embed "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/static/embed.go"
click node_api_contract "https://github.com/zr-jb/graphite-meter/blob/main/api/wire.md"
click node_browser_bootstrap "https://github.com/zr-jb/graphite-meter/blob/main/client/src/main.ts"
click node_browser_engine "https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/runner/engine.svelte.ts"
click node_browser_runner "https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/runner/RealRunner.ts"
click node_browser_workers "https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/runner/workers/download-worker.ts"
click node_browser_state_ui "https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/state/store.svelte.ts"
click node_native_entry "https://github.com/zr-jb/graphite-meter/blob/main/go/cmd/graphite-meter-client/main.go"
click node_native_runner "https://github.com/zr-jb/graphite-meter/blob/main/go/internal/goclient/runner.go"
click node_tui_lifecycle "https://github.com/zr-jb/graphite-meter/blob/main/go/cmd/graphite-meter-client/runlifecycle.go"
click node_container_image "https://github.com/zr-jb/graphite-meter/blob/main/container/Dockerfile"

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_server_entry,node_server_runtime,node_admission,node_server_config,node_endpoint_registry,node_meter,node_upload_accounting,node_transport_sessions,node_wire_protocol,node_auth,node_static_embed toneBlue
class node_browser_bootstrap,node_browser_engine,node_browser_runner,node_browser_workers,node_browser_state_ui toneAmber
class node_native_entry,node_native_runner,node_tui_lifecycle toneMint
class node_api_contract,node_container_image toneNeutral
```

## Components

### Go Server

Authoritative endpoint, transport, and admission boundary.

- [Server entry point](https://github.com/zr-jb/graphite-meter/blob/main/go/cmd/graphite-meter/main.go): Go command · `go/cmd/graphite-meter/main.go`
- [Listeners and admission](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/server/listeners.go): server runtime · Configures HTTP/1.1, HTTP/2, HTTP/3, TLS, limits, and access policy. · `go/internal/server/listeners.go`
- [Connection admission](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/server/admission.go): load control · `go/internal/server/admission.go`
- [Server configuration](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/config/config.go): configuration model · `go/internal/config/config.go`
- [Measurement endpoints](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/registry.go): endpoint registry · Exposes preflight, probe, download, upload, ping, and WebTransport operations. · `go/internal/endpoint/registry.go`
- [Meter handlers](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/meter.go): measurement handlers · `go/internal/endpoint/meter.go`
- [Upload accounting](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/endpoint/upload.go): upload handler · Reports server-observed received bytes and progress. · `go/internal/endpoint/upload.go`
- [Transport sessions](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/transport/session.go): transport abstraction · Normalizes streaming HTTP, WebSocket, QUIC, and WebTransport. · `go/internal/transport/session.go`
- [Framed wire protocol](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/wire/frame.go): protocol framing · Shared transport-independent control and measurement frames. · `go/internal/wire/frame.go`
- [Authentication service](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/auth/service.go): auth boundary · Optional password/OIDC sessions, policy, device approval, and transport enforcement. · `go/internal/auth/service.go`
- [Embedded browser assets](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/static/embed.go): static delivery · `go/internal/static/embed.go`

### Browser Client

Embedded Svelte measurement application.

- [Svelte application](https://github.com/zr-jb/graphite-meter/blob/main/client/src/main.ts): browser entry · `client/src/main.ts`
- [Measurement engine](https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/runner/engine.svelte.ts): runner orchestration · Schedules stages and decides stability and completion. · `client/src/lib/runner/engine.svelte.ts`
- [Real browser runner](https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/runner/RealRunner.ts): runner implementation · `client/src/lib/runner/RealRunner.ts`
- [Transport workers](https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/runner/workers/download-worker.ts): web workers · Run concurrent download, upload, and ping with rolling estimates. · `client/src/lib/runner/workers/download-worker.ts`
- [State and visualization](https://github.com/zr-jb/graphite-meter/blob/main/client/src/lib/state/store.svelte.ts): Svelte UI · Renders availability, live status, results, and charts from runner outputs. · `client/src/lib/state/store.svelte.ts`

### Native Client

Terminal implementation of the shared measurement contract.

- [TUI entry point](https://github.com/zr-jb/graphite-meter/blob/main/go/cmd/graphite-meter-client/main.go): Go command · `go/cmd/graphite-meter-client/main.go`
- [Native measurement runner](https://github.com/zr-jb/graphite-meter/blob/main/go/internal/goclient/runner.go): Go client runner · Executes the same server contract and transports. · `go/internal/goclient/runner.go`
- [Terminal lifecycle](https://github.com/zr-jb/graphite-meter/blob/main/go/cmd/graphite-meter-client/runlifecycle.go): TUI rendering · `go/cmd/graphite-meter-client/runlifecycle.go`

### Other components

- [Public API contract](https://github.com/zr-jb/graphite-meter/blob/main/api/wire.md): API specification · Routes plus preflight, probe, and wire schemas. · `api/wire.md`
- [Static OCI image](https://github.com/zr-jb/graphite-meter/blob/main/container/Dockerfile): deployment artifact · Builds a static binary for scratch-based deployment. · `container/Dockerfile`

## Connections

- Server entry point → Listeners and admission: starts
- Server configuration → Listeners and admission: configures
- Connection admission → Listeners and admission: limits connections
- Listeners and admission → Measurement endpoints: routes requests
- Measurement endpoints → Meter handlers: serves measurement stages
- Measurement endpoints → Upload accounting: receives uploads
- Measurement endpoints → Transport sessions: uses transports
- Transport sessions → Framed wire protocol: exchanges frames
- Authentication service → Listeners and admission: protects assets and transports
- Embedded browser assets → Listeners and admission: serves browser app
- Svelte application → Measurement engine: initializes
- Measurement engine → Real browser runner: controls
- Real browser runner → Transport workers: runs stages
- Transport workers → Measurement endpoints: preflight, probe, and measurement
- Measurement engine → State and visualization: publishes state
- State and visualization → Svelte application: renders in app
- TUI entry point → Native measurement runner: starts
- Native measurement runner → Terminal lifecycle: reports lifecycle
- Native measurement runner → Measurement endpoints: uses shared API
- Native measurement runner → Transport sessions: uses shared transports
- Public API contract → Measurement endpoints: specifies
- Public API contract → Real browser runner: implements
- Public API contract → Native measurement runner: implements
- Static OCI image → Server entry point: packages
