# ngthdong/egressa architecture

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

- Interactive diagram: https://gitdiagram.com/ngthdong/egressa
- Repository: https://github.com/ngthdong/egressa

## Overview

Egressa is a multi-gateway VPN that measures path quality and can migrate a client session to a better access path or egress gateway. The main workflow is client join/connect, controller-managed session and gateway state, per-gateway path measurement, migration decisions, and tunnel forwarding. The graph also includes the documented IPsec option and operator observability/network-emulation tools. Several subsystem links rely on the SOURCE INDEX or explicit command comments; unsampled implementations are not treated as inspected.

Main entry points: [`internal/client/agent.go`](https://github.com/ngthdong/egressa/blob/main/internal/client/agent.go) (Client agent), [`internal/controller/server.go`](https://github.com/ngthdong/egressa/blob/main/internal/controller/server.go) (Controller API), [`internal/gateway/agent.go`](https://github.com/ngthdong/egressa/blob/main/internal/gateway/agent.go) (Gateway agent), [`cmd/vpnctl/main.go`](https://github.com/ngthdong/egressa/blob/main/cmd/vpnctl/main.go) (Operator tooling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client workflow"]
  node_egressa_cli["Join and connect CLI<br/>[main.go]"]
  node_client_agent["Client agent<br/>[agent.go]"]
  node_client_state["Client status<br/>[status.go]"]
end

subgraph group_control["Control plane"]
  node_controller_api["Controller API<br/>[server.go]"]
  node_control_state[("Membership and policy")]
  node_persistence[("State persistence")]
end

subgraph group_optimize["Measurement and migration"]
  node_measurement["Path measurement"]
  node_path_monitor["Probe monitor<br/>[monitor.go]"]
  node_decision["Path decision<br/>[decide.go]"]
  node_handoff["Migration handoff"]
end

subgraph group_data["Gateway and dataplane"]
  node_gateway_agent["Gateway agent<br/>[agent.go]"]
  node_tunnel["WireGuard tunnel"]
  node_ipsec["IPsec integration"]
end

subgraph group_ops["Operations"]
  node_telemetry["Metrics and tracing"]
  node_vpnctl["Operator tooling<br/>[main.go]"]
  node_netem["Network emulation"]
end

node_user(("VPN user"))

node_user -->|"runs commands"| node_egressa_cli
node_egressa_cli -->|"starts agent"| node_client_agent
node_client_agent -->|"opens and updates session"| node_controller_api
node_controller_api -->|"reads and updates"| node_control_state
node_controller_api -->|"uses configured store"| node_persistence
node_client_agent -->|"starts probes"| node_path_monitor
node_path_monitor -->|"records probe results"| node_measurement
node_client_agent -->|"uses path measurements"| node_measurement
node_client_agent -->|"evaluates paths"| node_decision
node_decision -->|"checks cutover"| node_handoff
node_client_agent -->|"commits migration"| node_controller_api
node_client_agent -->|"configures client peers"| node_tunnel
node_gateway_agent -->|"registers and follows state"| node_controller_api
node_gateway_agent -->|"configures forwarding"| node_tunnel
node_client_agent -.->|"uses optional backend"| node_ipsec
node_gateway_agent -.->|"configures optional service"| node_ipsec
node_client_agent -->|"publishes metrics"| node_telemetry
node_vpnctl -->|"runs shaping commands"| node_netem
node_vpnctl -->|"reads migration traces"| node_telemetry
node_client_agent -->|"writes status"| node_client_state

click node_egressa_cli "https://github.com/ngthdong/egressa/blob/main/cmd/egressa/main.go"
click node_client_agent "https://github.com/ngthdong/egressa/blob/main/internal/client/agent.go"
click node_client_state "https://github.com/ngthdong/egressa/blob/main/internal/client/status.go"
click node_controller_api "https://github.com/ngthdong/egressa/blob/main/internal/controller/server.go"
click node_control_state "https://github.com/ngthdong/egressa/tree/main/internal/control"
click node_persistence "https://github.com/ngthdong/egressa/tree/main/internal/controller"
click node_measurement "https://github.com/ngthdong/egressa/tree/main/internal/measurement"
click node_path_monitor "https://github.com/ngthdong/egressa/blob/main/internal/pathmon/monitor.go"
click node_decision "https://github.com/ngthdong/egressa/blob/main/internal/client/decide.go"
click node_handoff "https://github.com/ngthdong/egressa/tree/main/internal/handoff"
click node_gateway_agent "https://github.com/ngthdong/egressa/blob/main/internal/gateway/agent.go"
click node_tunnel "https://github.com/ngthdong/egressa/tree/main/internal/tunnel"
click node_ipsec "https://github.com/ngthdong/egressa/tree/main/internal/ipsec"
click node_telemetry "https://github.com/ngthdong/egressa/tree/main/internal/telemetry"
click node_vpnctl "https://github.com/ngthdong/egressa/blob/main/cmd/vpnctl/main.go"
click node_netem "https://github.com/ngthdong/egressa/tree/main/internal/netem"

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_egressa_cli,node_client_agent,node_client_state,node_user toneBlue
class node_controller_api,node_control_state,node_persistence toneAmber
class node_measurement,node_path_monitor,node_decision,node_handoff toneMint
class node_gateway_agent,node_tunnel,node_ipsec toneRose
class node_telemetry,node_vpnctl,node_netem toneIndigo
```

## Components

### Client workflow

- [Join and connect CLI](https://github.com/ngthdong/egressa/blob/main/cmd/egressa/main.go): `cmd/egressa/main.go`
- [Client agent](https://github.com/ngthdong/egressa/blob/main/internal/client/agent.go): `internal/client/agent.go`
- [Client status](https://github.com/ngthdong/egressa/blob/main/internal/client/status.go): `internal/client/status.go`

### Control plane

- [Controller API](https://github.com/ngthdong/egressa/blob/main/internal/controller/server.go): `internal/controller/server.go`
- [Membership and policy](https://github.com/ngthdong/egressa/tree/main/internal/control): `internal/control`
- [State persistence](https://github.com/ngthdong/egressa/tree/main/internal/controller): `internal/controller`

### Measurement and migration

- [Path measurement](https://github.com/ngthdong/egressa/tree/main/internal/measurement): `internal/measurement`
- [Probe monitor](https://github.com/ngthdong/egressa/blob/main/internal/pathmon/monitor.go): `internal/pathmon/monitor.go`
- [Path decision](https://github.com/ngthdong/egressa/blob/main/internal/client/decide.go): `internal/client/decide.go`
- [Migration handoff](https://github.com/ngthdong/egressa/tree/main/internal/handoff): `internal/handoff`

### Gateway and dataplane

- [Gateway agent](https://github.com/ngthdong/egressa/blob/main/internal/gateway/agent.go): `internal/gateway/agent.go`
- [WireGuard tunnel](https://github.com/ngthdong/egressa/tree/main/internal/tunnel): `internal/tunnel`
- [IPsec integration](https://github.com/ngthdong/egressa/tree/main/internal/ipsec): `internal/ipsec`

### Operations

- [Metrics and tracing](https://github.com/ngthdong/egressa/tree/main/internal/telemetry): `internal/telemetry`
- [Operator tooling](https://github.com/ngthdong/egressa/blob/main/cmd/vpnctl/main.go): `cmd/vpnctl/main.go`
- [Network emulation](https://github.com/ngthdong/egressa/tree/main/internal/netem): `internal/netem`

### Other components

- **VPN user**

## Connections

- VPN user → Join and connect CLI: runs commands (evidence: `cmd/egressa/main.go`)
- Join and connect CLI → Client agent: starts agent (evidence: `cmd/egressa/main.go`)
- Client agent → Controller API: opens and updates session
- Controller API → Membership and policy: reads and updates (evidence: `internal/controller/server.go`)
- Controller API → State persistence: uses configured store
- Client agent → Probe monitor: starts probes (evidence: `internal/client/agent.go`)
- Probe monitor → Path measurement: records probe results (evidence: `internal/pathmon/monitor.go`)
- Client agent → Path measurement: uses path measurements (evidence: `internal/client/agent.go`)
- Client agent → Path decision: evaluates paths (evidence: `internal/client/agent.go`)
- Path decision → Migration handoff: checks cutover (evidence: `internal/client/decide.go`)
- Client agent → Controller API: commits migration
- Client agent → WireGuard tunnel: configures client peers (evidence: `internal/client/agent.go`)
- Gateway agent → Controller API: registers and follows state
- Gateway agent → WireGuard tunnel: configures forwarding (evidence: `internal/gateway/agent.go`)
- Client agent → IPsec integration: uses optional backend
- Gateway agent → IPsec integration: configures optional service
- Client agent → Metrics and tracing: publishes metrics (evidence: `internal/client/agent.go`)
- Operator tooling → Network emulation: runs shaping commands (evidence: `cmd/vpnctl/main.go`)
- Operator tooling → Metrics and tracing: reads migration traces (evidence: `cmd/vpnctl/main.go`)
- Client agent → Client status: writes status (evidence: `internal/client/agent.go`)
