# lukegus/termix architecture

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

- Interactive diagram: https://gitdiagram.com/lukegus/termix
- Repository: https://github.com/lukegus/termix

## Overview

#### Purpose and Delivery Model
Termix is a self-hosted server-management platform: SSH terminals, files, host metrics, tunnels, container control, serial access, and Guacamole-backed RDP/VNC/Telnet. It runs as a browser/PWA application or packaged Electron desktop client, backed by a Node/TypeScript service. Core entry points are `src/main.tsx`, `src/backend/starter.ts`, and `electron/main.cjs`.

#### Client Application Shell
The React frontend mounts from `src/main.tsx` into the tabbed/split-pane application shell in `src/ui/AppShell.tsx` and `src/ui/shell/TabContext.tsx`. Feature screens call backend HTTP/WebSocket-facing API modules under `src/ui/api/`, keeping UI components separated from transport details. Electron-specific browser/native bridging is isolated through `electron/preload.js` and `src/ui/lib/electron.ts`.

#### Backend API and Persistence
The backend bootstrap (`src/backend/starter.ts`) composes application services, database routes, SSH/terminal routes, Guacamole, homepage, and API documentation (`src/backend/swagger.ts`). SQLite persistence is centered on `src/backend/database/database.ts`, schema definitions in `src/backend/database/db/schema.ts`, and domain route handlers in `src/backend/database/routes/`. Database encryption, migrations, and field protection form a security boundary in `src/backend/utils/database-file-encryption.ts`, `src/backend/utils/database-migration.ts`, and `src/backend/utils/field-crypto.ts`.

#### Identity, Authorization, and Audit
User/session management, RBAC, credentials, API keys, SSO/OIDC/LDAP, TOTP, and WebAuthn are persisted and exposed through routes such as `src/backend/database/routes/users.ts`, `src/backend/database/routes/rbac.ts`, and `src/backend/database/routes/sso-provider-routes.ts`. Runtime authorization and request protection are concentrated in `src/backend/utils/auth-manager.ts`, `src/backend/utils/permission-manager.ts`, and `src/backend/utils/login-rate-limiter.ts`. Audit logging provides the cross-cutting accountability path at `src/backend/utils/audit-logger.ts`.

#### Remote-Access Execution Plane
SSH is the principal execution boundary: authenticated host resolution, connection reuse, jump hosts, host-key verification, terminal sessions, tmux monitoring, file operations, and forwarding reside in `src/backend/ssh/`. Key orchestration points are `src/backend/ssh/ssh-connection-pool.ts`, `src/backend/ssh/terminal-session-manager.ts`, and `src/backend/ssh/tunnel.ts`. The frontend presents these streams and controls in `src/ui/features/terminal/TerminalApp.tsx`, `src/ui/features/file-manager/FileManagerApp.tsx`, and `src/ui/features/tunnel/TunnelApp.tsx`. Serial access follows a parallel backend/native path via `src/backend/serial/serial.ts` and `src/ui/features/serial/Serial.tsx`.

#### Infrastructure and Remote Integrations
Remote desktop connections are tokenized/proxied through the Guacamole integration in `src/backend/guacamole/guacamole-server.ts` and `src/backend/guacamole/token-service.ts`, with an external `guacd` service expected by `docker/docker-compose.yml`. SSH also integrates Docker/Podman (`src/backend/ssh/docker.ts`), Tailscale, Proxmox, Vault signing, and notification/webhook services. Deployment is container-oriented through `docker/Dockerfile` and `docker/entrypoint.sh`; Nginx config supports HTTP/HTTPS fronting.

#### Observability and Dashboard Products
SSH-collected host telemetry flows through `src/backend/ssh/host-metrics.ts` and collectors in `src/backend/ssh/widgets/`, is stored/configured via database routes, and is rendered in `src/ui/features/host-metrics/HostMetricsApp.tsx`. Alert evaluation and delivery are handled by `src/backend/ssh/alert-engine.ts` and `src/backend/utils/notification-sender.ts`. User-configurable dashboard/homepage layouts and widgets span `src/backend/homepage.ts`, `src/ui/features/homepage/HomepageApp.tsx`, and `src/ui/features/homepage/widgets/WidgetRegistry.ts`.

