# tomheaton/menustats architecture

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

- Interactive diagram: https://gitdiagram.com/tomheaton/menustats
- Repository: https://github.com/tomheaton/menustats

## Overview

MenuStats is a macOS menu-bar monitor. At launch, its AppKit delegate starts a two-second refresh loop, reads CPU, memory, and SMC sensor data, then updates the status item and dropdown with current values and three-minute graphs. The dropdown also ranks app memory use and links to Activity Monitor. The sampled sources show the principal collectors and presentation components; the operating-system interfaces are external. Relationships shown here are limited to calls visible in the excerpts.

Main entry points: [`Sources/main.swift`](https://github.com/tomheaton/menustats/blob/main/Sources/main.swift) (App delegate), [`Sources/Stats.swift`](https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift) (CPU stats), [`Sources/SMC.swift`](https://github.com/tomheaton/menustats/blob/main/Sources/SMC.swift) (Sensor readings), [`Sources/Graph.swift`](https://github.com/tomheaton/menustats/blob/main/Sources/Graph.swift) (Graph rendering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Menu Bar App"]
  node_delegate["App delegate<br/>[main.swift]"]
end

subgraph group_collect["System Collection"]
  node_cpu["CPU stats<br/>[Stats.swift]"]
  node_memory["Memory stats<br/>[Stats.swift]"]
  node_appmemory["App memory ranking<br/>[Stats.swift]"]
  node_sensors["Sensor readings<br/>[SMC.swift]"]
  node_smc["SMC access<br/>[SMC.swift]"]
end

subgraph group_present["Display"]
  node_graph["Graph rendering<br/>[Graph.swift]"]
end

node_user(("Mac user"))
node_macos["macOS APIs"]
node_activity["Activity Monitor"]

node_user -->|"uses"| node_delegate
node_delegate -->|"reads ticks"| node_cpu
node_delegate -->|"computes usage"| node_cpu
node_delegate -->|"reads"| node_memory
node_delegate -->|"reads"| node_sensors
node_delegate -->|"ranks apps"| node_appmemory
node_delegate -->|"updates graphs"| node_graph
node_delegate -->|"opens Activity Monitor"| node_macos
node_smc -->|"calls IOKit"| node_macos
node_sensors -->|"reads keys"| node_smc
node_cpu -->|"reads host stats"| node_macos
node_memory -->|"reads VM stats"| node_macos

click node_delegate "https://github.com/tomheaton/menustats/blob/main/Sources/main.swift"
click node_cpu "https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift"
click node_memory "https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift"
click node_appmemory "https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift"
click node_sensors "https://github.com/tomheaton/menustats/blob/main/Sources/SMC.swift"
click node_smc "https://github.com/tomheaton/menustats/blob/main/Sources/SMC.swift"
click node_graph "https://github.com/tomheaton/menustats/blob/main/Sources/Graph.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_delegate,node_user toneBlue
class node_cpu,node_memory,node_appmemory,node_sensors,node_smc toneAmber
class node_graph,node_macos toneMint
class node_activity toneIndigo
```

## Components

### Menu Bar App

- [App delegate](https://github.com/tomheaton/menustats/blob/main/Sources/main.swift): `Sources/main.swift`

### System Collection

- [CPU stats](https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift): `Sources/Stats.swift`
- [Memory stats](https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift): `Sources/Stats.swift`
- [App memory ranking](https://github.com/tomheaton/menustats/blob/main/Sources/Stats.swift): `Sources/Stats.swift`
- [Sensor readings](https://github.com/tomheaton/menustats/blob/main/Sources/SMC.swift): `Sources/SMC.swift`
- [SMC access](https://github.com/tomheaton/menustats/blob/main/Sources/SMC.swift): `Sources/SMC.swift`

### Display

- [Graph rendering](https://github.com/tomheaton/menustats/blob/main/Sources/Graph.swift): `Sources/Graph.swift`

### Other components

- **Mac user**
- **macOS APIs**
- **Activity Monitor**

## Connections

- Mac user → App delegate: uses (evidence: `README.md`)
- App delegate → CPU stats: reads ticks (evidence: `Sources/main.swift`)
- App delegate → CPU stats: computes usage (evidence: `Sources/main.swift`)
- App delegate → Memory stats: reads (evidence: `Sources/main.swift`)
- App delegate → Sensor readings: reads (evidence: `Sources/main.swift`)
- App delegate → App memory ranking: ranks apps (evidence: `Sources/main.swift`)
- App delegate → Graph rendering: updates graphs (evidence: `Sources/main.swift`)
- App delegate → macOS APIs: opens Activity Monitor (evidence: `Sources/main.swift`)
- SMC access → macOS APIs: calls IOKit (evidence: `Sources/SMC.swift`)
- Sensor readings → SMC access: reads keys (evidence: `Sources/SMC.swift`)
- CPU stats → macOS APIs: reads host stats (evidence: `Sources/Stats.swift`)
- Memory stats → macOS APIs: reads VM stats (evidence: `Sources/Stats.swift`)
