Skip to content

Architecture

Damien PHILIPPE edited this page Oct 19, 2026 · 2 revisions

🏗️ Architecture

Crate layout

WattSeal is a Rust workspace made up of four crates:

wattseal/               ← Root binary (tray icon, lifecycle management)
  ├── collector/        ← Background sensor polling, power estimation
  ├── mqtt/             ← Optional MQTT publisher
  ├── common/           ← Shared types, SQLite layer, utilities
  └── ui/               ← Iced GUI (dashboard, hardware info, settings, charts)

The root binary spawns the UI as a separate process, so a UI crash can't take down the collector, and vice versa.

Diagram

Overall architecture

Data flow

  1. collector polls every sensor once per second.
  2. Raw SensorData is computed into ComputedSensorData (adds Total, per-process attribution, top-10 ranking).
  3. Written to SQLite and/or published to MQTT, depending on flags.
  4. ui reads the same SQLite file (WAL mode allows concurrent read/write), polling once per second.

Database

SQLite, WAL mode, power_monitoring.db next to the executable. One table per sensor type, plus hardware_info, devices, apps, ui_settings, and component_all_time_data for cumulative totals.

A background task averages raw per-second data older than 24 hours into hourly buckets, keeping the database small over months of use.

Schema is versioned (PRAGMA user_version), the collector migrates on startup, the UI waits for the schema to be current before opening.

Only one collector can run against a given database, enforced via an OS file lock (power_monitoring.db.collector.lock).

Prerequisites

  • Rust stable toolchain (version pinned in rust-toolchain.toml).

  • On linux, install the build deps for the tray icon, not needed at runtime but required to build the Linux version:

    sudo apt install libgtk-3-dev pkg-config libxkbcommon-dev libwayland-dev

Building from Source

Clone the repository:

git clone https://github.com/daminoup88/wattseal.git
cd wattseal

Debug build and run:

cargo run

Release build:

cargo build --release

⚠️ Elevated privileges are required to access hardware energy counters. Run with administrator rights on Windows (you will be prompted to elevate), or use sudo on Linux.

Clone this wiki locally