# subbareddyalamur/cloudterm architecture

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

- Interactive diagram: https://gitdiagram.com/subbareddyalamur/cloudterm
- Repository: https://github.com/subbareddyalamur/cloudterm

## Overview

#### 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: [`internal/handlers/handlers.go`](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/handlers/handlers.go) (HTTP handlers), [`web/frontend-v2/src/App.tsx`](https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/App.tsx) (React SPA), [`cmd/cloudterm/main.go`](https://github.com/subbareddyalamur/cloudterm/blob/main/cmd/cloudterm/main.go) (CloudTerm server), [`internal/session/manager.go`](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/session/manager.go) (Terminal session manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_spa["React SPA<br/>React/TypeScript<br/>[App.tsx]"]
  node_client_transport["API, WS and SSE client<br/>frontend transport<br/>[api.ts]"]
  node_terminal_ui["Terminal UI<br/>xterm component"]
  node_rdp_ui["Guacamole RDP client<br/>RDP component"]
  node_topology_ui["Topology view<br/>visualization component<br/>[TopologyRoute.tsx]"]
end

subgraph group_core["Core application"]
  node_main_server["CloudTerm server<br/>Go HTTP/WS/SSE server<br/>[main.go]"]
  node_handlers["HTTP handlers<br/>Go handler layer<br/>[handlers.go]"]
  node_session_manager["Terminal session manager<br/>PTY/SSM sessions<br/>[manager.go]"]
  node_recorder["Session recorder<br/>cast recorder<br/>[recorder.go]"]
  node_ai_agent["AI agent and safety<br/>streaming agent<br/>[agent.go]"]
end

subgraph group_aws["AWS operations"]
  node_discovery["Fleet discovery<br/>AWS discovery<br/>[discovery.go]"]
  node_aws_ops{{"AWS operations<br/>EC2/VPC/ELB/SSM/S3<br/>[filetransfer.go]"}}
  node_topology["Topology and reachability<br/>AWS graph service<br/>[topology.go]"]
end

subgraph group_access["Access sidecars"]
  node_forwarder["SSM forwarder<br/>Go tunnel service<br/>[main.go]"]
  node_guac_lite["guac-lite<br/>Node.js gateway<br/>[server.js]"]
  node_converter["Recording converter<br/>Python sidecar<br/>[api.py]"]
end

subgraph group_state["Protected state"]
  node_suggestions["Suggestion engine<br/>terminal learning<br/>[engine.go]"]
  node_encrypted_store[("Encrypted local stores<br/>bbolt and mounted state<br/>[store.go]")]
end

node_spa -->|"uses"| node_client_transport
node_spa -->|"renders"| node_terminal_ui
node_spa -->|"renders"| node_rdp_ui
node_spa -->|"renders"| node_topology_ui
node_client_transport -->|"HTTP, WebSocket, SSE"| node_main_server
node_main_server -->|"routes requests"| node_handlers
node_handlers -->|"fleet workflows"| node_discovery
node_handlers -->|"operations and transfers"| node_aws_ops
node_handlers -->|"topology requests"| node_topology
node_handlers -->|"terminal lifecycle"| node_session_manager
node_session_manager -->|"SSM sessions"| node_aws_ops
node_session_manager -->|"terminal output"| node_recorder
node_session_manager -->|"terminal activity"| node_suggestions
node_main_server -->|"AI streaming"| node_ai_agent
node_ai_agent -->|"controlled lookup tools"| node_aws_ops
node_topology -->|"derived graph data"| node_topology_ui
node_rdp_ui -->|"RDP stream"| node_guac_lite
node_guac_lite -->|"local tunnel"| node_forwarder
node_forwarder -->|"SSM port forwarding"| node_aws_ops
node_recorder -->|"recordings"| node_converter
node_suggestions -->|"encrypted learning data"| node_encrypted_store
node_main_server -->|"audit, cache, credentials"| node_encrypted_store
node_recorder -->|"casts and exports"| node_encrypted_store

