# sstangle73/ting-recorder architecture

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

- Interactive diagram: https://gitdiagram.com/sstangle73/ting-recorder
- Repository: https://github.com/sstangle73/ting-recorder

## Overview

ting-recorder is a self-hosted Ting sensor recorder: it authenticates to Whisker Labs, collects live readings and REST state, retains and analyzes them, then serves a web UI, read-only API, Prometheus metrics, and optional Home Assistant MQTT updates. The principal flow is account sign-in → per-sensor stream and REST polling → decoding and persistence → rollups/event inference → user-facing history and status. Edges reflect the supplied excerpts, SOURCE INDEX references, or README; unsampled subsystem details are represented only where documented.

Main entry points: [`ting_recorder/main.py`](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/main.py) (Recorder runtime), [`ting_recorder/web.py`](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/web.py) (Web UI and API), [`ting_recorder/hub.py`](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/hub.py) (Live hub session), [`ting_recorder/store.py`](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/store.py) (SQLite store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cloud["Ting Cloud Collection"]
  node_cognito["Cognito client<br/>[cognito.py]"]
  node_identity["Identity manager<br/>[identity.py]"]
  node_hub["Live hub session<br/>[hub.py]"]
  node_signalr["SignalR protocol<br/>[signalr.py]"]
  node_rest["Ting REST client<br/>[rest.py]"]
end

subgraph group_data["Recording and Analysis"]
  node_decoder["Reading decoder<br/>[decode.py]"]
  node_recorder["Recorder runtime<br/>[main.py]"]
  node_config["Runtime settings<br/>[config.py]"]
  node_demo["Synthetic data<br/>[demo.py]"]
  node_store[("SQLite store<br/>[store.py]")]
  node_infer["Event inference<br/>[infer.py]"]
  node_queries["History queries<br/>[queries.py]"]
end

subgraph group_web["Web and API"]
  node_web["Web UI and API<br/>[web.py]"]
  node_auth["Request authentication<br/>[auth.py]"]
  node_browser["Browser interface<br/>[app.js]"]
end

subgraph group_outputs["Exports and Integrations"]
  node_metrics["Prometheus metrics<br/>[metrics.py]"]
  node_publisher["MQTT publisher<br/>[mqtt.py]"]
end

node_owner(("Recorder operator"))
node_ting{{"Ting cloud"}}
node_prometheus(("Prometheus"))
node_mqtt["MQTT broker"]

node_owner -->|"configures"| node_recorder
node_recorder -->|"loads settings"| node_config
node_recorder -->|"coordinates sign-in"| node_identity
node_identity -->|"signs in"| node_cognito
node_cognito -->|"authenticates with"| node_ting
node_recorder -->|"polls state"| node_rest
node_rest -->|"requests account data"| node_ting
node_recorder -->|"starts sessions"| node_hub
node_hub -->|"gets credentials"| node_identity
node_hub -->|"uses protocol"| node_signalr
node_hub -->|"streams sensor data"| node_ting
node_hub -->|"decodes invocations"| node_decoder
node_recorder -.->|"handles readings"| node_decoder
node_recorder -->|"records readings"| node_store
node_recorder -->|"runs inference"| node_infer
node_infer -->|"reads and writes events"| node_store
node_recorder -->|"seeds demo data"| node_demo
node_demo -->|"writes synthetic data"| node_store
node_web -->|"checks access"| node_auth
node_web -->|"reads recorder data"| node_store
node_web -->|"queries history"| node_queries
node_web -->|"formats Ting state"| node_rest
node_browser -.->|"requests pages and data"| node_web
node_owner -->|"views history and status"| node_web
node_web -->|"serves metrics"| node_metrics
node_prometheus -->|"scrapes"| node_web
node_recorder -->|"starts publisher"| node_publisher
node_publisher -->|"publishes sensor state"| node_mqtt

click node_cognito "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/cognito.py"
click node_identity "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/identity.py"
click node_hub "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/hub.py"
click node_signalr "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/signalr.py"
click node_decoder "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/decode.py"
click node_rest "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/rest.py"
click node_recorder "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/main.py"
click node_config "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/config.py"
click node_demo "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/demo.py"
click node_store "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/store.py"
click node_infer "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/infer.py"
click node_queries "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/queries.py"
click node_web "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/web.py"
click node_auth "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/auth.py"
click node_browser "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/static/app.js"
click node_metrics "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/metrics.py"
click node_publisher "https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/mqtt.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_cognito,node_identity,node_hub,node_signalr,node_rest toneBlue
class node_decoder,node_recorder,node_config,node_demo,node_store,node_infer,node_queries toneAmber
class node_web,node_auth,node_browser toneMint
class node_metrics,node_publisher toneRose
class node_owner,node_ting,node_prometheus,node_mqtt toneIndigo
```

## Components

### Ting Cloud Collection

- [Cognito client](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/cognito.py): `ting_recorder/cognito.py`
- [Identity manager](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/identity.py): `ting_recorder/identity.py`
- [Live hub session](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/hub.py): `ting_recorder/hub.py`
- [SignalR protocol](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/signalr.py): `ting_recorder/signalr.py`
- [Ting REST client](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/rest.py): `ting_recorder/rest.py`

### Recording and Analysis

- [Reading decoder](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/decode.py): `ting_recorder/decode.py`
- [Recorder runtime](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/main.py): `ting_recorder/main.py`
- [Runtime settings](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/config.py): `ting_recorder/config.py`
- [Synthetic data](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/demo.py): `ting_recorder/demo.py`
- [SQLite store](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/store.py): `ting_recorder/store.py`
- [Event inference](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/infer.py): `ting_recorder/infer.py`
- [History queries](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/queries.py): `ting_recorder/queries.py`

### Web and API

- [Web UI and API](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/web.py): `ting_recorder/web.py`
- [Request authentication](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/auth.py): `ting_recorder/auth.py`
- [Browser interface](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/static/app.js): `ting_recorder/static/app.js`

### Exports and Integrations

- [Prometheus metrics](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/metrics.py): `ting_recorder/metrics.py`
- [MQTT publisher](https://github.com/sstangle73/ting-recorder/blob/main/ting_recorder/mqtt.py): `ting_recorder/mqtt.py`

### Other components

- **Recorder operator**
- **Ting cloud**
- **Prometheus**
- **MQTT broker**

## Connections

- Recorder operator → Recorder runtime: configures (evidence: `README.md`)
- Recorder runtime → Runtime settings: loads settings (evidence: `ting_recorder/main.py`)
- Recorder runtime → Identity manager: coordinates sign-in (evidence: `ting_recorder/main.py`)
- Identity manager → Cognito client: signs in (evidence: `ting_recorder/identity.py`)
- Cognito client → Ting cloud: authenticates with (evidence: `ting_recorder/cognito.py`)
- Recorder runtime → Ting REST client: polls state (evidence: `ting_recorder/main.py`)
- Ting REST client → Ting cloud: requests account data (evidence: `ting_recorder/rest.py`)
- Recorder runtime → Live hub session: starts sessions (evidence: `ting_recorder/main.py`)
- Live hub session → Identity manager: gets credentials (evidence: `ting_recorder/hub.py`)
- Live hub session → SignalR protocol: uses protocol (evidence: `ting_recorder/hub.py`)
- Live hub session → Ting cloud: streams sensor data (evidence: `ting_recorder/hub.py`)
- Live hub session → Reading decoder: decodes invocations (evidence: `ting_recorder/hub.py`)
- Recorder runtime → Reading decoder: handles readings
- Recorder runtime → SQLite store: records readings (evidence: `ting_recorder/main.py`)
- Recorder runtime → Event inference: runs inference (evidence: `ting_recorder/main.py`)
- Event inference → SQLite store: reads and writes events (evidence: `ting_recorder/infer.py`)
- Recorder runtime → Synthetic data: seeds demo data (evidence: `ting_recorder/main.py`)
- Synthetic data → SQLite store: writes synthetic data (evidence: `ting_recorder/demo.py`)
- Web UI and API → Request authentication: checks access (evidence: `ting_recorder/web.py`)
- Web UI and API → SQLite store: reads recorder data (evidence: `ting_recorder/web.py`)
- Web UI and API → History queries: queries history (evidence: `ting_recorder/web.py`)
- Web UI and API → Ting REST client: formats Ting state (evidence: `ting_recorder/web.py`)
- Browser interface → Web UI and API: requests pages and data
- Recorder operator → Web UI and API: views history and status (evidence: `README.md`)
- Web UI and API → Prometheus metrics: serves metrics (evidence: `ting_recorder/web.py`)
- Prometheus → Web UI and API: scrapes (evidence: `README.md`)
- Recorder runtime → MQTT publisher: starts publisher (evidence: `ting_recorder/main.py`)
- MQTT publisher → MQTT broker: publishes sensor state (evidence: `README.md`)