#### Packaging Boundaries
Web builds are Vite-based (`vite.config.ts`) and include a service worker at `public/sw.js`. Desktop packaging uses Electron Builder (`electron-builder.json`), native main/preload processes, and platform packaging assets under `build/`, `flatpak/`, `Casks/`, and `chocolatey/`.

Main entry points: [`src/backend/starter.ts`](https://github.com/lukegus/termix/blob/main/src/backend/starter.ts) (Backend bootstrap), [`src/ui/AppShell.tsx`](https://github.com/lukegus/termix/blob/main/src/ui/AppShell.tsx) (Tabbed app shell), [`src/backend/database/routes/users.ts`](https://github.com/lukegus/termix/blob/main/src/backend/database/routes/users.ts) (Domain API routes), [`src/backend/utils/auth-manager.ts`](https://github.com/lukegus/termix/blob/main/src/backend/utils/auth-manager.ts) (Identity and authorization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_web_entry["React web entry<br/>React entry<br/>[main.tsx]"]
  node_app_shell["Tabbed app shell<br/>React shell<br/>[AppShell.tsx]"]
  node_ui_api["UI API modules<br/>transport client"]
  node_access_ui["Access feature UIs<br/>terminal/files/tunnels UI<br/>[TerminalApp.tsx]"]
  node_metrics_dashboard_ui["Metrics and homepage<br/>dashboard UI<br/>[HostMetricsApp.tsx]"]
  node_electron_bridge["Electron bridge<br/>preload/native bridge<br/>[preload.js]"]
end

subgraph group_backend["Backend"]
  node_backend_bootstrap{{"Backend bootstrap<br/>Node/TypeScript service<br/>[starter.ts]"}}
  node_domain_routes["Domain API routes<br/>route handlers<br/>[users.ts]"]
  node_identity_security["Identity and authorization<br/>auth/RBAC protection<br/>[auth-manager.ts]"]
  node_audit_log["Audit logging<br/>accountability<br/>[audit-logger.ts]"]
  node_sqlite[("Encrypted SQLite<br/>persistence<br/>[database.ts]")]
end

subgraph group_remote["Remote execution"]
  node_ssh_plane{{"SSH execution plane<br/>connection/session service"}}
  node_remote_hosts(("Managed hosts<br/>SSH targets"))
  node_serial_plane["Serial access<br/>native serial service<br/>[serial.ts]"]
  node_guacamole["Guacamole proxy<br/>remote desktop integration"]
  node_guacd(("guacd<br/>external remote desktop daemon<br/>[docker-compose.yml]"))
  node_telemetry_alerts["Telemetry and alerts<br/>metrics/alert pipeline<br/>[host-metrics.ts]"]
end

subgraph group_delivery["Delivery"]
  node_electron_main{{"Electron main process<br/>desktop runtime<br/>[main.cjs]"}}
  node_web_delivery["Vite PWA build<br/>web delivery<br/>[vite.config.ts]"]
  node_container_delivery["Container deployment<br/>Docker runtime"]
end

node_web_entry -->|"mounts"| node_app_shell
node_app_shell -->|"hosts"| node_access_ui
node_app_shell -->|"hosts"| node_metrics_dashboard_ui
node_access_ui -->|"uses"| node_ui_api
node_metrics_dashboard_ui -->|"uses"| node_ui_api
node_ui_api -->|"HTTP/WebSocket"| node_backend_bootstrap
node_electron_main -->|"loads"| node_electron_bridge
node_electron_bridge -->|"native APIs"| node_app_shell
node_backend_bootstrap -->|"serves"| node_domain_routes
node_backend_bootstrap -->|"protects requests with"| node_identity_security
node_backend_bootstrap -->|"exposes"| node_ssh_plane
node_backend_bootstrap -->|"exposes"| node_serial_plane
node_backend_bootstrap -->|"integrates"| node_guacamole
node_backend_bootstrap -->|"runs"| node_telemetry_alerts
node_domain_routes -->|"persists"| node_sqlite
node_identity_security -->|"reads identity data"| node_sqlite
node_identity_security -->|"records events"| node_audit_log
node_domain_routes -.->|"records changes"| node_audit_log
node_ssh_plane -->|"SSH sessions"| node_remote_hosts
node_serial_plane -->|"serial devices"| node_remote_hosts
node_telemetry_alerts -->|"collects through"| node_ssh_plane
node_telemetry_alerts -->|"stores configuration"| node_sqlite
node_guacamole -->|"proxies to"| node_guacd
node_web_delivery -->|"builds"| node_web_entry
node_container_delivery -->|"deploys"| node_backend_bootstrap

click node_web_entry "https://github.com/lukegus/termix/blob/main/src/main.tsx"
click node_app_shell "https://github.com/lukegus/termix/blob/main/src/ui/AppShell.tsx"
click node_ui_api "https://github.com/lukegus/termix/blob/main/src/ui/api/host-metrics-api.ts"
click node_access_ui "https://github.com/lukegus/termix/blob/main/src/ui/features/terminal/TerminalApp.tsx"
click node_metrics_dashboard_ui "https://github.com/lukegus/termix/blob/main/src/ui/features/host-metrics/HostMetricsApp.tsx"
click node_electron_bridge "https://github.com/lukegus/termix/blob/main/electron/preload.js"
click node_backend_bootstrap "https://github.com/lukegus/termix/blob/main/src/backend/starter.ts"
click node_domain_routes "https://github.com/lukegus/termix/blob/main/src/backend/database/routes/users.ts"
click node_identity_security "https://github.com/lukegus/termix/blob/main/src/backend/utils/auth-manager.ts"
click node_audit_log "https://github.com/lukegus/termix/blob/main/src/backend/utils/audit-logger.ts"
click node_sqlite "https://github.com/lukegus/termix/blob/main/src/backend/database/database.ts"
click node_ssh_plane "https://github.com/lukegus/termix/blob/main/src/backend/ssh/ssh-connection-pool.ts"
click node_serial_plane "https://github.com/lukegus/termix/blob/main/src/backend/serial/serial.ts"
click node_guacamole "https://github.com/lukegus/termix/blob/main/src/backend/guacamole/guacamole-server.ts"
click node_guacd "https://github.com/lukegus/termix/blob/main/docker/docker-compose.yml"
click node_telemetry_alerts "https://github.com/lukegus/termix/blob/main/src/backend/ssh/host-metrics.ts"
click node_electron_main "https://github.com/lukegus/termix/blob/main/electron/main.cjs"
click node_web_delivery "https://github.com/lukegus/termix/blob/main/vite.config.ts"
click node_container_delivery "https://github.com/lukegus/termix/tree/main/docker/Dockerfile"

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_web_entry,node_app_shell,node_ui_api,node_access_ui,node_metrics_dashboard_ui,node_electron_bridge toneBlue
class node_backend_bootstrap,node_domain_routes,node_identity_security,node_audit_log,node_sqlite toneAmber
class node_ssh_plane,node_remote_hosts,node_serial_plane,node_guacamole,node_guacd,node_telemetry_alerts toneMint
class node_electron_main,node_web_delivery,node_container_delivery toneRose
```

## Components

### Client

- [React web entry](https://github.com/lukegus/termix/blob/main/src/main.tsx): React entry · `src/main.tsx`
- [Tabbed app shell](https://github.com/lukegus/termix/blob/main/src/ui/AppShell.tsx): React shell · Split-pane and tab state host. · `src/ui/AppShell.tsx`
- [UI API modules](https://github.com/lukegus/termix/blob/main/src/ui/api/host-metrics-api.ts): transport client · `src/ui/api/host-metrics-api.ts`
- [Access feature UIs](https://github.com/lukegus/termix/blob/main/src/ui/features/terminal/TerminalApp.tsx): terminal/files/tunnels UI · `src/ui/features/terminal/TerminalApp.tsx`
- [Metrics and homepage](https://github.com/lukegus/termix/blob/main/src/ui/features/host-metrics/HostMetricsApp.tsx): dashboard UI · `src/ui/features/host-metrics/HostMetricsApp.tsx`
- [Electron bridge](https://github.com/lukegus/termix/blob/main/electron/preload.js): preload/native bridge · `electron/preload.js`

### Backend

- [Backend bootstrap](https://github.com/lukegus/termix/blob/main/src/backend/starter.ts): Node/TypeScript service · Composes HTTP, WebSocket, domain, Guacamole, homepage, and docs services. · `src/backend/starter.ts`
- [Domain API routes](https://github.com/lukegus/termix/blob/main/src/backend/database/routes/users.ts): route handlers · `src/backend/database/routes/users.ts`
- [Identity and authorization](https://github.com/lukegus/termix/blob/main/src/backend/utils/auth-manager.ts): auth/RBAC protection · Sessions, RBAC, SSO, MFA, API keys, and rate limiting. · `src/backend/utils/auth-manager.ts`
- [Audit logging](https://github.com/lukegus/termix/blob/main/src/backend/utils/audit-logger.ts): accountability · `src/backend/utils/audit-logger.ts`
- [Encrypted SQLite](https://github.com/lukegus/termix/blob/main/src/backend/database/database.ts): persistence · Schema, migrations, and field protection form the data-security boundary. · `src/backend/database/database.ts`

### Remote execution

- [SSH execution plane](https://github.com/lukegus/termix/blob/main/src/backend/ssh/ssh-connection-pool.ts): connection/session service · Host resolution, pooling, terminal sessions, files, jump hosts, and forwarding. · `src/backend/ssh/ssh-connection-pool.ts`
- **Managed hosts**: SSH targets
- [Serial access](https://github.com/lukegus/termix/blob/main/src/backend/serial/serial.ts): native serial service · `src/backend/serial/serial.ts`
- [Guacamole proxy](https://github.com/lukegus/termix/blob/main/src/backend/guacamole/guacamole-server.ts): remote desktop integration · Tokenizes RDP, VNC, and Telnet sessions. · `src/backend/guacamole/guacamole-server.ts`
- [guacd](https://github.com/lukegus/termix/blob/main/docker/docker-compose.yml): external remote desktop daemon · `docker/docker-compose.yml`
- [Telemetry and alerts](https://github.com/lukegus/termix/blob/main/src/backend/ssh/host-metrics.ts): metrics/alert pipeline · SSH collectors feed host metrics, alert evaluation, and notifications. · `src/backend/ssh/host-metrics.ts`

### Delivery

- [Electron main process](https://github.com/lukegus/termix/blob/main/electron/main.cjs): desktop runtime · `electron/main.cjs`
- [Vite PWA build](https://github.com/lukegus/termix/blob/main/vite.config.ts): web delivery · Build includes a service worker. · `vite.config.ts`
- [Container deployment](https://github.com/lukegus/termix/tree/main/docker/Dockerfile): Docker runtime · `docker/Dockerfile`

## Connections

- React web entry → Tabbed app shell: mounts
- Tabbed app shell → Access feature UIs: hosts
- Tabbed app shell → Metrics and homepage: hosts
- Access feature UIs → UI API modules: uses
- Metrics and homepage → UI API modules: uses
- UI API modules → Backend bootstrap: HTTP/WebSocket
- Electron main process → Electron bridge: loads
- Electron bridge → Tabbed app shell: native APIs
- Backend bootstrap → Domain API routes: serves
- Backend bootstrap → Identity and authorization: protects requests with
- Backend bootstrap → SSH execution plane: exposes
- Backend bootstrap → Serial access: exposes
- Backend bootstrap → Guacamole proxy: integrates
- Backend bootstrap → Telemetry and alerts: runs
- Domain API routes → Encrypted SQLite: persists
- Identity and authorization → Encrypted SQLite: reads identity data
- Identity and authorization → Audit logging: records events
- Domain API routes → Audit logging: records changes
- SSH execution plane → Managed hosts: SSH sessions
- Serial access → Managed hosts: serial devices
- Telemetry and alerts → SSH execution plane: collects through
- Telemetry and alerts → Encrypted SQLite: stores configuration
- Guacamole proxy → guacd: proxies to
- Vite PWA build → React web entry: builds
- Container deployment → Backend bootstrap: deploys
