# hearthsim/hstracker architecture

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

- Interactive diagram: https://gitdiagram.com/hearthsim/hstracker
- Repository: https://github.com/hearthsim/hstracker

## Overview

#### Purpose and Runtime
HSTracker is a native macOS automatic Hearthstone deck tracker and deck manager. It is an Xcode Swift/Objective-C app; `HSTracker/AppDelegate.swift` is the application entry point, with target/build definition in `HSTracker.xcodeproj/project.pbxproj`. App UI is AppKit/XIB-based and supports persistent overlay windows above Hearthstone.

#### Live Game Ingestion
The logging subsystem follows Hearthstone log output, parses game-state events, and maintains the canonical live-match model. `HSTracker/Logging/LogReaderManager.swift` coordinates readers; `HSTracker/Logging/Parsers/PowerGameStateParser.swift` and `HSTracker/Logging/CoreManager.swift` translate log lines into entities, players, turns, zones, and game lifecycle events. This is the primary control-flow boundary between external game data and tracker behavior.

#### Game-State Observation and Native Integration
Watchers infer client UI/mode transitions not covered solely by parsed logs, feeding feature-specific state updates. Key components include `HSTracker/HearthWatcher/SceneWatcher.swift`, `HSTracker/HearthWatcher/BaconWatcher.swift`, and `HSTracker/HearthWatcher/DeckPickerWatcher.swift`. `HSTracker/HearthMirror/MirrorHelper.swift` and `HSTracker/Mono/MonoHelper.swift` form lower-level integration boundaries to Hearthstone process/runtime data; Mono proxies and simulation support are isolated under `HSTracker/Mono/`.

#### Hearthstone Domain Rules
`HSTracker/Hearthstone/Hearthstone.swift` connects parsed state to domain features. Rules are decomposed into dynamic counters (`HSTracker/Hearthstone/CounterSystem/CounterManager.swift`), active enchantment/effect interpretation (`HSTracker/Hearthstone/EffectSystem/Factory/EffectFactory.swift`), secrets (`HSTracker/Hearthstone/Secrets/SecretsManager.swift`), and related/generated-card prediction (`HSTracker/Hearthstone/RelatedCardsSystem/RelatedCardsManager.swift`). These systems consume entity/tag updates and produce displayable derived state.

#### Storage, Decks, and Imports
Local persistence covers card metadata, decks, and historical game statistics through `HSTracker/Database/Database.swift` and models such as `HSTracker/Database/Models/Deck.swift` and `HSTracker/Database/Models/GameStats.swift`. Deck creation/import paths are separate adapters: `HSTracker/Importers/DeckImporter.swift`, `HSTracker/Importers/ClipboardImporter.swift`, and `HSTracker/Importers/DeckSerializer.swift`. Card lookup and legality depend on the local database rather than the live logging pipeline.

#### Overlays and Application UI
The presentation layer renders live state into multiple independent AppKit windows/overlays. `HSTracker/UIs/Trackers/WindowManager.swift` and `HSTracker/UIs/Trackers/OverWindowController.swift` manage overlay placement/lifetime; deck and card HUDs are in `HSTracker/UIs/Trackers/CardHud.swift`. Feature screens include deck management (`HSTracker/UIs/DeckManager/DeckManager.swift`), Battlegrounds overlays (`HSTracker/UIs/Battlegrounds/BattlegroundsOverlay.swift`), and constructed mulligan guidance (`HSTracker/UIs/Constructed/Mulligan/ConstructedMulliganGuide.swift`).

#### External Services and Analytics
HSReplay.net is the principal remote service: `HSTracker/HSReplay/HSReplayManager.swift` coordinates account/API workflows, `HSTracker/HSReplay/HSReplayAPI.swift` defines service access, and `HSTracker/HSReplay/LogUploader.swift` uploads game logs. Shared HTTP transport is under `HSTracker/Network/Http.swift`. Telemetry/error integrations are represented by `HSTracker/Utility/Analytics/Influx.swift` and `HSTracker/Utility/Analytics/Sentry.swift`; remote behavior/config can be mediated by `HSTracker/Utility/RemoteConfig.swift`.

