2.5 KiB
2.5 KiB
Architecture
Overview
webterm is a Go HTTP/WebSocket server that hosts one or more terminal sessions and renders screenshot/telemetry surfaces for a dashboard UI.
Browser (generated terminal.js + ghostty-vt.wasm)
│
│ WS / HTTP / SSE
▼
webterm/server.go (LocalServer)
│
├── session_manager.go (route/app/session registry)
├── terminal_session.go (PTY-backed local sessions)
├── docker_exec_session.go (Docker exec-backed sessions)
├── docker_watcher.go (container add/remove discovery)
├── docker_stats.go (CPU sampling + sparkline data)
├── svg_exporter.go (terminal snapshot -> SVG)
└── png_exporter.go (terminal snapshot -> PNG via coverage blending)
Packages
cmd/webterm: CLI entrypointwebterm: server/runtime/domain logicinternal/terminalstate: Go terminal emulator wrapper (go-te) used for screenshotswebterm/coverage_table.go: coverage map for approximate PNG rendering
Runtime data flow
- Browser connects to
/ws/{route_key}. SessionManagerresolves or creates a session.- Session reads PTY output and updates:
- live WS stream (
stdout) - replay buffer (reconnect support)
- terminal-state tracker (
go-te) for screenshots
- live WS stream (
- Dashboard pulls
/screenshot.png(default) or/screenshot.svgwhenWEBTERM_SCREENSHOT_MODE=svg, and listens on/eventsfor activity.
Static assets
Assets live in webterm/static:
js/terminal.tssourcejs/terminal.jsgenerated bundled clientjs/ghostty-vt.wasmmonospace.css, icons,manifest.json
The server resolves static files from:
WEBTERM_STATIC_PATH(if set)- local repository-relative fallbacks rooted at
webterm/static - embedded assets bundled into the Go binary
Docker integration
- Compose mode loads services from a compose manifest (see
prod.compose.yaml) and creates tiles for services carryingwebterm-command. - Watch mode subscribes to Docker events and adds/removes tiles at runtime.
webterm-themecontrols tile theme; default theme applies if unset. Available themes:tango,xterm,monokai,monokai-pro,ristretto,dark,light,dracula,catppuccin,nord,gruvbox,solarized,tokyo,miasma,github,gotham.
Reliability notes
- WebSocket writes are serialized through a sender queue.
- Session-manager maps are lock-protected and race-tested.
- Replay buffers are bounded to avoid unbounded memory growth.