How subbareddyalamur/cloudterm works
Purpose and Entry Points
CloudTerm is a containerized browser-based operations console for AWS EC2 fleets. It uses AWS Systems Manager (SSM) for shell access, RDP tunneling, file operations, metrics, and discovery—avoiding direct SSH/RDP exposure.
Primary Go processes:
• Main API/UI server: cmd/cloudterm/main.go
• SSM tunnel/port-forwarding service: cmd/forwarder/main.go
• Embedded production React assets: web/embed_v2.go
Main Application Boundary
The Go main service owns HTTP, WebSocket, SSE, AWS orchestration, terminal session lifecycle, audit, and persistent encrypted local data. HTTP handlers are the boundary between browser workflows and domain services:
• internal/handlers/handlers.go
• internal/handlers/k8s.go
• internal/handlers/topology.go
The active client is a React/TypeScript SPA initialized at web/frontend-v2/src/main.tsx and composed by web/frontend-v2/src/App.tsx.
Fleet Discovery and AWS Operations
AWS integrations are centralized under internal/aws. Discovery concurrently resolves profile/manual-account fleets and regions, then caches/grouping data for the UI:
• internal/aws/discovery.go
• internal/aws/accounts.go
• internal/aws/clone.go
AWS is also the operational boundary: EC2/VPC/ELB APIs provide inventory and topology; SSM starts sessions and executes commands; optional S3 supports high-volume transfers. File browser, metrics, S3 transfer, network analysis, and topology all remain backend-mediated rather than browser-to-AWS.
Interactive Access and Data Movement
SSH-like terminal sessions run as isolated local PTYs that invoke SSM session tooling; browser terminal I/O travels over WebSocket. Recording captures terminal output as .cast:
• internal/session/manager.go
• internal/session/recorder.go
• web/frontend-v2/src/components/terminal/TerminalSession.tsx
The independent forwarder allocates local ports and maintains SSM tunnels for RDP and generic forwarding. RDP traffic then crosses Guacamole services rather than the main application:
• cmd/forwarder/main.go
• docker/guac-lite/server.js
• web/frontend-v2/src/components/rdp/GuacamoleClient.tsx
SSM-based and optional S3-presigned file transfer flows are backend-owned:
• internal/aws/filetransfer.go
• internal/aws/s3transfer.go
• internal/aws/filebrowser.go
AI, Suggestions, and Protected State
The AI agent assembles fleet/session context, exposes controlled AWS lookup tools, streams provider responses, and flags destructive proposals. It proposes rather than executes terminal commands:
• internal/llm/agent.go
• internal/llm/tools.go
• internal/llm/safety.go
Provider implementations support Bedrock, Anthropic, OpenAI, Gemini, and Ollama. The frontend consumes streamed AI state:
• internal/llm/factory.go
• web/frontend-v2/src/hooks/useAIStream.ts
A separate embedded suggestion engine observes terminal activity and persists encrypted learning data in bbolt; the RDP credential vault uses the same encryption posture:
• internal/suggest/engine.go
• internal/suggest/store.go
• internal/vault/store.go
Visualization and Client State
The SPA uses feature components plus Zustand stores to coordinate instance inventory, open sessions, layout, preferences, and activity. API/WS client code is the frontend transport boundary:
• web/frontend-v2/src/stores/instances.ts
• web/frontend-v2/src/stores/sessions.ts
• web/frontend-v2/src/lib/api.ts
Topology rendering consumes backend-derived AWS graph data and supports reachability/exposure workflows:
• internal/aws/topology.go
• internal/aws/reachability.go
• web/frontend-v2/src/components/topology/TopologyRoute.tsx
Deployment and Sidecars
docker-compose.yml orchestrates the main Go app, Go forwarder, Node.js guac-lite, Apache guacd, and a Python conversion sidecar. The converter asynchronously transforms SSH/RDP recordings to MP4 using agg, guacenc, and ffmpeg:
• docker-compose.yml
• docker/converter/api.py
• docker/converter/Dockerfile
Persistent host-mounted state includes discovery cache/preferences, audit JSONL, recordings/exports, and encrypted bbolt data. Configuration is environment-driven through internal/config/config.go; runtime images are defined by Dockerfile and Dockerfile.forwarder.
Main entry points: handlers.go HTTP handlers · App.tsx React SPA · main.go CloudTerm server · manager.go Terminal session manager
Components 18
Browser client
- React SPA · Operations console UI and client state.
web/frontend-v2/src/App.tsx - API, WS and SSE client
web/frontend-v2/src/lib/api.ts - Terminal UI
web/frontend-v2/src/components/terminal/TerminalSession.tsx - Guacamole RDP client
web/frontend-v2/src/components/rdp/GuacamoleClient.tsx - Topology view
web/frontend-v2/src/components/topology/TopologyRoute.tsx
Core application
- CloudTerm server · Browser boundary, orchestration, audit, and session lifecycle.
cmd/cloudterm/main.go - HTTP handlers
internal/handlers/handlers.go - Terminal session manager · Runs isolated local PTYs and records terminal output.
internal/session/manager.go - Session recorder
internal/session/recorder.go - AI agent and safety · Provides guarded proposals, not terminal execution.
internal/llm/agent.go
AWS operations
- Fleet discovery · Concurrently resolves accounts, fleets, regions, and UI cache data.
internal/aws/discovery.go - AWS operations · Backend-mediated inventory, sessions, files, metrics, and topology.
internal/aws/filetransfer.go - Topology and reachability
internal/aws/topology.go
Access sidecars
- SSM forwarder · Allocates local ports and maintains RDP and generic SSM tunnels.
cmd/forwarder/main.go - guac-lite
docker/guac-lite/server.js - Recording converter · Asynchronously converts SSH/RDP recordings to MP4.
docker/converter/api.py
Protected state
- Suggestion engine · Observes terminal activity for embedded suggestions.
internal/suggest/engine.go - Encrypted local stores · Stores learning data, RDP credentials, cache, audit, and recordings.
internal/suggest/store.go
Connections 23
- React SPA → API, WS and SSE client: uses
- React SPA → Terminal UI: renders
- React SPA → Guacamole RDP client: renders
- React SPA → Topology view: renders
- API, WS and SSE client → CloudTerm server: HTTP, WebSocket, SSE
- CloudTerm server → HTTP handlers: routes requests
- HTTP handlers → Fleet discovery: fleet workflows
- HTTP handlers → AWS operations: operations and transfers
- HTTP handlers → Topology and reachability: topology requests
- HTTP handlers → Terminal session manager: terminal lifecycle
- Terminal session manager → AWS operations: SSM sessions
- Terminal session manager → Session recorder: terminal output
- Terminal session manager → Suggestion engine: terminal activity
- CloudTerm server → AI agent and safety: AI streaming
- AI agent and safety → AWS operations: controlled lookup tools
- Topology and reachability → Topology view: derived graph data
- Guacamole RDP client → guac-lite: RDP stream
- guac-lite → SSM forwarder: local tunnel
- SSM forwarder → AWS operations: SSM port forwarding
- Session recorder → Recording converter: recordings
- Suggestion engine → Encrypted local stores: encrypted learning data
- CloudTerm server → Encrypted local stores: audit, cache, credentials
- Session recorder → Encrypted local stores: casts and exports