# az-code-lab/ampere architecture

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

- Interactive diagram: https://gitdiagram.com/az-code-lab/ampere
- Repository: https://github.com/az-code-lab/ampere
- Video tour (about a minute): https://gitdiagram.com/az-code-lab/ampere/video

## Overview

Ampere is a macOS menu-bar battery monitor and charge manager. Its principal workflow samples battery and power state, applies automatic or user-requested charging policy, and uses a privileged helper to change charging or sleep-related system state; the app then presents live status and controls. Other documented branches include registration, updates, keep-awake, and helper lifecycle cleanup. The excerpts establish key calls but omit much of the app UI and monitoring implementation, so uncertain subsystem wiring is left out.

Main entry points: [`Sources/Ampere/App.swift`](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/App.swift) (Menu Bar UI), [`Sources/Ampere/BatteryInfo.swift`](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.swift) (Charge Policy), [`Sources/SMCWriter/main.swift`](https://github.com/az-code-lab/ampere/blob/master/Sources/SMCWriter/main.swift) (SMC Writer), [`Sources/Ampere/main.swift`](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/main.swift) (App Launch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Menu Bar App"]
  node_appentry["App Launch<br/>[main.swift]"]
  node_appui["Menu Bar UI<br/>[App.swift]"]
end

subgraph group_charging["Charge Management"]
  node_battery["Battery Monitor<br/>[BatteryInfo.swift]"]
  node_policy["Charge Policy<br/>[BatteryInfo.swift]"]
end

subgraph group_privilege["Privileged Helper"]
  node_smc["SMC Writer<br/>[main.swift]"]
  node_native["Native Charge Limit"]
  node_pmset["Sleep State<br/>[PmsetState.swift]"]
  node_helpersetup["Helper Setup<br/>[HelperSetup.swift]"]
  node_cleanup["Cleanup Daemon"]
  node_uninstall["Helper Uninstall"]
end

subgraph group_services["App Services"]
  node_registration["Registration<br/>[Registration.swift]"]
  node_updater["In-App Updater<br/>[Updater.swift]"]
  node_keepawake["Keep Awake<br/>[BatteryInfo.swift]"]
end

node_user(("Mac User"))
node_macos["macOS Power APIs"]
node_license["License Service"]
node_cask["Homebrew Cask"]

node_user -->|"controls"| node_appui
node_appentry -->|"launches"| node_appui
node_appui -->|"shows status"| node_battery
node_battery -->|"samples power"| node_macos
node_appui -->|"sets modes"| node_policy
node_battery -->|"feeds state"| node_policy
node_policy -->|"requests writes"| node_smc
node_smc -->|"sets SMC state"| node_macos
node_policy -.->|"uses charge limit"| node_native
node_native -->|"updates limit"| node_macos
node_policy -->|"manages sleep"| node_pmset
node_pmset -->|"changes sleep settings"| node_macos
node_appentry -->|"sets up helper"| node_helpersetup
node_appui -->|"toggles assertion"| node_keepawake
node_keepawake -->|"holds awake"| node_macos
node_appui -->|"registers"| node_registration
node_registration -->|"verifies license"| node_license
node_appui -->|"checks and installs"| node_updater
node_updater -->|"checks release"| node_cask
node_appentry -->|"registers cleanup"| node_cleanup
node_cleanup -->|"invokes helper"| node_smc
node_smc -->|"cleans artifacts"| node_uninstall

click node_appentry "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/main.swift"
click node_appui "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/App.swift"
click node_battery "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.swift"
click node_policy "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.swift"
click node_smc "https://github.com/az-code-lab/ampere/blob/master/Sources/SMCWriter/main.swift"
click node_native "https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/NativeChargeLimit.swift"
click node_pmset "https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/PmsetState.swift"
click node_helpersetup "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/HelperSetup.swift"
click node_cleanup "https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/CleanupDaemon.swift"
click node_uninstall "https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/HelperUninstall.swift"
click node_registration "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/Registration.swift"
click node_updater "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/Updater.swift"
click node_keepawake "https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.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_appentry,node_appui,node_user toneBlue
class node_battery,node_policy toneAmber
class node_smc,node_native,node_pmset,node_helpersetup,node_cleanup,node_uninstall,node_macos toneMint
class node_registration,node_updater,node_keepawake toneRose
class node_license,node_cask toneIndigo
```

## Components

### Menu Bar App

- [App Launch](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/main.swift): `Sources/Ampere/main.swift`
- [Menu Bar UI](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/App.swift): `Sources/Ampere/App.swift`

### Charge Management

- [Battery Monitor](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.swift): `Sources/Ampere/BatteryInfo.swift`
- [Charge Policy](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.swift): `Sources/Ampere/BatteryInfo.swift`

### Privileged Helper

- [SMC Writer](https://github.com/az-code-lab/ampere/blob/master/Sources/SMCWriter/main.swift): `Sources/SMCWriter/main.swift`
- [Native Charge Limit](https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/NativeChargeLimit.swift): `Sources/Shared/NativeChargeLimit.swift`
- [Sleep State](https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/PmsetState.swift): `Sources/Shared/PmsetState.swift`
- [Helper Setup](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/HelperSetup.swift): `Sources/Ampere/HelperSetup.swift`
- [Cleanup Daemon](https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/CleanupDaemon.swift): `Sources/Shared/CleanupDaemon.swift`
- [Helper Uninstall](https://github.com/az-code-lab/ampere/blob/master/Sources/Shared/HelperUninstall.swift): `Sources/Shared/HelperUninstall.swift`

### App Services

- [Registration](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/Registration.swift): `Sources/Ampere/Registration.swift`
- [In-App Updater](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/Updater.swift): `Sources/Ampere/Updater.swift`
- [Keep Awake](https://github.com/az-code-lab/ampere/blob/master/Sources/Ampere/BatteryInfo.swift): `Sources/Ampere/BatteryInfo.swift`

### Other components

- **Mac User**
- **macOS Power APIs**
- **License Service**
- **Homebrew Cask**

## Connections

- Mac User → Menu Bar UI: controls
- App Launch → Menu Bar UI: launches
- Menu Bar UI → Battery Monitor: shows status
- Battery Monitor → macOS Power APIs: samples power
- Menu Bar UI → Charge Policy: sets modes
- Battery Monitor → Charge Policy: feeds state
- Charge Policy → SMC Writer: requests writes
- SMC Writer → macOS Power APIs: sets SMC state
- Charge Policy → Native Charge Limit: uses charge limit
- Native Charge Limit → macOS Power APIs: updates limit
- Charge Policy → Sleep State: manages sleep
- Sleep State → macOS Power APIs: changes sleep settings
- App Launch → Helper Setup: sets up helper
- Menu Bar UI → Keep Awake: toggles assertion
- Keep Awake → macOS Power APIs: holds awake
- Menu Bar UI → Registration: registers
- Registration → License Service: verifies license
- Menu Bar UI → In-App Updater: checks and installs
- In-App Updater → Homebrew Cask: checks release
- App Launch → Cleanup Daemon: registers cleanup
- Cleanup Daemon → SMC Writer: invokes helper
- SMC Writer → Helper Uninstall: cleans artifacts