click node_spa "https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/App.tsx"
click node_client_transport "https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/lib/api.ts"
click node_terminal_ui "https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/components/terminal/TerminalSession.tsx"
click node_rdp_ui "https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/components/rdp/GuacamoleClient.tsx"
click node_topology_ui "https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/components/topology/TopologyRoute.tsx"
click node_main_server "https://github.com/subbareddyalamur/cloudterm/blob/main/cmd/cloudterm/main.go"
click node_handlers "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/handlers/handlers.go"
click node_session_manager "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/session/manager.go"
click node_recorder "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/session/recorder.go"
click node_ai_agent "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/llm/agent.go"
click node_discovery "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/aws/discovery.go"
click node_aws_ops "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/aws/filetransfer.go"
click node_topology "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/aws/topology.go"
click node_forwarder "https://github.com/subbareddyalamur/cloudterm/blob/main/cmd/forwarder/main.go"
click node_guac_lite "https://github.com/subbareddyalamur/cloudterm/blob/main/docker/guac-lite/server.js"
click node_converter "https://github.com/subbareddyalamur/cloudterm/blob/main/docker/converter/api.py"
click node_suggestions "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/suggest/engine.go"
click node_encrypted_store "https://github.com/subbareddyalamur/cloudterm/blob/main/internal/suggest/store.go"

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_spa,node_client_transport,node_terminal_ui,node_rdp_ui,node_topology_ui toneBlue
class node_main_server,node_handlers,node_session_manager,node_recorder,node_ai_agent toneAmber
class node_discovery,node_aws_ops,node_topology toneMint
class node_forwarder,node_guac_lite,node_converter toneRose
class node_suggestions,node_encrypted_store toneIndigo
```

## Components

### Browser client

- [React SPA](https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/App.tsx): React/TypeScript · Operations console UI and client state. · `web/frontend-v2/src/App.tsx`
- [API, WS and SSE client](https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/lib/api.ts): frontend transport · `web/frontend-v2/src/lib/api.ts`
- [Terminal UI](https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/components/terminal/TerminalSession.tsx): xterm component · `web/frontend-v2/src/components/terminal/TerminalSession.tsx`
- [Guacamole RDP client](https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/components/rdp/GuacamoleClient.tsx): RDP component · `web/frontend-v2/src/components/rdp/GuacamoleClient.tsx`
- [Topology view](https://github.com/subbareddyalamur/cloudterm/blob/main/web/frontend-v2/src/components/topology/TopologyRoute.tsx): visualization component · `web/frontend-v2/src/components/topology/TopologyRoute.tsx`

### Core application

- [CloudTerm server](https://github.com/subbareddyalamur/cloudterm/blob/main/cmd/cloudterm/main.go): Go HTTP/WS/SSE server · Browser boundary, orchestration, audit, and session lifecycle. · `cmd/cloudterm/main.go`
- [HTTP handlers](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/handlers/handlers.go): Go handler layer · `internal/handlers/handlers.go`
- [Terminal session manager](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/session/manager.go): PTY/SSM sessions · Runs isolated local PTYs and records terminal output. · `internal/session/manager.go`
- [Session recorder](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/session/recorder.go): cast recorder · `internal/session/recorder.go`
- [AI agent and safety](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/llm/agent.go): streaming agent · Provides guarded proposals, not terminal execution. · `internal/llm/agent.go`

### AWS operations

- [Fleet discovery](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/aws/discovery.go): AWS discovery · Concurrently resolves accounts, fleets, regions, and UI cache data. · `internal/aws/discovery.go`
- [AWS operations](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/aws/filetransfer.go): EC2/VPC/ELB/SSM/S3 · Backend-mediated inventory, sessions, files, metrics, and topology. · `internal/aws/filetransfer.go`
- [Topology and reachability](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/aws/topology.go): AWS graph service · `internal/aws/topology.go`

### Access sidecars

- [SSM forwarder](https://github.com/subbareddyalamur/cloudterm/blob/main/cmd/forwarder/main.go): Go tunnel service · Allocates local ports and maintains RDP and generic SSM tunnels. · `cmd/forwarder/main.go`
- [guac-lite](https://github.com/subbareddyalamur/cloudterm/blob/main/docker/guac-lite/server.js): Node.js gateway · `docker/guac-lite/server.js`
- [Recording converter](https://github.com/subbareddyalamur/cloudterm/blob/main/docker/converter/api.py): Python sidecar · Asynchronously converts SSH/RDP recordings to MP4. · `docker/converter/api.py`

### Protected state

- [Suggestion engine](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/suggest/engine.go): terminal learning · Observes terminal activity for embedded suggestions. · `internal/suggest/engine.go`
- [Encrypted local stores](https://github.com/subbareddyalamur/cloudterm/blob/main/internal/suggest/store.go): bbolt and mounted state · Stores learning data, RDP credentials, cache, audit, and recordings. · `internal/suggest/store.go`

## Connections

- 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
