# ysamouhos/brew-server architecture

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

- Interactive diagram: https://gitdiagram.com/ysamouhos/brew-server
- Repository: https://github.com/ysamouhos/brew-server

## Overview

brew-server is an experimental Rust service that links MidnightBlue TETRA Basestations and Flowstations. Its main workflow accepts Brew client connections, decodes protocol messages, routes calls and SDS between clients, and records monitoring data. Separate branches provide SIP voice interconnection, server federation, station telemetry and position reporting, administration, and active/standby high availability. The source index identifies important modules, but many implementation details were not sampled; edges below are limited to documented relationships or references shown there.

Main entry points: [`src/router.rs`](https://github.com/ysamouhos/brew-server/blob/main/src/router.rs) (Call and SDS router), [`src/state.rs`](https://github.com/ysamouhos/brew-server/blob/main/src/state.rs) (Shared runtime state), [`src/dashboard.rs`](https://github.com/ysamouhos/brew-server/blob/main/src/dashboard.rs) (Admin dashboard), [`src/server.rs`](https://github.com/ysamouhos/brew-server/blob/main/src/server.rs) (Brew server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Brew core"]
  node_main["Service startup<br/>[main.rs]"]
  node_server["Brew server<br/>[server.rs]"]
  node_protocol["Brew protocol<br/>[protocol.rs]"]
  node_router["Call and SDS router<br/>[router.rs]"]
  node_state["Shared runtime state<br/>[state.rs]"]
  node_config["Configuration<br/>[config.rs]"]
  node_blacklist["ISSI blacklist<br/>[blacklist.rs]"]
  node_emergency["Emergency calls<br/>[emergency.rs]"]
end

subgraph group_voice["Voice and messaging"]
  node_siptransport["SIP transport<br/>[transport.rs]"]
  node_siprouting["SIP call routing<br/>[routing.rs]"]
  node_sipbridge["SIP-Brew bridge<br/>[bridge.rs]"]
  node_sipmedia["RTP media relay<br/>[media.rs]"]
  node_transcode["Voice transcoding<br/>[task.rs]"]
  node_sms["SMS center<br/>[sms_center.rs]"]
end

subgraph group_network["Federation and telemetry"]
  node_federation["Federation links<br/>[federation.rs]"]
  node_fedroute["Federation routing<br/>[fedroute.rs]"]
  node_telemetry["Station telemetry<br/>[telemetry.rs]"]
  node_position["Position reporting<br/>[position.rs]"]
  node_aprs["APRS reporting<br/>[aprs.rs]"]
  node_fsnet["WebSocket networking<br/>[fsnet.rs]"]
end

subgraph group_ops["Operations"]
  node_dashboard["Admin dashboard<br/>[dashboard.rs]"]
  node_control["Control commands<br/>[control.rs]"]
  node_monitor["Call monitoring<br/>[monitor.rs]"]
  node_store[("History store<br/>[store.rs]")]
end

subgraph group_ha["High availability"]
  node_ha["HA election and VIP<br/>[ha.rs]"]
  node_harepl["HA replication<br/>[ha_repl.rs]"]
end

node_stations(("TETRA stations"))

node_stations -->|"connect"| node_server
node_main -->|"starts"| node_server
node_main -->|"loads"| node_config
node_server -->|"decodes"| node_protocol
node_server -->|"uses"| node_state
node_router -->|"routes messages"| node_protocol
node_router -->|"reads and updates"| node_state
node_router -->|"reports delivery"| node_sms
node_router -->|"routes remotely"| node_fedroute
node_router -->|"checks"| node_blacklist
node_router -->|"uses"| node_siprouting
node_router -->|"handles calls"| node_emergency
node_siptransport -->|"resolves calls"| node_siprouting
node_siptransport -->|"bridges calls"| node_sipbridge
node_sipbridge -->|"relays media"| node_sipmedia
node_sipbridge -->|"uses"| node_transcode
node_federation -->|"exchanges routes"| node_fedroute
node_federation -->|"serves links"| node_fsnet
node_telemetry -->|"receives station data"| node_fsnet
node_telemetry -->|"advertises positions"| node_fedroute
node_aprs -->|"reports positions"| node_position
node_dashboard -->|"shows status"| node_monitor
node_dashboard -->|"manages messages"| node_sms
node_dashboard -->|"controls role"| node_ha
node_dashboard -->|"reads state"| node_state
node_control -->|"updates control state"| node_state
node_monitor -->|"persists history"| node_store
node_state -->|"opens"| node_store
node_ha -->|"replicates state"| node_harepl
node_ha -->|"coordinates role"| node_state

click node_main "https://github.com/ysamouhos/brew-server/blob/main/src/main.rs"
click node_server "https://github.com/ysamouhos/brew-server/blob/main/src/server.rs"
click node_protocol "https://github.com/ysamouhos/brew-server/blob/main/src/protocol.rs"
click node_router "https://github.com/ysamouhos/brew-server/blob/main/src/router.rs"
click node_state "https://github.com/ysamouhos/brew-server/blob/main/src/state.rs"
click node_config "https://github.com/ysamouhos/brew-server/blob/main/src/config.rs"
click node_blacklist "https://github.com/ysamouhos/brew-server/blob/main/src/blacklist.rs"
click node_emergency "https://github.com/ysamouhos/brew-server/blob/main/src/emergency.rs"
click node_siptransport "https://github.com/ysamouhos/brew-server/blob/main/src/sip/transport.rs"
click node_siprouting "https://github.com/ysamouhos/brew-server/blob/main/src/sip/routing.rs"
click node_sipbridge "https://github.com/ysamouhos/brew-server/blob/main/src/sip/bridge.rs"
click node_sipmedia "https://github.com/ysamouhos/brew-server/blob/main/src/sip/media.rs"
click node_transcode "https://github.com/ysamouhos/brew-server/blob/main/src/transcode/task.rs"
click node_sms "https://github.com/ysamouhos/brew-server/blob/main/src/sms_center.rs"
click node_federation "https://github.com/ysamouhos/brew-server/blob/main/src/federation.rs"
click node_fedroute "https://github.com/ysamouhos/brew-server/blob/main/src/fedroute.rs"
click node_telemetry "https://github.com/ysamouhos/brew-server/blob/main/src/telemetry.rs"
click node_position "https://github.com/ysamouhos/brew-server/blob/main/src/position.rs"
click node_aprs "https://github.com/ysamouhos/brew-server/blob/main/src/aprs.rs"
click node_fsnet "https://github.com/ysamouhos/brew-server/blob/main/src/fsnet.rs"
click node_dashboard "https://github.com/ysamouhos/brew-server/blob/main/src/dashboard.rs"
click node_control "https://github.com/ysamouhos/brew-server/blob/main/src/control.rs"
click node_monitor "https://github.com/ysamouhos/brew-server/blob/main/src/monitor.rs"
click node_store "https://github.com/ysamouhos/brew-server/blob/main/src/store.rs"
click node_ha "https://github.com/ysamouhos/brew-server/blob/main/src/ha.rs"
click node_harepl "https://github.com/ysamouhos/brew-server/blob/main/src/ha_repl.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_server,node_protocol,node_router,node_state,node_config,node_blacklist,node_emergency toneBlue
class node_siptransport,node_siprouting,node_sipbridge,node_sipmedia,node_transcode,node_sms toneAmber
class node_federation,node_fedroute,node_telemetry,node_position,node_aprs,node_fsnet toneMint
class node_dashboard,node_control,node_monitor,node_store toneRose
class node_ha,node_harepl,node_stations toneIndigo
```

## Components

### Brew core

- [Service startup](https://github.com/ysamouhos/brew-server/blob/main/src/main.rs): `src/main.rs`
- [Brew server](https://github.com/ysamouhos/brew-server/blob/main/src/server.rs): `src/server.rs`
- [Brew protocol](https://github.com/ysamouhos/brew-server/blob/main/src/protocol.rs): `src/protocol.rs`
- [Call and SDS router](https://github.com/ysamouhos/brew-server/blob/main/src/router.rs): `src/router.rs`
- [Shared runtime state](https://github.com/ysamouhos/brew-server/blob/main/src/state.rs): `src/state.rs`
- [Configuration](https://github.com/ysamouhos/brew-server/blob/main/src/config.rs): `src/config.rs`
- [ISSI blacklist](https://github.com/ysamouhos/brew-server/blob/main/src/blacklist.rs): `src/blacklist.rs`
- [Emergency calls](https://github.com/ysamouhos/brew-server/blob/main/src/emergency.rs): `src/emergency.rs`

### Voice and messaging

- [SIP transport](https://github.com/ysamouhos/brew-server/blob/main/src/sip/transport.rs): `src/sip/transport.rs`
- [SIP call routing](https://github.com/ysamouhos/brew-server/blob/main/src/sip/routing.rs): `src/sip/routing.rs`
- [SIP-Brew bridge](https://github.com/ysamouhos/brew-server/blob/main/src/sip/bridge.rs): `src/sip/bridge.rs`
- [RTP media relay](https://github.com/ysamouhos/brew-server/blob/main/src/sip/media.rs): `src/sip/media.rs`
- [Voice transcoding](https://github.com/ysamouhos/brew-server/blob/main/src/transcode/task.rs): `src/transcode/task.rs`
- [SMS center](https://github.com/ysamouhos/brew-server/blob/main/src/sms_center.rs): `src/sms_center.rs`

### Federation and telemetry

- [Federation links](https://github.com/ysamouhos/brew-server/blob/main/src/federation.rs): `src/federation.rs`
- [Federation routing](https://github.com/ysamouhos/brew-server/blob/main/src/fedroute.rs): `src/fedroute.rs`
- [Station telemetry](https://github.com/ysamouhos/brew-server/blob/main/src/telemetry.rs): `src/telemetry.rs`
- [Position reporting](https://github.com/ysamouhos/brew-server/blob/main/src/position.rs): `src/position.rs`
- [APRS reporting](https://github.com/ysamouhos/brew-server/blob/main/src/aprs.rs): `src/aprs.rs`
- [WebSocket networking](https://github.com/ysamouhos/brew-server/blob/main/src/fsnet.rs): `src/fsnet.rs`

### Operations

- [Admin dashboard](https://github.com/ysamouhos/brew-server/blob/main/src/dashboard.rs): `src/dashboard.rs`
- [Control commands](https://github.com/ysamouhos/brew-server/blob/main/src/control.rs): `src/control.rs`
- [Call monitoring](https://github.com/ysamouhos/brew-server/blob/main/src/monitor.rs): `src/monitor.rs`
- [History store](https://github.com/ysamouhos/brew-server/blob/main/src/store.rs): `src/store.rs`

### High availability

- [HA election and VIP](https://github.com/ysamouhos/brew-server/blob/main/src/ha.rs): `src/ha.rs`
- [HA replication](https://github.com/ysamouhos/brew-server/blob/main/src/ha_repl.rs): `src/ha_repl.rs`

### Other components

- **TETRA stations**

## Connections

- TETRA stations → Brew server: connect (evidence: `README.md`)
- Service startup → Brew server: starts (evidence: `src/main.rs`)
- Service startup → Configuration: loads (evidence: `src/main.rs`)
- Brew server → Brew protocol: decodes (evidence: `src/server.rs`)
- Brew server → Shared runtime state: uses (evidence: `src/server.rs`)
- Call and SDS router → Brew protocol: routes messages (evidence: `src/router.rs`)
- Call and SDS router → Shared runtime state: reads and updates (evidence: `src/router.rs`)
- Call and SDS router → SMS center: reports delivery (evidence: `src/router.rs`)
- Call and SDS router → Federation routing: routes remotely (evidence: `src/router.rs`)
- Call and SDS router → ISSI blacklist: checks (evidence: `src/router.rs`)
- Call and SDS router → SIP call routing: uses (evidence: `src/router.rs`)
- Call and SDS router → Emergency calls: handles calls (evidence: `src/emergency.rs`)
- SIP transport → SIP call routing: resolves calls (evidence: `src/sip/transport.rs`)
- SIP transport → SIP-Brew bridge: bridges calls (evidence: `src/sip/transport.rs`)
- SIP-Brew bridge → RTP media relay: relays media (evidence: `src/sip/bridge.rs`)
- SIP-Brew bridge → Voice transcoding: uses (evidence: `src/sip/bridge.rs`)
- Federation links → Federation routing: exchanges routes (evidence: `src/federation.rs`)
- Federation links → WebSocket networking: serves links (evidence: `src/federation.rs`)
- Station telemetry → WebSocket networking: receives station data (evidence: `src/telemetry.rs`)
- Station telemetry → Federation routing: advertises positions (evidence: `src/telemetry.rs`)
- APRS reporting → Position reporting: reports positions (evidence: `src/aprs.rs`)
- Admin dashboard → Call monitoring: shows status (evidence: `src/dashboard.rs`)
- Admin dashboard → SMS center: manages messages (evidence: `src/dashboard.rs`)
- Admin dashboard → HA election and VIP: controls role (evidence: `src/dashboard.rs`)
- Admin dashboard → Shared runtime state: reads state (evidence: `src/dashboard.rs`)
- Control commands → Shared runtime state: updates control state (evidence: `src/control.rs`)
- Call monitoring → History store: persists history (evidence: `src/monitor.rs`)
- Shared runtime state → History store: opens (evidence: `src/state.rs`)
- HA election and VIP → HA replication: replicates state (evidence: `src/ha.rs`)
- HA election and VIP → Shared runtime state: coordinates role (evidence: `src/ha.rs`)
