# garvshr/unetwork-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/garvshr/unetwork-monitor
- Repository: https://github.com/garvshr/unetwork-monitor

## Overview

Unetwork Device Monitor polls device-license status, tracks changes and offline duration, and sends alerts and reminders through a Telegram bot. Admins can ignore or resume alerts; approved friends can select devices and manage their own alert copies. The main polling and state logic is concentrated in main.py, with separate authentication, Unetwork API, and Telegram modules. The README documents persistence and user-facing features; unsampled internals are represented at the main.py subsystem level rather than inferred as separate implementations.

Main entry points: [`main.py`](https://github.com/garvshr/unetwork-monitor/blob/main/main.py) (Polling and alert logic), [`telegram.py`](https://github.com/garvshr/unetwork-monitor/blob/main/telegram.py) (Bot messaging and updates), [`unetwork.py`](https://github.com/garvshr/unetwork-monitor/blob/main/unetwork.py) (License API client), [`auth.py`](https://github.com/garvshr/unetwork-monitor/blob/main/auth.py) (Token refresh)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_monitor["Monitoring and state"]
  node_monitor_loop["Polling and alert logic<br/>[main.py]"]
  node_device_state[("Device alert state<br/>[main.py]")]
  node_user_access[("Approvals and subscriptions<br/>[main.py]")]
end

subgraph group_unetwork["Unetwork integration"]
  node_auth_manager["Token refresh<br/>[auth.py]"]
  node_license_client["License API client<br/>[unetwork.py]"]
end

subgraph group_telegram["Telegram interaction"]
  node_telegram_bot["Bot messaging and updates<br/>[telegram.py]"]
end

subgraph group_external["External services"]
  node_unetwork_service{{"Unetwork API"}}
  node_telegram_service{{"Telegram Bot API"}}
end

node_operator(("Admin or friend"))

node_operator -->|"sends commands"| node_telegram_bot
node_monitor_loop -->|"fetches licenses"| node_license_client
node_license_client -->|"gets access token"| node_auth_manager
node_auth_manager -->|"refreshes token"| node_unetwork_service
node_license_client -->|"requests licenses"| node_unetwork_service
node_monitor_loop -->|"tracks status"| node_device_state
node_monitor_loop -->|"checks subscriptions"| node_user_access
node_telegram_bot -->|"dispatches commands"| node_monitor_loop
node_monitor_loop -->|"sends alerts"| node_telegram_bot
node_telegram_bot -->|"sends and polls"| node_telegram_service

click node_monitor_loop "https://github.com/garvshr/unetwork-monitor/blob/main/main.py"
click node_device_state "https://github.com/garvshr/unetwork-monitor/blob/main/main.py"
click node_user_access "https://github.com/garvshr/unetwork-monitor/blob/main/main.py"
click node_auth_manager "https://github.com/garvshr/unetwork-monitor/blob/main/auth.py"
click node_license_client "https://github.com/garvshr/unetwork-monitor/blob/main/unetwork.py"
click node_telegram_bot "https://github.com/garvshr/unetwork-monitor/blob/main/telegram.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_monitor_loop,node_device_state,node_user_access toneBlue
class node_auth_manager,node_license_client toneAmber
class node_telegram_bot toneMint
class node_unetwork_service,node_telegram_service toneRose
class node_operator toneIndigo
```

## Components

### Monitoring and state

- [Polling and alert logic](https://github.com/garvshr/unetwork-monitor/blob/main/main.py): `main.py`
- [Device alert state](https://github.com/garvshr/unetwork-monitor/blob/main/main.py): `main.py`
- [Approvals and subscriptions](https://github.com/garvshr/unetwork-monitor/blob/main/main.py): `main.py`

### Unetwork integration

- [Token refresh](https://github.com/garvshr/unetwork-monitor/blob/main/auth.py): `auth.py`
- [License API client](https://github.com/garvshr/unetwork-monitor/blob/main/unetwork.py): `unetwork.py`

### Telegram interaction

- [Bot messaging and updates](https://github.com/garvshr/unetwork-monitor/blob/main/telegram.py): `telegram.py`

### External services

- **Unetwork API**
- **Telegram Bot API**

### Other components

- **Admin or friend**

## Connections

- Admin or friend → Bot messaging and updates: sends commands (evidence: `README.md`)
- Polling and alert logic → License API client: fetches licenses (evidence: `README.md`)
- License API client → Token refresh: gets access token (evidence: `unetwork.py`)
- Token refresh → Unetwork API: refreshes token (evidence: `auth.py`)
- License API client → Unetwork API: requests licenses (evidence: `unetwork.py`)
- Polling and alert logic → Device alert state: tracks status (evidence: `README.md`)
- Polling and alert logic → Approvals and subscriptions: checks subscriptions (evidence: `README.md`)
- Bot messaging and updates → Polling and alert logic: dispatches commands (evidence: `README.md`)
- Polling and alert logic → Bot messaging and updates: sends alerts (evidence: `main.py`)
- Bot messaging and updates → Telegram Bot API: sends and polls (evidence: `telegram.py`)
