# hoophq/hoop architecture

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

- Interactive diagram: https://gitdiagram.com/hoophq/hoop
- Repository: https://github.com/hoophq/hoop

## Overview

1. This repository is a monorepo for a security gateway platform centered on the `gateway` service. The architecture is split into control plane, real-time proxy/data plane, edge helpers (`agent`, `client`), and two UI generations (`webapp` and `webapp_v2`).

2. `gateway` is the core server. It exposes the admin/API surface under `gateway/api`, owns auth, users, orgs, connections, sessions, runbooks, guardrails, AI features, audit, feature flags, plugins, and integrations. It is the main orchestration point for policy and session lifecycle.

3. The data plane lives in `gateway/transport`, `gateway/broker`, `gateway/proxyproto`, and protocol-specific packages like `gateway/rdp` and `gateway/session`. This layer accepts live traffic, applies interceptors, enforces guardrails/masking/review workflows, and forwards approved traffic to the target system while recording activity.

4. Protocol handling is a first-class boundary. The repo contains explicit adapters/parsers for PostgreSQL, MySQL, MSSQL, MongoDB, SSH, SSM, Kubernetes, HTTP/gRPC, and RDP. Shared low-level parsing/redaction primitives also exist in `common/*types` and `_libhoop`, which keeps protocol inspection separate from business APIs.

5. The `agent` service is the remote sidecar/helper that runs near infrastructure and connects back to the gateway. It handles backend-specific execution and provisioning tasks (`dbprovisioner`, `pgmanager`, `bareexec`, runbook hooks, SSH/SSM, EKS), and uses shared protobufs in `common/proto` for internal communication.

6. The `client` module is the operator-facing CLI/daemon. It handles login, session start/connect, local proxying, installs/upgrades, and command execution. It is the user entry point that tunnels the operator’s traffic into the gateway rather than connecting directly to resources.

7. Session capture and audit are built into the backend. `gateway/session` stores append-only event logs/WALs, `gateway/audit` and `gateway/events` derive searchable audit records, and `gateway/models` plus `rootfs/app/migrations` define the durable PostgreSQL schema. This is what makes replay, compliance logging, and session search possible.

8. Policy enforcement is layered into the gateway transport. Guardrails, access-request rules, data masking, reviews/approvals, and webhooks/plugins are all implemented as pipeline steps around the live session stream. Slack/Teams/Jira integrations are used for human approval and workflow notifications.

9. Identity and access are a major boundary. `gateway/idp`, `gateway/api/login/*`, `gateway/externaljwt`, `gateway/machineidentity`, and `gateway/api/mcpauth` support local auth plus OIDC/SAML/SPIFFE-style and machine identities. The gateway uses these identities to attach permissions, groups, and ABAC-like rules to both humans and AI agents.

10. There are two frontend stacks. `webapp` is the older ClojureScript SPA organized around events/subscriptions, while `webapp_v2` is a newer React/Vite app with page-based features and service modules. Both talk to the gateway’s HTTP API for administration, sessions, resource setup, reviews, and settings.

11. `agentrs` is a Rust companion/runtime focused on proxying and session handling, including websocket, TLS, and RDP-specific logic. It appears to support performance-sensitive or alternate client/agent paths rather than replacing the main Go gateway.

12. Deployment is packaged for multiple environments: Docker/Docker Compose, Helm charts for gateway and agent, and AWS templates. `rootfs` and the various Dockerfiles assemble the runtime image, while the top-level scripts automate local dev, release, and migration checks.

