# rurza/batfi architecture

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

- Interactive diagram: https://gitdiagram.com/rurza/batfi
- Repository: https://github.com/rurza/batfi

## Overview

BatFi is a macOS battery-management app for Apple Silicon that lets users set charging limits and temporarily override them, including charging to 100% or discharging. The app’s main workflow runs from its menu-bar controls and settings into charging policy, which acts through system clients and a privileged helper; the UI also presents battery and power information. Onboarding, notifications, charts, and energy-use monitoring are distinct capabilities. Some subsystem links are based on the SOURCE INDEX or README because their implementation excerpts were not supplied.

Main entry points: [`BatFiKit/Sources/App/App.swift`](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/App/App.swift) (BatFi app), [`BatFiKit/Sources/AppCore/ChargingManager.swift`](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/ChargingManager.swift) (Charging policy), [`BatFiKit/Sources/AppCore/MenuContent.swift`](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/MenuContent.swift) (Menu content), [`BatFiKit/Sources/AppCore/StatusItemManager.swift`](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/StatusItemManager.swift) (Menu bar)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and Controls"]
  node_app["BatFi app<br/>[App.swift]"]
  node_settings["Settings<br/>[Settings.swift]"]
  node_onboarding["Onboarding<br/>[Onboarding.swift]"]
  node_shortcuts["App shortcuts<br/>[AppShortcuts.swift]"]
  node_status["Menu bar"]
  node_menu["Menu content<br/>[MenuContent.swift]"]
end

subgraph group_battery["Battery Management"]
  node_charging["Charging policy"]
  node_mode["Charging modes"]
  node_notifications["Notifications"]
  node_mag_safe["MagSafe indicator"]
  node_persistence[("Persistence<br/>[Persistence.swift]")]
end

subgraph group_helper["Helper and System"]
  node_helper_connection["Helper connection"]
  node_helper_client["Helper client<br/>[HelperClient.swift]"]
  node_xpc["XPC service<br/>[XPCService.swift]"]
  node_server["Privileged helper<br/>[Server.swift]"]
end

subgraph group_insight["Battery Insights"]
  node_power_state["Power state<br/>[PowerState.swift]"]
  node_battery_info["Battery information<br/>[BatteryInfo.swift]"]
  node_charts["Power charts<br/>[ChartsView.swift]"]
  node_energy["Energy usage"]
end

node_user(("Mac user"))
node_system{{"macOS battery services"}}

node_user -->|"uses"| node_app
node_app -->|"presents"| node_onboarding
node_app -->|"starts"| node_charging
node_app -->|"starts"| node_status
node_app -->|"opens"| node_settings
node_user -->|"configures"| node_settings
node_user -->|"controls"| node_status
node_status -->|"renders"| node_menu
node_menu -->|"displays"| node_battery_info
node_menu -->|"displays"| node_charts
node_menu -->|"displays"| node_energy
node_status -->|"invokes overrides"| node_charging
node_charging -->|"sets mode"| node_mode
node_charging -->|"observes"| node_power_state
node_app -->|"starts"| node_notifications
node_app -->|"starts"| node_mag_safe
node_app -->|"checks helper"| node_helper_connection
node_helper_connection -->|"checks health"| node_helper_client
node_charging -.->|"controls charging"| node_system
node_helper_client -.->|"communicates"| node_xpc
node_server -.->|"serves"| node_xpc
node_charging -.->|"stores state"| node_persistence
node_shortcuts -.->|"requests actions"| node_charging
node_power_state -.->|"informs display"| node_battery_info

