# nirvanasangsara-ai/phosphor-hud architecture

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

- Interactive diagram: https://gitdiagram.com/nirvanasangsara-ai/phosphor-hud
- Repository: https://github.com/nirvanasangsara-ai/phosphor-hud

## Overview

Phosphor is a cross-platform AI subscription-usage HUD, led by a native macOS menu-bar app. The main workflow is local provider/account discovery and usage collection, followed by quota and burn-rate calculation, then a consolidated panel with reset and billing context. Local session logs also support token-cost and subscription-ROI views; optional GitHub PR metrics add a separate engineering-efficiency feature. Windows ports core calculations into a Tauri HUD. The graph includes documented capabilities whose implementation was not sampled; those links cite the README rather than imply source inspection.

Main entry points: [`Sources/Phosphor/Views.swift`](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Views.swift) (HUD views), [`Sources/Phosphor/Store.swift`](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Store.swift) (Usage store), [`windows/phosphor-core/src/collect.rs`](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/collect.rs) (HUD collection), [`Sources/Phosphor/App.swift`](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/App.swift) (App lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mac["macOS HUD"]
  node_app["App lifecycle<br/>[App.swift]"]
  node_views["HUD views<br/>[Views.swift]"]
  node_store["Usage store<br/>[Store.swift]"]
  node_accounts["Accounts<br/>[Accounts.swift]"]
  node_devview["PR dashboard<br/>[DevStatsView.swift]"]
  node_theme["Theme system<br/>[Theme.swift]"]
  node_builtin["Built-in themes"]
  node_icon["Quota icon color<br/>[IconColor.swift]"]
  node_crt["CRT icon<br/>[CRTIcon.swift]"]
  node_localization["Localization<br/>[L10n.swift]"]
  node_connect["Service connection<br/>[Connect.swift]"]
end

subgraph group_usage["Usage and insights"]
  node_providers["Provider readers<br/>[Providers.swift]"]
  node_registry["Provider discovery<br/>[Registry.swift]"]
  node_auth["OAuth refresh<br/>[AuthRefresh.swift]"]
  node_logs["Log scanning<br/>[LogScanner.swift]"]
  node_parsers["Log parsers<br/>[LogParsers.swift]"]
  node_tokenusage["Token accounting<br/>[TokenUsage.swift]"]
  node_forecast["Quota forecast<br/>[Forecast.swift]"]
  node_pricing["Usage pricing<br/>[Pricing.swift]"]
  node_devstats["PR insights<br/>[DevStats.swift]"]
  node_status["Status readings"]
end

subgraph group_windows["Windows HUD"]
  node_wincollect["HUD collection<br/>[collect.rs]"]
  node_winquota["Quota readings<br/>[quota.rs]"]
  node_winpaths["Local paths<br/>[paths.rs]"]
  node_winpricing["Pricing math<br/>[pricing.rs]"]
  node_wintime["Time utilities<br/>[timeutil.rs]"]
  node_winledger["Usage ledger<br/>[ledger.rs]"]
  node_winui["Windows HUD<br/>[app.js]"]
end

subgraph group_integrations["External services"]
  node_gh["GitHub services"]
  node_providersvc["AI providers"]
end

node_user(("User"))

node_user -->|"opens HUD"| node_app
node_app -->|"shows panel"| node_views
node_app -.->|"refreshes readings"| node_store
node_store -.->|"discovers services"| node_registry
node_store -.->|"collects usage"| node_providers
node_providers -->|"refreshes tokens"| node_auth
node_providers -->|"reads provider usage"| node_providersvc
node_store -.->|"loads account details"| node_accounts
node_views -->|"shows burn rate"| node_forecast
node_store -->|"scans local sessions"| node_logs
node_logs -->|"parses records"| node_parsers
node_logs -->|"aggregates tokens"| node_tokenusage
node_views -->|"shows ROI"| node_pricing
node_devview -->|"shows PR metrics"| node_devstats
node_devstats -->|"queries read-only"| node_gh
node_views -->|"renders themed HUD"| node_theme
node_theme -->|"loads defaults"| node_builtin
node_views -->|"colors quota bars"| node_icon
node_views -->|"renders icon"| node_crt
node_views -->|"localizes interface"| node_localization
node_views -->|"offers setup guidance"| node_connect
node_views -->|"shows status dots"| node_status
node_user -->|"uses Windows HUD"| node_winui
node_winui -.->|"requests readings"| node_wincollect
node_wincollect -->|"collects quotas"| node_winquota
node_wincollect -->|"reads local files"| node_winpaths
node_wincollect -->|"uses session logs"| node_winledger
node_winledger -->|"prices usage"| node_winpricing
node_winquota -->|"formats reset times"| node_wintime
node_wincollect -->|"reads provider limits"| node_providersvc

click node_app "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/App.swift"
click node_views "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Views.swift"
click node_store "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Store.swift"
click node_accounts "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Accounts.swift"
click node_providers "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Providers.swift"
click node_registry "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Registry.swift"
click node_auth "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/AuthRefresh.swift"
click node_logs "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/LogScanner.swift"
click node_parsers "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/LogParsers.swift"
click node_tokenusage "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/TokenUsage.swift"
click node_forecast "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/Forecast.swift"
click node_pricing "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/Pricing.swift"
click node_devstats "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/DevStats.swift"
click node_devview "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/DevStatsView.swift"
click node_theme "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Theme.swift"
click node_builtin "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/BuiltinThemes.swift"
click node_icon "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/IconColor.swift"
click node_crt "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/CRTIcon.swift"
click node_localization "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/L10n.swift"
click node_connect "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Connect.swift"
click node_status "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/ServiceStatus.swift"
click node_wincollect "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/collect.rs"
click node_winquota "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/quota.rs"
click node_winpaths "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/paths.rs"
click node_winpricing "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/pricing.rs"
click node_wintime "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/timeutil.rs"
click node_winledger "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/ledger.rs"
click node_winui "https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-hud/ui/app.js"

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_views,node_store,node_accounts,node_devview,node_theme,node_builtin,node_icon,node_crt,node_localization,node_connect,node_user toneBlue
class node_providers,node_registry,node_auth,node_logs,node_parsers,node_tokenusage,node_forecast,node_pricing,node_devstats,node_status toneAmber
class node_wincollect,node_winquota,node_winpaths,node_winpricing,node_wintime,node_winledger,node_winui toneMint
class node_gh,node_providersvc toneRose
```

## Components

### macOS HUD

- [App lifecycle](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/App.swift): `Sources/Phosphor/App.swift`
- [HUD views](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Views.swift): `Sources/Phosphor/Views.swift`
- [Usage store](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Store.swift): `Sources/Phosphor/Store.swift`
- [Accounts](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Accounts.swift): `Sources/Phosphor/Accounts.swift`
- [PR dashboard](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/DevStatsView.swift): `Sources/Phosphor/DevStatsView.swift`
- [Theme system](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Theme.swift): `Sources/Phosphor/Theme.swift`
- [Built-in themes](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/BuiltinThemes.swift): `Sources/Phosphor/BuiltinThemes.swift`
- [Quota icon color](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/IconColor.swift): `Sources/PhosphorCore/IconColor.swift`
- [CRT icon](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/CRTIcon.swift): `Sources/Phosphor/CRTIcon.swift`
- [Localization](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/L10n.swift): `Sources/PhosphorCore/L10n.swift`
- [Service connection](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Connect.swift): `Sources/Phosphor/Connect.swift`

### Usage and insights

- [Provider readers](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Providers.swift): `Sources/Phosphor/Providers.swift`
- [Provider discovery](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/Registry.swift): `Sources/Phosphor/Registry.swift`
- [OAuth refresh](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/AuthRefresh.swift): `Sources/Phosphor/AuthRefresh.swift`
- [Log scanning](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/LogScanner.swift): `Sources/PhosphorCore/LogScanner.swift`
- [Log parsers](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/LogParsers.swift): `Sources/PhosphorCore/LogParsers.swift`
- [Token accounting](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/TokenUsage.swift): `Sources/PhosphorCore/TokenUsage.swift`
- [Quota forecast](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/Forecast.swift): `Sources/PhosphorCore/Forecast.swift`
- [Usage pricing](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/Pricing.swift): `Sources/PhosphorCore/Pricing.swift`
- [PR insights](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/Phosphor/DevStats.swift): `Sources/Phosphor/DevStats.swift`
- [Status readings](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/Sources/PhosphorCore/ServiceStatus.swift): `Sources/PhosphorCore/ServiceStatus.swift`

### Windows HUD

- [HUD collection](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/collect.rs): `windows/phosphor-core/src/collect.rs`
- [Quota readings](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/quota.rs): `windows/phosphor-core/src/quota.rs`
- [Local paths](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/paths.rs): `windows/phosphor-core/src/paths.rs`
- [Pricing math](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/pricing.rs): `windows/phosphor-core/src/pricing.rs`
- [Time utilities](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/timeutil.rs): `windows/phosphor-core/src/timeutil.rs`
- [Usage ledger](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-core/src/ledger.rs): `windows/phosphor-core/src/ledger.rs`
- [Windows HUD](https://github.com/nirvanasangsara-ai/phosphor-hud/blob/main/windows/phosphor-hud/ui/app.js): `windows/phosphor-hud/ui/app.js`

### External services

- **GitHub services**
- **AI providers**

### Other components

- **User**

## Connections

- User → App lifecycle: opens HUD
- App lifecycle → HUD views: shows panel
- App lifecycle → Usage store: refreshes readings
- Usage store → Provider discovery: discovers services
- Usage store → Provider readers: collects usage
- Provider readers → OAuth refresh: refreshes tokens (evidence: `Sources/Phosphor/Providers.swift`)
- Provider readers → AI providers: reads provider usage (evidence: `Sources/Phosphor/Providers.swift`)
- Usage store → Accounts: loads account details
- HUD views → Quota forecast: shows burn rate (evidence: `Sources/Phosphor/Views.swift`)
- Usage store → Log scanning: scans local sessions
- Log scanning → Log parsers: parses records (evidence: `Sources/PhosphorCore/LogScanner.swift`)
- Log scanning → Token accounting: aggregates tokens (evidence: `Sources/Phosphor/UsageLogs.swift`)
- HUD views → Usage pricing: shows ROI
- PR dashboard → PR insights: shows PR metrics
- PR insights → GitHub services: queries read-only
- HUD views → Theme system: renders themed HUD (evidence: `Sources/Phosphor/Views.swift`)
- Theme system → Built-in themes: loads defaults (evidence: `Sources/Phosphor/Theme.swift`)
- HUD views → Quota icon color: colors quota bars (evidence: `Sources/Phosphor/Views.swift`)
- HUD views → CRT icon: renders icon (evidence: `Sources/Phosphor/Views.swift`)
- HUD views → Localization: localizes interface
- HUD views → Service connection: offers setup guidance (evidence: `Sources/Phosphor/Views.swift`)
- HUD views → Status readings: shows status dots
- User → Windows HUD: uses Windows HUD
- Windows HUD → HUD collection: requests readings
- HUD collection → Quota readings: collects quotas (evidence: `windows/phosphor-core/src/collect.rs`)
- HUD collection → Local paths: reads local files (evidence: `windows/phosphor-core/src/collect.rs`)
- HUD collection → Usage ledger: uses session logs (evidence: `windows/phosphor-core/src/collect.rs`)
- Usage ledger → Pricing math: prices usage (evidence: `windows/phosphor-core/src/ledger.rs`)
- Quota readings → Time utilities: formats reset times (evidence: `windows/phosphor-core/src/quota.rs`)
- HUD collection → AI providers: reads provider limits (evidence: `windows/phosphor-core/src/collect.rs`)
