# stasync/relay-dotnet architecture

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

- Interactive diagram: https://gitdiagram.com/stasync/relay-dotnet
- Repository: https://github.com/stasync/relay-dotnet

## Overview

Relay is a .NET UDP relay node, controlled by a backend over an authenticated HTTP API. The backend opens rooms; clients connect to a room using a token, join, and exchange packets that the room forwards. Room lifecycle events can trigger backend webhooks. The graph preserves the control plane, UDP forwarding, and rate-limiting capability documented or visible in the supplied material. Some runtime wiring is unsampled, so only documented or evidenced relationships are connected.

Main entry points: [`runtime/Room.cs`](https://github.com/stasync/relay-dotnet/blob/main/runtime/Room.cs) (Room lifecycle and forwarding), [`runtime/Entry.cs`](https://github.com/stasync/relay-dotnet/blob/main/runtime/Entry.cs) (Node startup), [`runtime/HttpServer.cs`](https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpServer.cs) (HTTP listener), [`runtime/HttpRequestHandler.cs`](https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpRequestHandler.cs) (API request handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_node["Node runtime"]
  node_node_entry["Node startup<br/>[Entry.cs]"]
  node_startup_args["Startup configuration"]
end

subgraph group_control["HTTP control plane"]
  node_http_server["HTTP listener<br/>[HttpServer.cs]"]
  node_routes["Route matching<br/>[RouteTemplate.cs]"]
  node_request_handler["API request handling"]
  node_http_errors["HTTP status errors"]
end

subgraph group_rooms["Room and UDP traffic"]
  node_room_settings["Room settings<br/>[RoomSettings.cs]"]
  node_room["Room lifecycle and forwarding<br/>[Room.cs]"]
  node_client_messages["Client message types"]
  node_room_messages["Room message types<br/>[RoomMessageType.cs]"]
  node_rate_tracker["Ingress rate limiter"]
end

subgraph group_hooks["Webhook integration"]
  node_webhook_sender["Webhook delivery and retry"]
end

node_backend(("Backend service"))
node_client(("UDP clients"))
node_backend_hooks(("Backend webhook receiver"))

node_backend -->|"calls API"| node_http_server
node_http_server -->|"dispatches requests"| node_request_handler
node_http_server -->|"matches routes"| node_routes
node_http_server -->|"handles status errors"| node_http_errors
node_request_handler -->|"parses settings"| node_room_settings
node_request_handler -->|"reads and closes"| node_room
node_request_handler -->|"opens room via callback"| node_node_entry
node_node_entry -->|"loads configuration"| node_startup_args
node_node_entry -->|"starts listener"| node_http_server
node_node_entry -->|"binds handler"| node_request_handler
node_node_entry -->|"creates and starts"| node_room
node_room_settings -.->|"configures"| node_room
node_client -->|"joins and sends UDP"| node_room
node_room -->|"decodes message types"| node_client_messages
node_room -.->|"emits room messages"| node_room_messages
node_room -->|"registers rate limiter"| node_rate_tracker
node_node_entry -->|"sends lifecycle events"| node_webhook_sender
node_webhook_sender -->|"posts webhooks"| node_backend_hooks

click node_node_entry "https://github.com/stasync/relay-dotnet/blob/main/runtime/Entry.cs"
click node_startup_args "https://github.com/stasync/relay-dotnet/blob/main/runtime/StartupArguments.cs"
click node_http_server "https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpServer.cs"
click node_routes "https://github.com/stasync/relay-dotnet/blob/main/runtime/RouteTemplate.cs"
click node_request_handler "https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpRequestHandler.cs"
click node_http_errors "https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpStatusException.cs"
click node_room_settings "https://github.com/stasync/relay-dotnet/blob/main/runtime/RoomSettings.cs"
click node_room "https://github.com/stasync/relay-dotnet/blob/main/runtime/Room.cs"
click node_client_messages "https://github.com/stasync/relay-dotnet/blob/main/runtime/ClientMessageType.cs"
click node_room_messages "https://github.com/stasync/relay-dotnet/blob/main/runtime/RoomMessageType.cs"
click node_rate_tracker "https://github.com/stasync/relay-dotnet/blob/main/runtime/IncomingDataAmountTracker.cs"
click node_webhook_sender "https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpWebhookSender.cs"

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_node_entry,node_startup_args,node_client toneBlue
class node_http_server,node_routes,node_request_handler,node_http_errors toneAmber
class node_room_settings,node_room,node_client_messages,node_room_messages,node_rate_tracker,node_backend_hooks toneMint
class node_webhook_sender toneRose
class node_backend toneIndigo
```

## Components

### Node runtime

- [Node startup](https://github.com/stasync/relay-dotnet/blob/main/runtime/Entry.cs): `runtime/Entry.cs`
- [Startup configuration](https://github.com/stasync/relay-dotnet/blob/main/runtime/StartupArguments.cs): `runtime/StartupArguments.cs`

### HTTP control plane

- [HTTP listener](https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpServer.cs): `runtime/HttpServer.cs`
- [Route matching](https://github.com/stasync/relay-dotnet/blob/main/runtime/RouteTemplate.cs): `runtime/RouteTemplate.cs`
- [API request handling](https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpRequestHandler.cs): `runtime/HttpRequestHandler.cs`
- [HTTP status errors](https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpStatusException.cs): `runtime/HttpStatusException.cs`

### Room and UDP traffic

- [Room settings](https://github.com/stasync/relay-dotnet/blob/main/runtime/RoomSettings.cs): `runtime/RoomSettings.cs`
- [Room lifecycle and forwarding](https://github.com/stasync/relay-dotnet/blob/main/runtime/Room.cs): `runtime/Room.cs`
- [Client message types](https://github.com/stasync/relay-dotnet/blob/main/runtime/ClientMessageType.cs): `runtime/ClientMessageType.cs`
- [Room message types](https://github.com/stasync/relay-dotnet/blob/main/runtime/RoomMessageType.cs): `runtime/RoomMessageType.cs`
- [Ingress rate limiter](https://github.com/stasync/relay-dotnet/blob/main/runtime/IncomingDataAmountTracker.cs): `runtime/IncomingDataAmountTracker.cs`

### Webhook integration

- [Webhook delivery and retry](https://github.com/stasync/relay-dotnet/blob/main/runtime/HttpWebhookSender.cs): `runtime/HttpWebhookSender.cs`

### Other components

- **Backend service**
- **UDP clients**
- **Backend webhook receiver**

## Connections

- Backend service → HTTP listener: calls API (evidence: `README.md`)
- HTTP listener → API request handling: dispatches requests (evidence: `runtime/Entry.cs`)
- HTTP listener → Route matching: matches routes (evidence: `runtime/HttpServer.cs`)
- HTTP listener → HTTP status errors: handles status errors (evidence: `runtime/HttpServer.cs`)
- API request handling → Room settings: parses settings (evidence: `runtime/HttpRequestHandler.cs`)
- API request handling → Room lifecycle and forwarding: reads and closes (evidence: `runtime/HttpRequestHandler.cs`)
- API request handling → Node startup: opens room via callback (evidence: `runtime/Entry.cs`)
- Node startup → Startup configuration: loads configuration (evidence: `runtime/Entry.cs`)
- Node startup → HTTP listener: starts listener (evidence: `runtime/Entry.cs`)
- Node startup → API request handling: binds handler (evidence: `runtime/Entry.cs`)
- Node startup → Room lifecycle and forwarding: creates and starts (evidence: `runtime/Entry.cs`)
- Room settings → Room lifecycle and forwarding: configures (evidence: `runtime/Room.cs`)
- UDP clients → Room lifecycle and forwarding: joins and sends UDP (evidence: `README.md`)
- Room lifecycle and forwarding → Client message types: decodes message types (evidence: `runtime/Room.cs`)
- Room lifecycle and forwarding → Room message types: emits room messages (evidence: `runtime/Room.cs`)
- Room lifecycle and forwarding → Ingress rate limiter: registers rate limiter (evidence: `runtime/Room.cs`)
- Node startup → Webhook delivery and retry: sends lifecycle events (evidence: `runtime/Entry.cs`)
- Webhook delivery and retry → Backend webhook receiver: posts webhooks (evidence: `runtime/HttpWebhookSender.cs`)
