# lexi1986/unifi-sonar architecture

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

- Interactive diagram: https://gitdiagram.com/lexi1986/unifi-sonar
- Repository: https://github.com/lexi1986/unifi-sonar

## Overview

UniFi Sonar is a self-hosted network monitoring and troubleshooting dashboard. Its main workflow polls a UniFi controller (or simulated network), normalizes and stores observations, evaluates issues and history, then serves a dashboard and integrations. Separate branches add DNS-filter analysis, security and segmentation checks, internet diagnostics, notifications, and Home Assistant MQTT. Edges follow sampled excerpts, SOURCE INDEX references, or README statements; some capabilities are documented but their internal wiring was not sampled.

Main entry points: [`app/collector.py`](https://github.com/lexi1986/unifi-sonar/blob/main/app/collector.py) (Polling collector), [`app/main.py`](https://github.com/lexi1986/unifi-sonar/blob/main/app/main.py) (API server), [`app/rules.py`](https://github.com/lexi1986/unifi-sonar/blob/main/app/rules.py) (Issue detection), [`app/unifi_client.py`](https://github.com/lexi1986/unifi-sonar/blob/main/app/unifi_client.py) (UniFi client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Monitoring runtime"]
  node_config["Settings<br/>[config.py]"]
  node_collector["Polling collector<br/>[collector.py]"]
  node_unifi["UniFi client<br/>[unifi_client.py]"]
  node_mock["Demo network<br/>[mock.py]"]
  node_db[("History store<br/>[db.py]")]
end

subgraph group_analysis["Network analysis"]
  node_rules["Issue detection<br/>[rules.py]"]
  node_rules_extra["Extended checks<br/>[rules_extra.py]"]
  node_channels["Channel analysis<br/>[channels.py]"]
  node_changes["Change timeline<br/>[changes.py]"]
  node_bufferbloat["Bufferbloat tests<br/>[bufferbloat.py]"]
  node_identify["Device identification<br/>[identify.py]"]
  node_schedules["Pause schedules<br/>[schedules.py]"]
end

subgraph group_security["Security and DNS"]
  node_segments["Network segments<br/>[segments.py]"]
  node_adguard["AdGuard analysis<br/>[adguard.py]"]
  node_pihole["Pi-hole analysis<br/>[pihole.py]"]
  node_advisories["Firmware advisories<br/>[advisories.py]"]
  node_vulnscan["Vulnerability checks<br/>[vulnscan.py]"]
  node_portprobe["Port probing<br/>[portprobe.py]"]
end

subgraph group_integrations["Integrations"]
  node_notify["Notifications<br/>[notify.py]"]
  node_ha_mqtt["Home Assistant MQTT<br/>[ha_mqtt.py]"]
  node_backups["Controller backups<br/>[backups.py]"]
end

subgraph group_experience["Dashboard and access"]
  node_main["API server<br/>[main.py]"]
  node_web["Web dashboard<br/>[app.js]"]
  node_auth["Login and sessions<br/>[auth.py]"]
  node_passkeys["Passkeys<br/>[passkeys.py]"]
  node_setup["Setup wizard<br/>[setup.py]"]
  node_i18n["English and Dutch<br/>[i18n.py]"]
end

node_user(("Network operator"))
node_controller["UniFi controller"]
node_mqtt_broker["MQTT broker"]

node_user -->|"uses dashboard"| node_main
node_main -->|"serves assets"| node_web
node_main -->|"starts monitoring"| node_collector
node_main -->|"checks access"| node_auth
node_main -->|"handles passkeys"| node_passkeys
node_main -->|"tests setup"| node_setup
node_main -->|"loads settings"| node_config
node_main -->|"uses storage"| node_db
node_controller -->|"provides network data"| node_unifi
node_collector -->|"polls controller"| node_unifi
node_collector -->|"uses demo source"| node_mock
node_collector -->|"reads settings"| node_config
node_collector -->|"stores history"| node_db
node_collector -->|"evaluates issues"| node_rules
node_collector -->|"sends alerts"| node_notify
node_collector -->|"records changes"| node_changes
node_collector -->|"updates channel data"| node_channels
node_collector -->|"starts integration"| node_ha_mqtt
node_collector -->|"syncs DNS data"| node_adguard
node_collector -->|"checks advisories"| node_advisories
node_collector -->|"manages backups"| node_backups
node_collector -->|"runs diagnostics"| node_bufferbloat
node_collector -->|"applies schedules"| node_schedules
node_collector -->|"runs checks"| node_vulnscan
node_rules -->|"runs extra checks"| node_rules_extra
node_rules -->|"checks segments"| node_segments
node_rules_extra -->|"reads DNS findings"| node_adguard
node_unifi -->|"normalizes networks"| node_segments
node_vulnscan -->|"uses advisories"| node_advisories
node_ha_mqtt -->|"publishes discovery"| node_mqtt_broker
node_adguard -->|"shares API interface"| node_pihole
node_main -->|"serves identification"| node_identify
node_main -->|"localizes responses"| node_i18n
node_user -.->|"receives alerts"| node_notify

click node_main "https://github.com/lexi1986/unifi-sonar/blob/main/app/main.py"
click node_web "https://github.com/lexi1986/unifi-sonar/blob/main/web/app.js"
click node_auth "https://github.com/lexi1986/unifi-sonar/blob/main/app/auth.py"
click node_passkeys "https://github.com/lexi1986/unifi-sonar/blob/main/app/passkeys.py"
click node_setup "https://github.com/lexi1986/unifi-sonar/blob/main/app/setup.py"
click node_config "https://github.com/lexi1986/unifi-sonar/blob/main/app/config.py"
click node_collector "https://github.com/lexi1986/unifi-sonar/blob/main/app/collector.py"
click node_unifi "https://github.com/lexi1986/unifi-sonar/blob/main/app/unifi_client.py"
click node_mock "https://github.com/lexi1986/unifi-sonar/blob/main/app/mock.py"
click node_db "https://github.com/lexi1986/unifi-sonar/blob/main/app/db.py"
click node_rules "https://github.com/lexi1986/unifi-sonar/blob/main/app/rules.py"
click node_rules_extra "https://github.com/lexi1986/unifi-sonar/blob/main/app/rules_extra.py"
click node_channels "https://github.com/lexi1986/unifi-sonar/blob/main/app/channels.py"
click node_changes "https://github.com/lexi1986/unifi-sonar/blob/main/app/changes.py"
click node_bufferbloat "https://github.com/lexi1986/unifi-sonar/blob/main/app/bufferbloat.py"
click node_segments "https://github.com/lexi1986/unifi-sonar/blob/main/app/segments.py"
click node_adguard "https://github.com/lexi1986/unifi-sonar/blob/main/app/adguard.py"
click node_pihole "https://github.com/lexi1986/unifi-sonar/blob/main/app/pihole.py"
click node_advisories "https://github.com/lexi1986/unifi-sonar/blob/main/app/advisories.py"
click node_vulnscan "https://github.com/lexi1986/unifi-sonar/blob/main/app/vulnscan.py"
click node_portprobe "https://github.com/lexi1986/unifi-sonar/blob/main/app/portprobe.py"
click node_identify "https://github.com/lexi1986/unifi-sonar/blob/main/app/identify.py"
click node_notify "https://github.com/lexi1986/unifi-sonar/blob/main/app/notify.py"
click node_ha_mqtt "https://github.com/lexi1986/unifi-sonar/blob/main/app/ha_mqtt.py"
click node_backups "https://github.com/lexi1986/unifi-sonar/blob/main/app/backups.py"
click node_i18n "https://github.com/lexi1986/unifi-sonar/blob/main/app/i18n.py"
click node_schedules "https://github.com/lexi1986/unifi-sonar/blob/main/app/schedules.py"

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_config,node_collector,node_unifi,node_mock,node_db toneBlue
class node_rules,node_rules_extra,node_channels,node_changes,node_bufferbloat,node_identify,node_schedules toneAmber
class node_segments,node_adguard,node_pihole,node_advisories,node_vulnscan,node_portprobe toneMint
class node_notify,node_ha_mqtt,node_backups toneRose
class node_main,node_web,node_auth,node_passkeys,node_setup,node_i18n,node_user,node_controller,node_mqtt_broker toneIndigo
```

## Components

### Monitoring runtime

- [Settings](https://github.com/lexi1986/unifi-sonar/blob/main/app/config.py): `app/config.py`
- [Polling collector](https://github.com/lexi1986/unifi-sonar/blob/main/app/collector.py): `app/collector.py`
- [UniFi client](https://github.com/lexi1986/unifi-sonar/blob/main/app/unifi_client.py): `app/unifi_client.py`
- [Demo network](https://github.com/lexi1986/unifi-sonar/blob/main/app/mock.py): `app/mock.py`
- [History store](https://github.com/lexi1986/unifi-sonar/blob/main/app/db.py): `app/db.py`

### Network analysis

- [Issue detection](https://github.com/lexi1986/unifi-sonar/blob/main/app/rules.py): `app/rules.py`
- [Extended checks](https://github.com/lexi1986/unifi-sonar/blob/main/app/rules_extra.py): `app/rules_extra.py`
- [Channel analysis](https://github.com/lexi1986/unifi-sonar/blob/main/app/channels.py): `app/channels.py`
- [Change timeline](https://github.com/lexi1986/unifi-sonar/blob/main/app/changes.py): `app/changes.py`
- [Bufferbloat tests](https://github.com/lexi1986/unifi-sonar/blob/main/app/bufferbloat.py): `app/bufferbloat.py`
- [Device identification](https://github.com/lexi1986/unifi-sonar/blob/main/app/identify.py): `app/identify.py`
- [Pause schedules](https://github.com/lexi1986/unifi-sonar/blob/main/app/schedules.py): `app/schedules.py`

### Security and DNS

- [Network segments](https://github.com/lexi1986/unifi-sonar/blob/main/app/segments.py): `app/segments.py`
- [AdGuard analysis](https://github.com/lexi1986/unifi-sonar/blob/main/app/adguard.py): `app/adguard.py`
- [Pi-hole analysis](https://github.com/lexi1986/unifi-sonar/blob/main/app/pihole.py): `app/pihole.py`
- [Firmware advisories](https://github.com/lexi1986/unifi-sonar/blob/main/app/advisories.py): `app/advisories.py`
- [Vulnerability checks](https://github.com/lexi1986/unifi-sonar/blob/main/app/vulnscan.py): `app/vulnscan.py`
- [Port probing](https://github.com/lexi1986/unifi-sonar/blob/main/app/portprobe.py): `app/portprobe.py`

### Integrations

- [Notifications](https://github.com/lexi1986/unifi-sonar/blob/main/app/notify.py): `app/notify.py`
- [Home Assistant MQTT](https://github.com/lexi1986/unifi-sonar/blob/main/app/ha_mqtt.py): `app/ha_mqtt.py`
- [Controller backups](https://github.com/lexi1986/unifi-sonar/blob/main/app/backups.py): `app/backups.py`

### Dashboard and access

- [API server](https://github.com/lexi1986/unifi-sonar/blob/main/app/main.py): `app/main.py`
- [Web dashboard](https://github.com/lexi1986/unifi-sonar/blob/main/web/app.js): `web/app.js`
- [Login and sessions](https://github.com/lexi1986/unifi-sonar/blob/main/app/auth.py): `app/auth.py`
- [Passkeys](https://github.com/lexi1986/unifi-sonar/blob/main/app/passkeys.py): `app/passkeys.py`
- [Setup wizard](https://github.com/lexi1986/unifi-sonar/blob/main/app/setup.py): `app/setup.py`
- [English and Dutch](https://github.com/lexi1986/unifi-sonar/blob/main/app/i18n.py): `app/i18n.py`

### Other components

- **Network operator**
- **UniFi controller**
- **MQTT broker**

## Connections

- Network operator → API server: uses dashboard (evidence: `README.md`)
- API server → Web dashboard: serves assets (evidence: `app/main.py`)
- API server → Polling collector: starts monitoring (evidence: `app/main.py`)
- API server → Login and sessions: checks access (evidence: `app/main.py`)
- API server → Passkeys: handles passkeys (evidence: `app/main.py`)
- API server → Setup wizard: tests setup (evidence: `app/main.py`)
- API server → Settings: loads settings (evidence: `app/main.py`)
- API server → History store: uses storage (evidence: `app/main.py`)
- UniFi controller → UniFi client: provides network data (evidence: `README.md`)
- Polling collector → UniFi client: polls controller (evidence: `app/collector.py`)
- Polling collector → Demo network: uses demo source (evidence: `app/collector.py`)
- Polling collector → Settings: reads settings (evidence: `app/collector.py`)
- Polling collector → History store: stores history (evidence: `app/collector.py`)
- Polling collector → Issue detection: evaluates issues (evidence: `app/collector.py`)
- Polling collector → Notifications: sends alerts (evidence: `app/collector.py`)
- Polling collector → Change timeline: records changes (evidence: `app/collector.py`)
- Polling collector → Channel analysis: updates channel data (evidence: `app/collector.py`)
- Polling collector → Home Assistant MQTT: starts integration (evidence: `app/collector.py`)
- Polling collector → AdGuard analysis: syncs DNS data (evidence: `app/collector.py`)
- Polling collector → Firmware advisories: checks advisories (evidence: `app/collector.py`)
- Polling collector → Controller backups: manages backups (evidence: `app/collector.py`)
- Polling collector → Bufferbloat tests: runs diagnostics (evidence: `app/collector.py`)
- Polling collector → Pause schedules: applies schedules (evidence: `app/collector.py`)
- Polling collector → Vulnerability checks: runs checks (evidence: `app/collector.py`)
- Issue detection → Extended checks: runs extra checks (evidence: `app/rules.py`)
- Issue detection → Network segments: checks segments (evidence: `app/rules.py`)
- Extended checks → AdGuard analysis: reads DNS findings (evidence: `app/rules_extra.py`)
- UniFi client → Network segments: normalizes networks (evidence: `app/unifi_client.py`)
- Vulnerability checks → Firmware advisories: uses advisories (evidence: `app/vulnscan.py`)
- Home Assistant MQTT → MQTT broker: publishes discovery (evidence: `README.md`)
- AdGuard analysis → Pi-hole analysis: shares API interface (evidence: `app/adguard.py`)
- API server → Device identification: serves identification (evidence: `app/main.py`)
- API server → English and Dutch: localizes responses (evidence: `app/main.py`)
- Network operator → Notifications: receives alerts (evidence: `README.md`)