Main entry points: [`gateway/api/server.go`](https://github.com/hoophq/hoop/blob/main/gateway/api/server.go) (Gateway API), [`gateway/transport/server.go`](https://github.com/hoophq/hoop/blob/main/gateway/transport/server.go) (Transport), [`gateway/services/session.go`](https://github.com/hoophq/hoop/blob/main/gateway/services/session.go) (Services), [`gateway/rdp/rdp.go`](https://github.com/hoophq/hoop/blob/main/gateway/rdp/rdp.go) (RDP stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Gateway core"]
  node_gateway_api["Gateway API<br/>http/admin surface<br/>[server.go]"]
  node_gateway_idp["Identity<br/>[core.go]"]
  node_gateway_models[("Models<br/>db schema")]
  node_gateway_services["Services<br/>[session.go]"]
  node_gateway_events["Events<br/>event pipeline<br/>[publish.go]"]
  node_gateway_audit["Audit<br/>compliance log<br/>[audit.go]"]
  node_gateway_session["Session WAL<br/>append-only log<br/>[wal.go]"]
end

subgraph group_plane["Data plane"]
  node_gateway_transport["Transport<br/>live proxy<br/>[server.go]"]
  node_gateway_broker["Broker"]
  node_gateway_proxyproto["Proxy adapters<br/>protocol adapters<br/>[sshproxy.go]"]
  node_gateway_rdp["RDP stack<br/>rdp inspect<br/>[rdp.go]"]
  node_gateway_plugins["Policy plugins<br/>enforcement plugins<br/>[review.go]"]
end

subgraph group_edge["Edge helpers"]
  node_agent_service["Agent<br/>remote sidecar<br/>[main.go]"]
  node_client_cli["Client CLI<br/>operator client<br/>[root.go]"]
  node_agentrs_runtime["Agent RS<br/>rust runtime<br/>[main.rs]"]
end

subgraph group_ui["User interfaces"]
  node_webapp["Webapp<br/>cljs spa<br/>[app.cljs]"]
  node_webapp_v2["Webapp V2<br/>react app<br/>[App.jsx]"]
end

subgraph group_shared["Shared libs"]
  node_common_proto["Proto common<br/>shared proto<br/>[transport.proto]"]
  node_common_types["Common types<br/>shared primitives<br/>[packet.go]"]
  node_libhoop["Libhoop<br/>low-level core<br/>[libhoop.go]"]
end

subgraph group_deploy["Packaging"]
  node_rootfs["Runtime image<br/>packaging<br/>[000001_init.up.sql]"]
  node_deployments["Deployments<br/>helm/docker<br/>[Chart.yaml]"]
end

node_gateway_api -->|"auth"| node_gateway_idp
node_gateway_api -->|"orchestrates"| node_gateway_services
node_gateway_api -->|"persists"| node_gateway_models
node_gateway_api -->|"publishes"| node_gateway_events
node_gateway_services -->|"uses"| node_gateway_models
node_gateway_services -->|"records"| node_gateway_audit
node_gateway_session -->|"feeds"| node_gateway_audit
node_gateway_transport -->|"dispatches"| node_gateway_broker
node_gateway_transport -->|"enforces"| node_gateway_plugins
node_gateway_transport -->|"captures"| node_gateway_session
node_gateway_transport -->|"adapts"| node_gateway_proxyproto
node_gateway_transport -->|"inspects"| node_gateway_rdp
node_gateway_broker -->|"routes"| node_gateway_proxyproto
node_gateway_rdp -->|"analyzes"| node_gateway_audit
node_agent_service -->|"rpc"| node_common_proto
node_client_cli -->|"admin api"| node_gateway_api
node_client_cli -->|"tunnels"| node_gateway_transport
node_agentrs_runtime -->|"ws/rpc"| node_common_proto
node_webapp -->|"admin ui"| node_gateway_api
node_webapp_v2 -->|"admin ui"| node_gateway_api
node_gateway_api -->|"deployed with"| node_rootfs
node_gateway_api -->|"shipped via"| node_deployments
node_agent_service -->|"shipped via"| node_deployments
node_common_types -->|"builds on"| node_libhoop
node_gateway_proxyproto -->|"parses"| node_common_types
node_gateway_rdp -->|"reuses"| node_libhoop

click node_gateway_api "https://github.com/hoophq/hoop/blob/main/gateway/api/server.go"
click node_gateway_idp "https://github.com/hoophq/hoop/blob/main/gateway/idp/core.go"
click node_gateway_models "https://github.com/hoophq/hoop/tree/main/gateway/models"
click node_gateway_services "https://github.com/hoophq/hoop/blob/main/gateway/services/session.go"
click node_gateway_events "https://github.com/hoophq/hoop/blob/main/gateway/events/publish.go"
click node_gateway_audit "https://github.com/hoophq/hoop/blob/main/gateway/audit/audit.go"
click node_gateway_session "https://github.com/hoophq/hoop/blob/main/gateway/session/wal/wal.go"
click node_gateway_transport "https://github.com/hoophq/hoop/blob/main/gateway/transport/server.go"
click node_gateway_broker "https://github.com/hoophq/hoop/blob/main/gateway/broker/protocol_manager.go"
click node_gateway_proxyproto "https://github.com/hoophq/hoop/blob/main/gateway/proxyproto/sshproxy/sshproxy.go"
click node_gateway_rdp "https://github.com/hoophq/hoop/blob/main/gateway/rdp/rdp.go"
click node_gateway_plugins "https://github.com/hoophq/hoop/blob/main/gateway/transport/plugins/review/review.go"
click node_agent_service "https://github.com/hoophq/hoop/blob/main/agent/main.go"
click node_client_cli "https://github.com/hoophq/hoop/blob/main/client/cmd/root.go"
click node_agentrs_runtime "https://github.com/hoophq/hoop/blob/main/agentrs/src/main.rs"
click node_webapp "https://github.com/hoophq/hoop/blob/main/webapp/src/webapp/app.cljs"
click node_webapp_v2 "https://github.com/hoophq/hoop/blob/main/webapp_v2/src/App.jsx"
click node_common_proto "https://github.com/hoophq/hoop/blob/main/common/proto/transport.proto"
click node_common_types "https://github.com/hoophq/hoop/blob/main/common/pgtypes/packet.go"
click node_libhoop "https://github.com/hoophq/hoop/blob/main/_libhoop/libhoop.go"
click node_rootfs "https://github.com/hoophq/hoop/blob/main/rootfs/app/migrations/000001_init.up.sql"
click node_deployments "https://github.com/hoophq/hoop/blob/main/deploy/helm-chart/chart/gateway/Chart.yaml"

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_gateway_api,node_gateway_idp,node_gateway_models,node_gateway_services,node_gateway_events,node_gateway_audit,node_gateway_session toneBlue
class node_gateway_transport,node_gateway_broker,node_gateway_proxyproto,node_gateway_rdp,node_gateway_plugins toneAmber
class node_agent_service,node_client_cli,node_agentrs_runtime toneMint
class node_webapp,node_webapp_v2 toneRose
class node_common_proto,node_common_types,node_libhoop toneIndigo
class node_rootfs,node_deployments toneTeal
```

## Components

### Gateway core

Control plane, APIs, persistence, and policy services.

- [Gateway API](https://github.com/hoophq/hoop/blob/main/gateway/api/server.go): http/admin surface · HTTP admin/API entrypoint for users, resources, sessions, reviews, integrations, and settings. · `gateway/api/server.go`
- [Identity](https://github.com/hoophq/hoop/blob/main/gateway/idp/core.go): auth/identity · Local, OIDC, SAML, machine identity, and external JWT auth boundaries. · `gateway/idp/core.go`
- [Models](https://github.com/hoophq/hoop/tree/main/gateway/models): db schema · Durable PostgreSQL-backed domain models and migrations for the control plane. · `gateway/models`
- [Services](https://github.com/hoophq/hoop/blob/main/gateway/services/session.go): domain services · Business logic for access requests, guardrails, data masking, sessions, and feature flags. · `gateway/services/session.go`
- [Events](https://github.com/hoophq/hoop/blob/main/gateway/events/publish.go): event pipeline · Event catalog, validation, derivation, publication, and routing into workers. · `gateway/events/publish.go`
- [Audit](https://github.com/hoophq/hoop/blob/main/gateway/audit/audit.go): compliance log · Redaction and audit record generation for searchable session and security logs. · `gateway/audit/audit.go`
- [Session WAL](https://github.com/hoophq/hoop/blob/main/gateway/session/wal/wal.go): append-only log · Session event logs and WAL formats used for replay and capture. · `gateway/session/wal/wal.go`

### Data plane

Live session transport, protocol handling, and policy enforcement.

- [Transport](https://github.com/hoophq/hoop/blob/main/gateway/transport/server.go): live proxy · Session transport server, interceptors, stream clients, system actions, and plugin pipelines. · `gateway/transport/server.go`
- [Broker](https://github.com/hoophq/hoop/blob/main/gateway/broker/protocol_manager.go): protocol broker · Protocol manager and live session broker that coordinate protocol-specific handlers. · `gateway/broker/protocol_manager.go`
- [Proxy adapters](https://github.com/hoophq/hoop/blob/main/gateway/proxyproto/sshproxy/sshproxy.go): protocol adapters · Protocol-specific proxy adapters for SSH, Postgres, SSM, HTTP, gRPC, and TLS termination. · `gateway/proxyproto/sshproxy/sshproxy.go`
- [RDP stack](https://github.com/hoophq/hoop/blob/main/gateway/rdp/rdp.go): rdp inspect · RDP parsing, recording, OCR, and analysis components. · `gateway/rdp/rdp.go`
- [Policy plugins](https://github.com/hoophq/hoop/blob/main/gateway/transport/plugins/review/review.go): enforcement plugins · Access control, audit, DLP, review, Slack, and webhook steps around live traffic. · `gateway/transport/plugins/review/review.go`

### Edge helpers

Operator client and remote agent runtimes.

- [Agent](https://github.com/hoophq/hoop/blob/main/agent/main.go): remote sidecar · Remote helper that provisions databases, runs backend-specific tasks, and connects back to gateway. · `agent/main.go`
- [Client CLI](https://github.com/hoophq/hoop/blob/main/client/cmd/root.go): operator client · CLI/daemon used for login, connect, session start, proxying, installs, and upgrades. · `client/cmd/root.go`
- [Agent RS](https://github.com/hoophq/hoop/blob/main/agentrs/src/main.rs): rust runtime · Rust companion runtime for websocket, TLS, proxy, and RDP-sensitive paths. · `agentrs/src/main.rs`

### User interfaces

Two generations of admin and session UIs.

- [Webapp](https://github.com/hoophq/hoop/blob/main/webapp/src/webapp/app.cljs): cljs spa · Legacy ClojureScript admin UI for management, sessions, resources, and workflows. · `webapp/src/webapp/app.cljs`
- [Webapp V2](https://github.com/hoophq/hoop/blob/main/webapp_v2/src/App.jsx): react app · Newer React/Vite admin UI with page-based features and service modules. · `webapp_v2/src/App.jsx`

### Shared libs

Common code, protocol types, and low-level primitives.

- [Proto common](https://github.com/hoophq/hoop/blob/main/common/proto/transport.proto): shared proto · Shared protobuf contracts for agent, client, gateway, transport, and system RPCs. · `common/proto/transport.proto`
- [Common types](https://github.com/hoophq/hoop/blob/main/common/pgtypes/packet.go): shared primitives · Protocol parsers, redactors, logging, backoff, client config, and utility libraries. · `common/pgtypes/packet.go`
- [Libhoop](https://github.com/hoophq/hoop/blob/main/_libhoop/libhoop.go): low-level core · Shared low-level proxy and redaction primitives used by protocol inspection code. · `_libhoop/libhoop.go`

### Packaging

Container, Helm, and migration/runtime assembly.

- [Runtime image](https://github.com/hoophq/hoop/blob/main/rootfs/app/migrations/000001_init.up.sql): packaging · Application image assembly, migrations, and bundled helper scripts for deployment/runtime. · `rootfs/app/migrations/000001_init.up.sql`
- [Deployments](https://github.com/hoophq/hoop/blob/main/deploy/helm-chart/chart/gateway/Chart.yaml): helm/docker · Docker, Compose, Helm, and AWS packaging for gateway and agent environments. · `deploy/helm-chart/chart/gateway/Chart.yaml`

## Connections

- Gateway API → Identity: auth · Delegates login and identity boundaries to local, OIDC, SAML, and machine identity flows.
- Gateway API → Services: orchestrates · API handlers call domain services for access requests, guardrails, sessions, and configuration.
- Gateway API → Models: persists · Reads and writes durable domain state through the PostgreSQL schema.
- Gateway API → Events: publishes · Emits routed events for integrations, audit, and asynchronous workflows.
- Services → Models: uses · Service layer persists and queries core business entities.
- Services → Audit: records · Service actions contribute to audit and compliance records.
- Session WAL → Audit: feeds · Session WAL and event logs are transformed into audit/searchable records.
- Transport → Broker: dispatches · Transport hands live streams to the broker for protocol coordination.
- Transport → Policy plugins: enforces · Live traffic passes through access control, DLP, review, Slack, and webhook steps.
- Transport → Session WAL: captures · Transport writes session activity into append-only event logs.
- Transport → Proxy adapters: adapts · Uses protocol-specific proxy adapters for SSH, Postgres, SSM, HTTP, gRPC, and TLS termination.
- Transport → RDP stack: inspects · Routes RDP traffic into parser, recorder, OCR, and analysis components.
- Broker → Proxy adapters: routes · Broker selects protocol handlers and forwards approved traffic.
- RDP stack → Audit: analyzes · RDP analysis contributes detections and session artifacts to compliance and review.
- Agent → Proto common: rpc · Communicates with gateway using shared protobuf contracts.
- Client CLI → Gateway API: admin api · CLI and daemon use the HTTP/API surface for login, sessions, resources, and administration.
- Client CLI → Transport: tunnels · Operator traffic is tunneled into the live gateway transport path.
- Agent RS → Proto common: ws/rpc · Rust runtime shares message contracts and session semantics with the rest of the platform.
- Webapp → Gateway API: admin ui · Legacy SPA talks to the gateway HTTP API for management and session views.
- Webapp V2 → Gateway API: admin ui · React/Vite UI consumes the same gateway API for modern administration flows.
- Gateway API → Runtime image: deployed with · Gateway runtime and schema migrations are packaged into the app image.
- Gateway API → Deployments: shipped via · Gateway is deployed through Docker, Helm, and cloud templates.
- Agent → Deployments: shipped via · Agent runtime is packaged for container and Helm-based deployment.
- Common types → Libhoop: builds on · Protocol and redaction helpers lean on low-level shared primitives.
- Proxy adapters → Common types: parses · Protocol adapters rely on shared packet/type definitions.
- RDP stack → Libhoop: reuses · RDP inspection shares low-level redaction and proxy primitives.
