516f1b1946
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2.1 KiB
2.1 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)
Packages
cmd/webterm: CLI entrypointwebterm: server/runtime/domain logicinternal/terminalstate: Go terminal emulator wrapper (go-te) used for screenshots
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.svgand 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.
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.