# shark-empire/mitos-power architecture

> Architecture diagram of the GitHub repository shark-empire/mitos-power, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shark-empire/mitos-power
- Repository: https://github.com/shark-empire/mitos-power

## Overview

mitos-power is MITOS’s central power-management daemon, exposing battery, profile, display, thermal, sleep, shutdown and inhibitor operations through a Unix-socket API. The main workflow is a local client request or hardware/event update entering the daemon, reaching the PowerManager and relevant subsystem, then producing a response or broadcast event. Configuration initializes behavior; policy and scheduling add automated actions. The README documents the broader capability set, while sampled excerpts substantiate IPC dispatch, manager coordination, profiles, inhibitors and thermal handling; links for unsampled internals are limited accordingly.

Main entry points: [`src/manager/manager.rs`](https://github.com/shark-empire/mitos-power/blob/main/src/manager/manager.rs) (PowerManager), [`src/ipc/server.rs`](https://github.com/shark-empire/mitos-power/blob/main/src/ipc/server.rs) (Unix IPC server), [`src/hardware/mod.rs`](https://github.com/shark-empire/mitos-power/blob/main/src/hardware/mod.rs) (Hardware access), [`bin/mitos-powerctl.rs`](https://github.com/shark-empire/mitos-power/blob/main/bin/mitos-powerctl.rs) (powerctl CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and API"]
  node_cli["powerctl CLI<br/>[mitos-powerctl.rs]"]
  node_daemon["Daemon runtime<br/>[daemon.rs]"]
  node_ipc["Unix IPC server<br/>[server.rs]"]
  node_protocol["IPC protocol<br/>[protocol.rs]"]
  node_config["Configuration<br/>[mod.rs]"]
end

subgraph group_control["Management and policy"]
  node_manager["PowerManager<br/>[manager.rs]"]
  node_policy["Policy engine<br/>[policy.rs]"]
  node_scheduler["Operation scheduler<br/>[scheduler.rs]"]
  node_inhibitors[("Inhibitor registry<br/>[manager.rs]")]
end

subgraph group_power["Power features"]
  node_profiles["Power profiles<br/>[manager.rs]"]
  node_battery["Battery monitoring<br/>[mod.rs]"]
  node_ac["AC detection<br/>[mod.rs]"]
  node_display["Display controls<br/>[mod.rs]"]
  node_cpu["CPU controls<br/>[mod.rs]"]
  node_thermal["Thermal monitoring<br/>[mod.rs]"]
  node_idle["Idle behavior<br/>[mod.rs]"]
  node_sleep["Sleep operations<br/>[mod.rs]"]
  node_shutdown["Shutdown operations<br/>[mod.rs]"]
end

subgraph group_hardware["Hardware and state"]
  node_devices["Device events<br/>[mod.rs]"]
  node_hardware["Hardware access<br/>[mod.rs]"]
  node_events["Daemon events<br/>[events.rs]"]
  node_state[("Persistent state<br/>[database.rs]")]
end

node_clients(("MITOS clients"))
node_kernel(("Linux kernel interfaces"))

node_clients -->|"invokes"| node_cli
node_cli -->|"sends requests"| node_ipc
node_clients -->|"connects"| node_ipc
node_ipc -->|"decodes messages"| node_protocol
node_ipc -->|"dispatches requests"| node_manager
node_daemon -->|"runs server"| node_ipc
node_config -->|"configures startup"| node_daemon
node_manager -->|"runs policy"| node_policy
node_manager -->|"selects profiles"| node_profiles
node_manager -->|"checks blockers"| node_inhibitors
node_manager -->|"schedules operations"| node_scheduler
node_manager -->|"reads battery state"| node_battery
node_manager -->|"reads AC state"| node_ac
node_manager -->|"controls display"| node_display
node_manager -->|"applies CPU settings"| node_cpu
node_manager -->|"reads thermal state"| node_thermal
node_manager -->|"manages idle state"| node_idle
node_manager -->|"invokes sleep"| node_sleep
node_manager -->|"invokes shutdown"| node_shutdown
node_manager -->|"publishes events"| node_events
node_ipc -->|"forwards subscriptions"| node_events
node_ipc -->|"releases on disconnect"| node_inhibitors
node_devices -->|"reports device state"| node_manager
node_battery -->|"reads hardware"| node_hardware
node_ac -->|"detects power source"| node_hardware
node_thermal -->|"reads thermal zones"| node_hardware
node_display -->|"writes display controls"| node_hardware
node_cpu -->|"writes CPU controls"| node_hardware
node_sleep -->|"requests sleep"| node_kernel
node_shutdown -->|"requests power action"| node_kernel
node_state -.->|"stores state"| node_manager

click node_cli "https://github.com/shark-empire/mitos-power/blob/main/bin/mitos-powerctl.rs"
click node_daemon "https://github.com/shark-empire/mitos-power/blob/main/src/daemon/daemon.rs"
click node_ipc "https://github.com/shark-empire/mitos-power/blob/main/src/ipc/server.rs"
click node_protocol "https://github.com/shark-empire/mitos-power/blob/main/src/ipc/protocol.rs"
click node_config "https://github.com/shark-empire/mitos-power/blob/main/src/config/mod.rs"
click node_manager "https://github.com/shark-empire/mitos-power/blob/main/src/manager/manager.rs"
click node_policy "https://github.com/shark-empire/mitos-power/blob/main/src/manager/policy.rs"
click node_scheduler "https://github.com/shark-empire/mitos-power/blob/main/src/manager/scheduler.rs"
click node_inhibitors "https://github.com/shark-empire/mitos-power/blob/main/src/inhibitor/manager.rs"
click node_profiles "https://github.com/shark-empire/mitos-power/blob/main/src/profiles/manager.rs"
click node_battery "https://github.com/shark-empire/mitos-power/blob/main/src/battery/mod.rs"
click node_ac "https://github.com/shark-empire/mitos-power/blob/main/src/ac/mod.rs"
click node_display "https://github.com/shark-empire/mitos-power/blob/main/src/display/mod.rs"
click node_cpu "https://github.com/shark-empire/mitos-power/blob/main/src/cpu/mod.rs"
click node_thermal "https://github.com/shark-empire/mitos-power/blob/main/src/thermal/mod.rs"
click node_idle "https://github.com/shark-empire/mitos-power/blob/main/src/idle/mod.rs"
click node_sleep "https://github.com/shark-empire/mitos-power/blob/main/src/sleep/mod.rs"
click node_shutdown "https://github.com/shark-empire/mitos-power/blob/main/src/shutdown/mod.rs"
click node_devices "https://github.com/shark-empire/mitos-power/blob/main/src/devices/mod.rs"
click node_hardware "https://github.com/shark-empire/mitos-power/blob/main/src/hardware/mod.rs"
click node_events "https://github.com/shark-empire/mitos-power/blob/main/src/ipc/events.rs"
click node_state "https://github.com/shark-empire/mitos-power/blob/main/src/persistence/database.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_cli,node_daemon,node_ipc,node_protocol,node_config,node_clients toneBlue
class node_manager,node_policy,node_scheduler,node_inhibitors toneAmber
class node_profiles,node_battery,node_ac,node_display,node_cpu,node_thermal,node_idle,node_sleep,node_shutdown toneMint
class node_devices,node_hardware,node_events,node_state toneRose
class node_kernel toneIndigo
```

## Components

### Entry and API

- [powerctl CLI](https://github.com/shark-empire/mitos-power/blob/main/bin/mitos-powerctl.rs): `bin/mitos-powerctl.rs`
- [Daemon runtime](https://github.com/shark-empire/mitos-power/blob/main/src/daemon/daemon.rs): `src/daemon/daemon.rs`
- [Unix IPC server](https://github.com/shark-empire/mitos-power/blob/main/src/ipc/server.rs): `src/ipc/server.rs`
- [IPC protocol](https://github.com/shark-empire/mitos-power/blob/main/src/ipc/protocol.rs): `src/ipc/protocol.rs`
- [Configuration](https://github.com/shark-empire/mitos-power/blob/main/src/config/mod.rs): `src/config/mod.rs`

### Management and policy

- [PowerManager](https://github.com/shark-empire/mitos-power/blob/main/src/manager/manager.rs): `src/manager/manager.rs`
- [Policy engine](https://github.com/shark-empire/mitos-power/blob/main/src/manager/policy.rs): `src/manager/policy.rs`
- [Operation scheduler](https://github.com/shark-empire/mitos-power/blob/main/src/manager/scheduler.rs): `src/manager/scheduler.rs`
- [Inhibitor registry](https://github.com/shark-empire/mitos-power/blob/main/src/inhibitor/manager.rs): `src/inhibitor/manager.rs`

### Power features

- [Power profiles](https://github.com/shark-empire/mitos-power/blob/main/src/profiles/manager.rs): `src/profiles/manager.rs`
- [Battery monitoring](https://github.com/shark-empire/mitos-power/blob/main/src/battery/mod.rs): `src/battery/mod.rs`
- [AC detection](https://github.com/shark-empire/mitos-power/blob/main/src/ac/mod.rs): `src/ac/mod.rs`
- [Display controls](https://github.com/shark-empire/mitos-power/blob/main/src/display/mod.rs): `src/display/mod.rs`
- [CPU controls](https://github.com/shark-empire/mitos-power/blob/main/src/cpu/mod.rs): `src/cpu/mod.rs`
- [Thermal monitoring](https://github.com/shark-empire/mitos-power/blob/main/src/thermal/mod.rs): `src/thermal/mod.rs`
- [Idle behavior](https://github.com/shark-empire/mitos-power/blob/main/src/idle/mod.rs): `src/idle/mod.rs`
- [Sleep operations](https://github.com/shark-empire/mitos-power/blob/main/src/sleep/mod.rs): `src/sleep/mod.rs`
- [Shutdown operations](https://github.com/shark-empire/mitos-power/blob/main/src/shutdown/mod.rs): `src/shutdown/mod.rs`

### Hardware and state

- [Device events](https://github.com/shark-empire/mitos-power/blob/main/src/devices/mod.rs): `src/devices/mod.rs`
- [Hardware access](https://github.com/shark-empire/mitos-power/blob/main/src/hardware/mod.rs): `src/hardware/mod.rs`
- [Daemon events](https://github.com/shark-empire/mitos-power/blob/main/src/ipc/events.rs): `src/ipc/events.rs`
- [Persistent state](https://github.com/shark-empire/mitos-power/blob/main/src/persistence/database.rs): `src/persistence/database.rs`

### Other components

- **MITOS clients**
- **Linux kernel interfaces**

## Connections

- MITOS clients → powerctl CLI: invokes
- powerctl CLI → Unix IPC server: sends requests
- MITOS clients → Unix IPC server: connects
- Unix IPC server → IPC protocol: decodes messages
- Unix IPC server → PowerManager: dispatches requests
- Daemon runtime → Unix IPC server: runs server
- Configuration → Daemon runtime: configures startup
- PowerManager → Policy engine: runs policy
- PowerManager → Power profiles: selects profiles
- PowerManager → Inhibitor registry: checks blockers
- PowerManager → Operation scheduler: schedules operations
- PowerManager → Battery monitoring: reads battery state
- PowerManager → AC detection: reads AC state
- PowerManager → Display controls: controls display
- PowerManager → CPU controls: applies CPU settings
- PowerManager → Thermal monitoring: reads thermal state
- PowerManager → Idle behavior: manages idle state
- PowerManager → Sleep operations: invokes sleep
- PowerManager → Shutdown operations: invokes shutdown
- PowerManager → Daemon events: publishes events
- Unix IPC server → Daemon events: forwards subscriptions
- Unix IPC server → Inhibitor registry: releases on disconnect
- Device events → PowerManager: reports device state
- Battery monitoring → Hardware access: reads hardware
- AC detection → Hardware access: detects power source
- Thermal monitoring → Hardware access: reads thermal zones
- Display controls → Hardware access: writes display controls
- CPU controls → Hardware access: writes CPU controls
- Sleep operations → Linux kernel interfaces: requests sleep
- Shutdown operations → Linux kernel interfaces: requests power action
- Persistent state → PowerManager: stores state
