# srimanachanta/stasis architecture

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

- Interactive diagram: https://gitdiagram.com/srimanachanta/stasis
- Repository: https://github.com/srimanachanta/stasis

## Overview

Stasis is a macOS menu-bar battery monitor and charging controller for Apple Silicon MacBooks. On launch, the app initializes battery services, reads system and SMC metrics, evaluates charging policy, and presents live status and controls in the menu bar and settings. Charging changes are sent through an XPC daemon to hardware-facing SMC code. The graph also preserves the dashboard, power-flow visualization, settings, and privileged helper roles. Relationships are limited to the supplied excerpts, SOURCE INDEX references, and README; unsampled subsystem details are not inferred.

Main entry points: [`Stasis/Services/BatteryService.swift`](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/BatteryService.swift) (Battery service), [`Stasis/AppDelegate.swift`](https://github.com/srimanachanta/stasis/blob/main/Stasis/AppDelegate.swift) (App startup), [`Stasis/ViewModels/MenuViewModel.swift`](https://github.com/srimanachanta/stasis/blob/main/Stasis/ViewModels/MenuViewModel.swift) (Menu view model), [`Helper/Helper.swift`](https://github.com/srimanachanta/stasis/blob/main/Helper/Helper.swift) (SMC reader helper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and presentation"]
  node_app["App startup<br/>[AppDelegate.swift]"]
  node_status["Menu bar status"]
  node_menu["Battery menu<br/>[MenuBuilder.swift]"]
  node_viewmodel["Menu view model"]
  node_indicator["Battery indicator"]
  node_powerflow["Power flow diagram"]
  node_settingswindow["Settings window"]
  node_settings["Settings panels"]
end

subgraph group_monitor["Battery monitoring"]
  node_metrics["Battery metrics"]
  node_batteryservice["Battery service"]
  node_iokit["IOKit monitoring<br/>[IOKitService.swift]"]
  node_smcconnection["SMC reader connection"]
  node_system["System information"]
end

subgraph group_policy["Charging control"]
  node_charge["Charging policy"]
  node_helpermanager["Charging helper manager"]
  node_chargeprotocol["Charging XPC protocol"]
end

subgraph group_hardware["Privileged hardware access"]
  node_helperentry["Reader helper entry<br/>[main.swift]"]
  node_readerhelper["SMC reader helper<br/>[Helper.swift]"]
  node_readerprotocol["Reader XPC protocol"]
  node_daemonentry["Charging daemon entry<br/>[main.swift]"]
  node_chargingdaemon["Charging daemon"]
  node_smcbattery["SMC battery access<br/>[SMCBattery.swift]"]
  node_smcadapter["SMC adapter access<br/>[SMCAdapter.swift]"]
end

node_user(("Mac user"))
node_macos["macOS power and notification APIs"]

node_user -->|"launches"| node_app
node_app -->|"initializes"| node_batteryservice
node_app -->|"creates"| node_charge
node_app -->|"creates"| node_viewmodel
node_app -->|"builds"| node_menu
node_app -->|"creates"| node_settingswindow
node_app -->|"creates"| node_status
node_status -->|"reads"| node_viewmodel
node_status -->|"hosts"| node_indicator
node_menu -->|"reads"| node_viewmodel
node_menu -->|"opens"| node_settingswindow
node_menu -->|"shows"| node_powerflow
node_viewmodel -->|"observes"| node_batteryservice
node_viewmodel -->|"observes"| node_charge
node_viewmodel -->|"reads"| node_system
node_settingswindow -->|"hosts"| node_settings
node_user -.->|"views"| node_status
node_user -.->|"configures"| node_settings
node_batteryservice -->|"starts monitoring"| node_iokit
node_batteryservice -->|"uses"| node_smcconnection
node_batteryservice -->|"requests SMC reads"| node_readerhelper
node_batteryservice -->|"updates"| node_metrics
node_charge -->|"evaluates and commands"| node_batteryservice
node_batteryservice -->|"uses"| node_helpermanager
node_helpermanager -->|"connects through"| node_chargeprotocol
node_helperentry -->|"instantiates"| node_readerhelper
node_readerhelper -->|"implements"| node_readerprotocol
node_readerhelper -->|"reads and probes"| node_smcbattery
node_readerhelper -->|"reads and probes"| node_smcadapter
node_daemonentry -->|"instantiates"| node_chargingdaemon
node_chargingdaemon -->|"implements"| node_chargeprotocol
node_chargingdaemon -->|"controls charging"| node_smcbattery
node_chargingdaemon -->|"controls LED"| node_smcadapter
node_batteryservice -->|"uses IOKit"| node_macos
node_charge -->|"asserts sleep and notifies"| node_macos

click node_app "https://github.com/srimanachanta/stasis/blob/main/Stasis/AppDelegate.swift"
click node_status "https://github.com/srimanachanta/stasis/blob/main/Stasis/StatusBarManager.swift"
click node_menu "https://github.com/srimanachanta/stasis/blob/main/Stasis/Views/MenuBuilder.swift"
click node_viewmodel "https://github.com/srimanachanta/stasis/blob/main/Stasis/ViewModels/MenuViewModel.swift"
click node_indicator "https://github.com/srimanachanta/stasis/blob/main/Stasis/Views/BatteryIndicatorView.swift"
click node_powerflow "https://github.com/srimanachanta/stasis/blob/main/Stasis/Views/PowerSankeyView.swift"
click node_settingswindow "https://github.com/srimanachanta/stasis/blob/main/Stasis/Controllers/SettingsWindowController.swift"
click node_settings "https://github.com/srimanachanta/stasis/tree/main/Stasis/Views/Settings"
click node_metrics "https://github.com/srimanachanta/stasis/blob/main/Stasis/Models/BatteryMetrics.swift"
click node_batteryservice "https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/BatteryService.swift"
click node_iokit "https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/IOKitService.swift"
click node_smcconnection "https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/SMCReaderConnection.swift"
click node_system "https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/SystemService.swift"
click node_charge "https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/ChargeManager.swift"
click node_helpermanager "https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/ChargingHelperManager.swift"
click node_chargeprotocol "https://github.com/srimanachanta/stasis/blob/main/ChargingHelper/ChargingHelperProtocol.swift"
click node_helperentry "https://github.com/srimanachanta/stasis/blob/main/Helper/main.swift"
click node_readerhelper "https://github.com/srimanachanta/stasis/blob/main/Helper/Helper.swift"
click node_readerprotocol "https://github.com/srimanachanta/stasis/blob/main/Helper/HelperProtocol.swift"
click node_daemonentry "https://github.com/srimanachanta/stasis/blob/main/ChargingHelper/main.swift"
click node_chargingdaemon "https://github.com/srimanachanta/stasis/blob/main/ChargingHelper/ChargingHelper.swift"
click node_smcbattery "https://github.com/srimanachanta/stasis/blob/main/SMCPower/SMCBattery.swift"
click node_smcadapter "https://github.com/srimanachanta/stasis/blob/main/SMCPower/SMCAdapter.swift"

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_app,node_status,node_menu,node_viewmodel,node_indicator,node_powerflow,node_settingswindow,node_settings,node_user toneBlue
class node_metrics,node_batteryservice,node_iokit,node_smcconnection,node_system toneAmber
class node_charge,node_helpermanager,node_chargeprotocol,node_macos toneMint
class node_helperentry,node_readerhelper,node_readerprotocol,node_daemonentry,node_chargingdaemon,node_smcbattery,node_smcadapter toneRose
```

## Components

### App and presentation

- [App startup](https://github.com/srimanachanta/stasis/blob/main/Stasis/AppDelegate.swift): `Stasis/AppDelegate.swift`
- [Menu bar status](https://github.com/srimanachanta/stasis/blob/main/Stasis/StatusBarManager.swift): `Stasis/StatusBarManager.swift`
- [Battery menu](https://github.com/srimanachanta/stasis/blob/main/Stasis/Views/MenuBuilder.swift): `Stasis/Views/MenuBuilder.swift`
- [Menu view model](https://github.com/srimanachanta/stasis/blob/main/Stasis/ViewModels/MenuViewModel.swift): `Stasis/ViewModels/MenuViewModel.swift`
- [Battery indicator](https://github.com/srimanachanta/stasis/blob/main/Stasis/Views/BatteryIndicatorView.swift): `Stasis/Views/BatteryIndicatorView.swift`
- [Power flow diagram](https://github.com/srimanachanta/stasis/blob/main/Stasis/Views/PowerSankeyView.swift): `Stasis/Views/PowerSankeyView.swift`
- [Settings window](https://github.com/srimanachanta/stasis/blob/main/Stasis/Controllers/SettingsWindowController.swift): `Stasis/Controllers/SettingsWindowController.swift`
- [Settings panels](https://github.com/srimanachanta/stasis/tree/main/Stasis/Views/Settings): `Stasis/Views/Settings`

### Battery monitoring

- [Battery metrics](https://github.com/srimanachanta/stasis/blob/main/Stasis/Models/BatteryMetrics.swift): `Stasis/Models/BatteryMetrics.swift`
- [Battery service](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/BatteryService.swift): `Stasis/Services/BatteryService.swift`
- [IOKit monitoring](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/IOKitService.swift): `Stasis/Services/IOKitService.swift`
- [SMC reader connection](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/SMCReaderConnection.swift): `Stasis/Services/SMCReaderConnection.swift`
- [System information](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/SystemService.swift): `Stasis/Services/SystemService.swift`

### Charging control

- [Charging policy](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/ChargeManager.swift): `Stasis/Services/ChargeManager.swift`
- [Charging helper manager](https://github.com/srimanachanta/stasis/blob/main/Stasis/Services/ChargingHelperManager.swift): `Stasis/Services/ChargingHelperManager.swift`
- [Charging XPC protocol](https://github.com/srimanachanta/stasis/blob/main/ChargingHelper/ChargingHelperProtocol.swift): `ChargingHelper/ChargingHelperProtocol.swift`

### Privileged hardware access

- [Reader helper entry](https://github.com/srimanachanta/stasis/blob/main/Helper/main.swift): `Helper/main.swift`
- [SMC reader helper](https://github.com/srimanachanta/stasis/blob/main/Helper/Helper.swift): `Helper/Helper.swift`
- [Reader XPC protocol](https://github.com/srimanachanta/stasis/blob/main/Helper/HelperProtocol.swift): `Helper/HelperProtocol.swift`
- [Charging daemon entry](https://github.com/srimanachanta/stasis/blob/main/ChargingHelper/main.swift): `ChargingHelper/main.swift`
- [Charging daemon](https://github.com/srimanachanta/stasis/blob/main/ChargingHelper/ChargingHelper.swift): `ChargingHelper/ChargingHelper.swift`
- [SMC battery access](https://github.com/srimanachanta/stasis/blob/main/SMCPower/SMCBattery.swift): `SMCPower/SMCBattery.swift`
- [SMC adapter access](https://github.com/srimanachanta/stasis/blob/main/SMCPower/SMCAdapter.swift): `SMCPower/SMCAdapter.swift`

### Other components

- **Mac user**
- **macOS power and notification APIs**

## Connections

- Mac user → App startup: launches (evidence: `Stasis/AppDelegate.swift`)
- App startup → Battery service: initializes (evidence: `Stasis/AppDelegate.swift`)
- App startup → Charging policy: creates (evidence: `Stasis/AppDelegate.swift`)
- App startup → Menu view model: creates (evidence: `Stasis/AppDelegate.swift`)
- App startup → Battery menu: builds (evidence: `Stasis/AppDelegate.swift`)
- App startup → Settings window: creates (evidence: `Stasis/AppDelegate.swift`)
- App startup → Menu bar status: creates (evidence: `Stasis/AppDelegate.swift`)
- Menu bar status → Menu view model: reads (evidence: `Stasis/StatusBarManager.swift`)
- Menu bar status → Battery indicator: hosts (evidence: `Stasis/StatusBarManager.swift`)
- Battery menu → Menu view model: reads (evidence: `Stasis/Views/MenuBuilder.swift`)
- Battery menu → Settings window: opens (evidence: `Stasis/Views/MenuBuilder.swift`)
- Battery menu → Power flow diagram: shows (evidence: `Stasis/Views/MenuBuilder.swift`)
- Menu view model → Battery service: observes (evidence: `Stasis/ViewModels/MenuViewModel.swift`)
- Menu view model → Charging policy: observes (evidence: `Stasis/ViewModels/MenuViewModel.swift`)
- Menu view model → System information: reads (evidence: `Stasis/ViewModels/MenuViewModel.swift`)
- Settings window → Settings panels: hosts (evidence: `Stasis/Controllers/SettingsWindowController.swift`)
- Mac user → Menu bar status: views (evidence: `README.md`)
- Mac user → Settings panels: configures (evidence: `README.md`)
- Battery service → IOKit monitoring: starts monitoring (evidence: `Stasis/Services/BatteryService.swift`)
- Battery service → SMC reader connection: uses (evidence: `Stasis/Services/BatteryService.swift`)
- Battery service → SMC reader helper: requests SMC reads (evidence: `Stasis/Services/BatteryService.swift`)
- Battery service → Battery metrics: updates (evidence: `Stasis/Services/BatteryService.swift`)
- Charging policy → Battery service: evaluates and commands (evidence: `Stasis/Services/ChargeManager.swift`)
- Battery service → Charging helper manager: uses (evidence: `Stasis/Services/BatteryService.swift`)
- Charging helper manager → Charging XPC protocol: connects through (evidence: `Stasis/Services/ChargingHelperManager.swift`)
- Reader helper entry → SMC reader helper: instantiates (evidence: `Helper/main.swift`)
- SMC reader helper → Reader XPC protocol: implements (evidence: `Helper/Helper.swift`)
- SMC reader helper → SMC battery access: reads and probes (evidence: `Helper/Helper.swift`)
- SMC reader helper → SMC adapter access: reads and probes (evidence: `Helper/Helper.swift`)
- Charging daemon entry → Charging daemon: instantiates (evidence: `ChargingHelper/main.swift`)
- Charging daemon → Charging XPC protocol: implements (evidence: `ChargingHelper/ChargingHelper.swift`)
- Charging daemon → SMC battery access: controls charging (evidence: `ChargingHelper/ChargingHelper.swift`)
- Charging daemon → SMC adapter access: controls LED (evidence: `ChargingHelper/ChargingHelper.swift`)
- Battery service → macOS power and notification APIs: uses IOKit (evidence: `Stasis/Services/BatteryService.swift`)
- Charging policy → macOS power and notification APIs: asserts sleep and notifies (evidence: `Stasis/Services/ChargeManager.swift`)
