cdcc9bfc23
The dashboard now always downloads SVG on right-click even when PNG thumbnails are enabled, while keeping SVG as the default mode in the docs and tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 (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.svg(default) or/screenshot.pngwhenWEBTERM_SCREENSHOT_MODE=png, and listens on/eventsfor activity.
Static assets
Assets live in webterm/static:
js/terminal.tssourcejs/terminal.jsbundled 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 and creates tiles for services carrying
webterm-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.