click node_app "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/App/App.swift"
click node_settings "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Settings/Settings.swift"
click node_onboarding "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Onboarding/Onboarding.swift"
click node_shortcuts "https://github.com/rurza/batfi/blob/main/App/AppShortcuts.swift"
click node_status "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/StatusItemManager.swift"
click node_menu "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/MenuContent.swift"
click node_charging "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/ChargingManager.swift"
click node_mode "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppShared/AppChargingMode.swift"
click node_notifications "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Notifications/NotificationsManager.swift"
click node_mag_safe "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/MagSafeColorManager.swift"
click node_persistence "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Clients/Persistence.swift"
click node_helper_connection "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/App/HelperConnectionManager.swift"
click node_helper_client "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Clients/HelperClient.swift"
click node_xpc "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Shared/XPCService.swift"
click node_server "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Server/Server.swift"
click node_power_state "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppShared/PowerState.swift"
click node_battery_info "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Shared/BatteryInfo.swift"
click node_charts "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/PowerCharts/ChartsView.swift"
click node_energy "https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/HighEnergyUsage/HighEnergyUsageView.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_settings,node_onboarding,node_shortcuts,node_status,node_menu,node_user toneBlue
class node_charging,node_mode,node_notifications,node_mag_safe,node_persistence toneAmber
class node_helper_connection,node_helper_client,node_xpc,node_server toneMint
class node_power_state,node_battery_info,node_charts,node_energy toneRose
class node_system toneIndigo
```

## Components

### App and Controls

- [BatFi app](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/App/App.swift): `BatFiKit/Sources/App/App.swift`
- [Settings](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Settings/Settings.swift): `BatFiKit/Sources/Settings/Settings.swift`
- [Onboarding](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Onboarding/Onboarding.swift): `BatFiKit/Sources/Onboarding/Onboarding.swift`
- [App shortcuts](https://github.com/rurza/batfi/blob/main/App/AppShortcuts.swift): `App/AppShortcuts.swift`
- [Menu bar](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/StatusItemManager.swift): `BatFiKit/Sources/AppCore/StatusItemManager.swift`
- [Menu content](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/MenuContent.swift): `BatFiKit/Sources/AppCore/MenuContent.swift`

### Battery Management

- [Charging policy](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/ChargingManager.swift): `BatFiKit/Sources/AppCore/ChargingManager.swift`
- [Charging modes](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppShared/AppChargingMode.swift): `BatFiKit/Sources/AppShared/AppChargingMode.swift`
- [Notifications](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Notifications/NotificationsManager.swift): `BatFiKit/Sources/Notifications/NotificationsManager.swift`
- [MagSafe indicator](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppCore/MagSafeColorManager.swift): `BatFiKit/Sources/AppCore/MagSafeColorManager.swift`
- [Persistence](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Clients/Persistence.swift): `BatFiKit/Sources/Clients/Persistence.swift`

### Helper and System

- [Helper connection](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/App/HelperConnectionManager.swift): `BatFiKit/Sources/App/HelperConnectionManager.swift`
- [Helper client](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Clients/HelperClient.swift): `BatFiKit/Sources/Clients/HelperClient.swift`
- [XPC service](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Shared/XPCService.swift): `BatFiKit/Sources/Shared/XPCService.swift`
- [Privileged helper](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Server/Server.swift): `BatFiKit/Sources/Server/Server.swift`

### Battery Insights

- [Power state](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/AppShared/PowerState.swift): `BatFiKit/Sources/AppShared/PowerState.swift`
- [Battery information](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/Shared/BatteryInfo.swift): `BatFiKit/Sources/Shared/BatteryInfo.swift`
- [Power charts](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/PowerCharts/ChartsView.swift): `BatFiKit/Sources/PowerCharts/ChartsView.swift`
- [Energy usage](https://github.com/rurza/batfi/blob/main/BatFiKit/Sources/HighEnergyUsage/HighEnergyUsageView.swift): `BatFiKit/Sources/HighEnergyUsage/HighEnergyUsageView.swift`

### Other components

- **Mac user**
- **macOS battery services**

## Connections

- Mac user → BatFi app: uses
- BatFi app → Onboarding: presents (evidence: `BatFiKit/Sources/App/App.swift`)
- BatFi app → Charging policy: starts (evidence: `BatFiKit/Sources/App/App.swift`)
- BatFi app → Menu bar: starts (evidence: `BatFiKit/Sources/App/App.swift`)
- BatFi app → Settings: opens (evidence: `BatFiKit/Sources/App/App.swift`)
- Mac user → Settings: configures (evidence: `BatFiKit/Sources/Settings/Settings.swift`)
- Mac user → Menu bar: controls (evidence: `BatFiKit/Sources/AppCore/StatusItemManager.swift`)
- Menu bar → Menu content: renders (evidence: `BatFiKit/Sources/AppCore/StatusItemManager.swift`)
- Menu content → Battery information: displays (evidence: `BatFiKit/Sources/AppCore/MenuContent.swift`)
- Menu content → Power charts: displays (evidence: `BatFiKit/Sources/AppCore/MenuContent.swift`)
- Menu content → Energy usage: displays (evidence: `BatFiKit/Sources/AppCore/MenuContent.swift`)
- Menu bar → Charging policy: invokes overrides (evidence: `BatFiKit/Sources/AppCore/StatusItemManager.swift`)
- Charging policy → Charging modes: sets mode (evidence: `BatFiKit/Sources/AppCore/ChargingManager.swift`)
- Charging policy → Power state: observes (evidence: `BatFiKit/Sources/AppCore/ChargingManager.swift`)
- BatFi app → Notifications: starts (evidence: `BatFiKit/Sources/App/App.swift`)
- BatFi app → MagSafe indicator: starts (evidence: `BatFiKit/Sources/App/App.swift`)
- BatFi app → Helper connection: checks helper (evidence: `BatFiKit/Sources/App/App.swift`)
- Helper connection → Helper client: checks health (evidence: `BatFiKit/Sources/App/HelperConnectionManager.swift`)
- Charging policy → macOS battery services: controls charging
- Helper client → XPC service: communicates
- Privileged helper → XPC service: serves
- Charging policy → Persistence: stores state
- App shortcuts → Charging policy: requests actions
- Power state → Battery information: informs display
