# jack-avery/ansible-tf2network-relay architecture

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

- Interactive diagram: https://gitdiagram.com/jack-avery/ansible-tf2network-relay
- Repository: https://github.com/jack-avery/ansible-tf2network-relay

## Overview

This is a Discord bot that relays messages from configured Discord channels into Team Fortress 2 servers and provides `/rcon` and `/servers` slash commands. Its main workflow is Discord message handling, formatting and sanitization, then RCON dispatch; command interactions are dispatched to their handlers and returned as embeds. A background task refreshes server status for `/servers`. The README documents the required SourceMod plugin for displaying relayed messages; unsampled plugin-side wiring is not inferred.

Main entry points: [`src/main.rs`](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs) (Event handling), [`src/commands/rcon.rs`](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/commands/rcon.rs) (RCON command), [`src/commands/servers.rs`](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/commands/servers.rs) (Servers command), [`src/state.rs`](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/state.rs) (Status refresh)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_main["Event handling<br/>[main.rs]"]
  node_relay["Message formatting<br/>[main.rs]"]
  node_rcon_transport["RCON transport<br/>[main.rs]"]
  node_errors["Command errors<br/>[error.rs]"]
end

subgraph group_commands["Slash commands"]
  node_rcon_command["RCON command<br/>[rcon.rs]"]
  node_servers_command["Servers command<br/>[servers.rs]"]
end

subgraph group_server["Server state"]
  node_state["Status refresh<br/>[state.rs]"]
  node_state_cache[("Host status cache<br/>[state.rs]")]
end

subgraph group_configuration["Configuration"]
  node_config["Access configuration<br/>[config.rs]"]
  node_manifest["Server manifest<br/>[manifest.rs]"]
end

node_discord(("Discord users and gateway"))
node_manifest_file["manifest.yml"]
node_environment["Environment variables"]
node_game_servers(("TF2 servers"))
node_sourcemod["SourceMod relay plugin"]

node_discord -->|"sends events"| node_main
node_main -->|"handles messages"| node_relay
node_relay -->|"sends relay command"| node_rcon_transport
node_rcon_transport -->|"executes RCON"| node_game_servers
node_game_servers -.->|"plugin displays relay"| node_sourcemod
node_main -->|"dispatches command"| node_rcon_command
node_main -->|"dispatches command"| node_servers_command
node_main -->|"loads config"| node_config
node_environment -->|"provides RCON_USERS"| node_config
node_rcon_command -->|"checks access"| node_config
node_main -->|"loads manifest"| node_manifest
node_manifest_file -->|"provides server data"| node_manifest
node_main -->|"starts refresh"| node_state
node_state -->|"reads host definitions"| node_manifest
node_state -->|"queries status"| node_game_servers
node_state -->|"updates status"| node_state_cache
node_rcon_command -->|"looks up server"| node_state_cache
node_servers_command -->|"reads all status"| node_state_cache
node_rcon_command -->|"runs command"| node_game_servers
node_rcon_command -->|"returns failures"| node_errors
node_servers_command -->|"returns failures"| node_errors
node_rcon_command -->|"returns embed or error"| node_main
node_servers_command -->|"returns embed or error"| node_main
node_main -->|"replies with embed"| node_discord

click node_main "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs"
click node_relay "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs"
click node_rcon_transport "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs"
click node_rcon_command "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/commands/rcon.rs"
click node_servers_command "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/commands/servers.rs"
click node_config "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/config.rs"
click node_manifest "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/manifest.rs"
click node_state "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/state.rs"
click node_state_cache "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/state.rs"
click node_errors "https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/error.rs"

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_main,node_relay,node_rcon_transport,node_errors,node_discord toneBlue
class node_rcon_command,node_servers_command toneAmber
class node_state,node_state_cache,node_game_servers toneMint
class node_config,node_manifest toneRose
class node_manifest_file,node_environment,node_sourcemod toneIndigo
```

## Components

### Bot runtime

- [Event handling](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs): `src/main.rs`
- [Message formatting](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs): `src/main.rs`
- [RCON transport](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/main.rs): `src/main.rs`
- [Command errors](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/error.rs): `src/error.rs`

### Slash commands

- [RCON command](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/commands/rcon.rs): `src/commands/rcon.rs`
- [Servers command](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/commands/servers.rs): `src/commands/servers.rs`

### Server state

- [Status refresh](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/state.rs): `src/state.rs`
- [Host status cache](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/state.rs): `src/state.rs`

### Configuration

- [Access configuration](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/config.rs): `src/config.rs`
- [Server manifest](https://github.com/jack-avery/ansible-tf2network-relay/blob/main/src/manifest.rs): `src/manifest.rs`

### Other components

- **Discord users and gateway**
- **manifest.yml**
- **Environment variables**
- **TF2 servers**
- **SourceMod relay plugin**

## Connections

- Discord users and gateway → Event handling: sends events
- Event handling → Message formatting: handles messages
- Message formatting → RCON transport: sends relay command
- RCON transport → TF2 servers: executes RCON
- TF2 servers → SourceMod relay plugin: plugin displays relay
- Event handling → RCON command: dispatches command
- Event handling → Servers command: dispatches command
- Event handling → Access configuration: loads config
- Environment variables → Access configuration: provides RCON_USERS
- RCON command → Access configuration: checks access
- Event handling → Server manifest: loads manifest
- manifest.yml → Server manifest: provides server data
- Event handling → Status refresh: starts refresh
- Status refresh → Server manifest: reads host definitions
- Status refresh → TF2 servers: queries status
- Status refresh → Host status cache: updates status
- RCON command → Host status cache: looks up server
- Servers command → Host status cache: reads all status
- RCON command → TF2 servers: runs command
- RCON command → Command errors: returns failures
- Servers command → Command errors: returns failures
- RCON command → Event handling: returns embed or error
- Servers command → Event handling: returns embed or error
- Event handling → Discord users and gateway: replies with embed