#### Specialized Battlegrounds Simulation
Battlegrounds state has dedicated model, watcher, UI, and simulation paths. `HSTracker/Hearthstone/BattlegroundsBoardState.swift` captures board state; `HSTracker/BobsBuddy/BobsBuddyInvoker.swift` invokes combat analysis; `HSTracker/Mono/SimulationRunner.swift` bridges simulation execution. Results flow to `HSTracker/UIs/Trackers/BobsBuddyPanel.swift` and Battlegrounds overlays rather than the constructed deck HUD.

Main entry points: [`HSTracker/Hearthstone/Hearthstone.swift`](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/Hearthstone.swift) (Hearthstone Domain), [`HSTracker/UIs/Trackers/CardHud.swift`](https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Trackers/CardHud.swift) (Card HUD), [`HSTracker/AppDelegate.swift`](https://github.com/hearthsim/hstracker/blob/master/HSTracker/AppDelegate.swift) (App Delegate), [`HSTracker/Logging/LogReaderManager.swift`](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/LogReaderManager.swift) (Log Reader Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Live Ingestion"]
  node_log_readers["Log Reader Manager<br/>log coordinator"]
  node_power_parser["Power Game Parser<br/>log parser"]
  node_core_manager["Core Manager<br/>game-state reducer<br/>[CoreManager.swift]"]
  node_watchers["Scene &amp; Mode Watchers<br/>native watcher<br/>[SceneWatcher.swift]"]
  node_hearth_integration{{"Hearth Runtime Bridge<br/>process integration<br/>[MirrorHelper.swift]"}}
end

subgraph group_domain["Game Domain"]
  node_hearthstone["Hearthstone Domain<br/>feature coordinator<br/>[Hearthstone.swift]"]
  node_counters["Counter Manager<br/>derived counters"]
  node_effects["Effect Factory<br/>effect interpreter"]
  node_secrets_related["Secrets &amp; Related Cards<br/>prediction rules"]
  node_bg_state["Battlegrounds Board<br/>board model"]
  node_simulation["Bob's Buddy Simulation<br/>combat analysis"]
end

subgraph group_presentation["Native UI"]
  node_overlays["Overlay Windows<br/>AppKit overlay manager"]
  node_card_hud["Card HUD<br/>live deck overlay<br/>[CardHud.swift]"]
  node_bg_ui["Battlegrounds UI<br/>Battlegrounds overlay"]
  node_deck_manager["Deck Manager<br/>deck screen<br/>[DeckManager.swift]"]
end

subgraph group_data["Data &amp; Services"]
  node_database[("Local Database<br/>persistent store<br/>[Database.swift]")]
  node_deck_import["Deck Import<br/>import adapter<br/>[DeckImporter.swift]"]
  node_hsreplay{{"HSReplay Manager<br/>remote service client"}}
  node_log_uploader["Log Uploader<br/>upload client<br/>[LogUploader.swift]"]
  node_telemetry{{"Telemetry &amp; Remote Config<br/>analytics integration<br/>[Influx.swift]"}}
end

node_app["App Delegate<br/>macOS entry point<br/>[AppDelegate.swift]"]

node_app -->|"starts"| node_log_readers
node_app -->|"launches"| node_overlays
node_app -->|"opens"| node_deck_manager
node_log_readers -->|"log lines"| node_power_parser
node_power_parser -->|"state events"| node_core_manager
node_hearth_integration -->|"runtime signals"| node_watchers
node_watchers -->|"mode updates"| node_hearthstone
node_core_manager -->|"canonical live state"| node_hearthstone
node_hearthstone -->|"entity/tag updates"| node_counters
node_hearthstone -->|"entity/tag updates"| node_effects
node_hearthstone -->|"entity/tag updates"| node_secrets_related
node_hearthstone -->|"Battlegrounds state"| node_bg_state
node_hearthstone -->|"live deck state"| node_card_hud
node_counters -->|"display counters"| node_card_hud
node_effects -->|"active effects"| node_card_hud
node_secrets_related -->|"predictions"| node_card_hud
node_card_hud -->|"hosted in"| node_overlays
node_bg_state -->|"combat state"| node_simulation
node_simulation -->|"combat results"| node_bg_ui
node_bg_state -->|"board state"| node_bg_ui
node_bg_ui -->|"hosted in"| node_overlays
node_deck_import -->|"saves decks"| node_database
node_deck_manager -->|"imports decks"| node_deck_import
node_deck_manager -->|"reads and writes"| node_database
node_hearthstone -->|"card lookup and legality"| node_database
node_log_readers -.->|"game logs"| node_log_uploader
node_log_uploader -->|"uploads via"| node_hsreplay
node_app -.->|"reports events"| node_telemetry

click node_app "https://github.com/hearthsim/hstracker/blob/master/HSTracker/AppDelegate.swift"
click node_log_readers "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/LogReaderManager.swift"
click node_power_parser "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/Parsers/PowerGameStateParser.swift"
click node_core_manager "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/CoreManager.swift"
click node_watchers "https://github.com/hearthsim/hstracker/blob/master/HSTracker/HearthWatcher/SceneWatcher.swift"
click node_hearth_integration "https://github.com/hearthsim/hstracker/blob/master/HSTracker/HearthMirror/MirrorHelper.swift"
click node_hearthstone "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/Hearthstone.swift"
click node_counters "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/CounterSystem/CounterManager.swift"
click node_effects "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/EffectSystem/Factory/EffectFactory.swift"
click node_secrets_related "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/Secrets/SecretsManager.swift"
click node_bg_state "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/BattlegroundsBoardState.swift"
click node_simulation "https://github.com/hearthsim/hstracker/blob/master/HSTracker/BobsBuddy/BobsBuddyInvoker.swift"
click node_overlays "https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Trackers/WindowManager.swift"
click node_card_hud "https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Trackers/CardHud.swift"
click node_bg_ui "https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Battlegrounds/BattlegroundsOverlay.swift"
click node_deck_manager "https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/DeckManager/DeckManager.swift"
click node_database "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Database/Database.swift"
click node_deck_import "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Importers/DeckImporter.swift"
click node_hsreplay "https://github.com/hearthsim/hstracker/blob/master/HSTracker/HSReplay/HSReplayManager.swift"
click node_log_uploader "https://github.com/hearthsim/hstracker/blob/master/HSTracker/HSReplay/LogUploader.swift"
click node_telemetry "https://github.com/hearthsim/hstracker/blob/master/HSTracker/Utility/Analytics/Influx.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_log_readers,node_power_parser,node_core_manager,node_watchers,node_hearth_integration toneBlue
class node_hearthstone,node_counters,node_effects,node_secrets_related,node_bg_state,node_simulation toneAmber
class node_overlays,node_card_hud,node_bg_ui,node_deck_manager toneMint
class node_database,node_deck_import,node_hsreplay,node_log_uploader,node_telemetry toneRose
class node_app toneNeutral
```

## Components

### Live Ingestion

Hearthstone data enters through logs and native observation.

- [Log Reader Manager](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/LogReaderManager.swift): log coordinator · Follows Hearthstone log output. · `HSTracker/Logging/LogReaderManager.swift`
- [Power Game Parser](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/Parsers/PowerGameStateParser.swift): log parser · `HSTracker/Logging/Parsers/PowerGameStateParser.swift`
- [Core Manager](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Logging/CoreManager.swift): game-state reducer · Maintains entities, players, turns, zones, and lifecycle. · `HSTracker/Logging/CoreManager.swift`
- [Scene & Mode Watchers](https://github.com/hearthsim/hstracker/blob/master/HSTracker/HearthWatcher/SceneWatcher.swift): native watcher · Infers client UI and mode transitions. · `HSTracker/HearthWatcher/SceneWatcher.swift`
- [Hearth Runtime Bridge](https://github.com/hearthsim/hstracker/blob/master/HSTracker/HearthMirror/MirrorHelper.swift): process integration · Mirror and Mono access to Hearthstone runtime data. · `HSTracker/HearthMirror/MirrorHelper.swift`

### Game Domain

Canonical match state and derived Hearthstone rules.

- [Hearthstone Domain](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/Hearthstone.swift): feature coordinator · Connects live state to tracker features. · `HSTracker/Hearthstone/Hearthstone.swift`
- [Counter Manager](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/CounterSystem/CounterManager.swift): derived counters · `HSTracker/Hearthstone/CounterSystem/CounterManager.swift`
- [Effect Factory](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/EffectSystem/Factory/EffectFactory.swift): effect interpreter · `HSTracker/Hearthstone/EffectSystem/Factory/EffectFactory.swift`
- [Secrets & Related Cards](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/Secrets/SecretsManager.swift): prediction rules · Derives secret and generated-card predictions. · `HSTracker/Hearthstone/Secrets/SecretsManager.swift`
- [Battlegrounds Board](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Hearthstone/BattlegroundsBoardState.swift): board model · `HSTracker/Hearthstone/BattlegroundsBoardState.swift`
- [Bob's Buddy Simulation](https://github.com/hearthsim/hstracker/blob/master/HSTracker/BobsBuddy/BobsBuddyInvoker.swift): combat analysis · Invokes Mono-backed combat simulation. · `HSTracker/BobsBuddy/BobsBuddyInvoker.swift`

### Native UI

AppKit screens and persistent game overlays.

- [Overlay Windows](https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Trackers/WindowManager.swift): AppKit overlay manager · Places and manages windows above Hearthstone. · `HSTracker/UIs/Trackers/WindowManager.swift`
- [Card HUD](https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Trackers/CardHud.swift): live deck overlay · `HSTracker/UIs/Trackers/CardHud.swift`
- [Battlegrounds UI](https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/Battlegrounds/BattlegroundsOverlay.swift): Battlegrounds overlay · Shows board and combat-analysis results. · `HSTracker/UIs/Battlegrounds/BattlegroundsOverlay.swift`
- [Deck Manager](https://github.com/hearthsim/hstracker/blob/master/HSTracker/UIs/DeckManager/DeckManager.swift): deck screen · `HSTracker/UIs/DeckManager/DeckManager.swift`

### Data & Services

Local deck data and remote integrations.

- [Local Database](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Database/Database.swift): persistent store · Stores card metadata, decks, and game statistics. · `HSTracker/Database/Database.swift`
- [Deck Import](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Importers/DeckImporter.swift): import adapter · Imports and serializes deck lists. · `HSTracker/Importers/DeckImporter.swift`
- [HSReplay Manager](https://github.com/hearthsim/hstracker/blob/master/HSTracker/HSReplay/HSReplayManager.swift): remote service client · Coordinates account and API workflows. · `HSTracker/HSReplay/HSReplayManager.swift`
- [Log Uploader](https://github.com/hearthsim/hstracker/blob/master/HSTracker/HSReplay/LogUploader.swift): upload client · `HSTracker/HSReplay/LogUploader.swift`
- [Telemetry & Remote Config](https://github.com/hearthsim/hstracker/blob/master/HSTracker/Utility/Analytics/Influx.swift): analytics integration · `HSTracker/Utility/Analytics/Influx.swift`

### Other components

- [App Delegate](https://github.com/hearthsim/hstracker/blob/master/HSTracker/AppDelegate.swift): macOS entry point · `HSTracker/AppDelegate.swift`

## Connections

- App Delegate → Log Reader Manager: starts
- App Delegate → Overlay Windows: launches
- App Delegate → Deck Manager: opens
- Log Reader Manager → Power Game Parser: log lines
- Power Game Parser → Core Manager: state events
- Hearth Runtime Bridge → Scene & Mode Watchers: runtime signals
- Scene & Mode Watchers → Hearthstone Domain: mode updates
- Core Manager → Hearthstone Domain: canonical live state
- Hearthstone Domain → Counter Manager: entity/tag updates
- Hearthstone Domain → Effect Factory: entity/tag updates
- Hearthstone Domain → Secrets & Related Cards: entity/tag updates
- Hearthstone Domain → Battlegrounds Board: Battlegrounds state
- Hearthstone Domain → Card HUD: live deck state
- Counter Manager → Card HUD: display counters
- Effect Factory → Card HUD: active effects
- Secrets & Related Cards → Card HUD: predictions
- Card HUD → Overlay Windows: hosted in
- Battlegrounds Board → Bob's Buddy Simulation: combat state
- Bob's Buddy Simulation → Battlegrounds UI: combat results
- Battlegrounds Board → Battlegrounds UI: board state
- Battlegrounds UI → Overlay Windows: hosted in
- Deck Import → Local Database: saves decks
- Deck Manager → Deck Import: imports decks
- Deck Manager → Local Database: reads and writes
- Hearthstone Domain → Local Database: card lookup and legality
- Log Reader Manager → Log Uploader: game logs
- Log Uploader → HSReplay Manager: uploads via
- App Delegate → Telemetry & Remote Config: reports events
