# krishhgg/insomnia architecture

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

- Interactive diagram: https://gitdiagram.com/krishhgg/insomnia
- Repository: https://github.com/krishhgg/insomnia

## Overview

Insomnia is a macOS menu-bar app for timed keep-awake sessions. The user starts, extends, or ends a countdown; session management coordinates sleep prevention, lid-close actions, power rules, and cleanup. Settings configure those behaviors, while a journal and launchd backstop support recovery after app failure. The graph preserves documented capabilities even where implementation was not sampled; edges without direct source excerpts rely on README statements or SOURCE INDEX references, not a full inspection of those implementations.

Main entry points: [`Sources/Insomnia/Core/SessionManager.swift`](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SessionManager.swift) (Session manager), [`Sources/Insomnia/UI/StatusItemController.swift`](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/StatusItemController.swift) (Status controls), [`Sources/Insomnia/Core/AppServices.swift`](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/AppServices.swift) (Service coordinator), [`Sources/Insomnia/UI/SettingsView.swift`](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/SettingsView.swift) (Settings window)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Menu-bar interface"]
  node_app["App lifecycle<br/>[InsomniaApp.swift]"]
  node_status["Status controls"]
  node_statusview["Countdown view"]
  node_duration["Duration entry"]
  node_settings["Settings window<br/>[SettingsView.swift]"]
end

subgraph group_sessions["Session and recovery"]
  node_manager["Session manager"]
  node_math["Session timing<br/>[SessionMath.swift]"]
  node_services["Service coordinator<br/>[AppServices.swift]"]
  node_backstop["Recovery backstop"]
end

subgraph group_integrations["Mac integrations"]
  node_lidactions["Lid actions<br/>[LidActions.swift]"]
  node_sleep["Sleep prevention<br/>[SleepGuard.swift]"]
  node_freezer["App freezing<br/>[Freezer.swift]"]
  node_power["Battery and heat rules<br/>[PowerMonitor.swift]"]
  node_network["Hotspot failover"]
  node_tmux["tmux nudges<br/>[TmuxNudge.swift]"]
end

subgraph group_state["Settings and state"]
  node_config["User configuration<br/>[Config.swift]"]
  node_session["Active session<br/>[Session.swift]"]
  node_store[("Session journal and state<br/>[Store.swift]")]
  node_paths["Persistent paths<br/>[Paths.swift]"]
  node_log[("Activity log<br/>[Log.swift]")]
end

node_user(("Mac user"))

node_user -->|"controls sessions"| node_status
node_user -->|"configures rules"| node_settings
node_app -->|"creates interface"| node_status
node_status -->|"hosts view"| node_statusview
node_status -->|"starts and ends"| node_manager
node_status -->|"reads duration"| node_duration
node_statusview -->|"shows session state"| node_manager
node_settings -->|"updates settings"| node_manager
node_manager -->|"calculates deadlines"| node_math
node_manager -->|"tracks session"| node_session
node_manager -->|"persists recovery state"| node_store
node_manager -->|"starts integrations"| node_services
node_services -->|"dispatches lid events"| node_lidactions
node_services -->|"runs power rules"| node_power
node_lidactions -->|"freezes configured apps"| node_freezer
node_manager -->|"prevents sleep"| node_sleep
node_manager -->|"arms recovery"| node_backstop
node_backstop -->|"checks due recovery"| node_store
node_settings -->|"edits preferences"| node_config
node_manager -->|"uses preferences"| node_config
node_store -->|"resolves files"| node_paths
node_manager -->|"records activity"| node_log
node_services -->|"manages hotspot"| node_network
node_network -->|"triggers pane nudges"| node_tmux

click node_app "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/InsomniaApp.swift"
click node_status "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/StatusItemController.swift"
click node_statusview "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/StatusRootView.swift"
click node_duration "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/DurationInput.swift"
click node_settings "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/SettingsView.swift"
click node_manager "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SessionManager.swift"
click node_math "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SessionMath.swift"
click node_services "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/AppServices.swift"
click node_lidactions "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/LidActions.swift"
click node_sleep "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SleepGuard.swift"
click node_freezer "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/Freezer.swift"
click node_power "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/PowerMonitor.swift"
click node_network "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/NetworkFailover.swift"
click node_tmux "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/TmuxNudge.swift"
click node_config "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Model/Config.swift"
click node_session "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Model/Session.swift"
click node_store "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Store/Store.swift"
click node_paths "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Store/Paths.swift"
click node_backstop "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/LaunchdBackstop.swift"
click node_log "https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/Log.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_status,node_statusview,node_duration,node_settings,node_user toneBlue
class node_manager,node_math,node_services,node_backstop toneAmber
class node_lidactions,node_sleep,node_freezer,node_power,node_network,node_tmux toneMint
class node_config,node_session,node_store,node_paths,node_log toneRose
```

## Components

### Menu-bar interface

- [App lifecycle](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/InsomniaApp.swift): `Sources/Insomnia/InsomniaApp.swift`
- [Status controls](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/StatusItemController.swift): `Sources/Insomnia/UI/StatusItemController.swift`
- [Countdown view](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/StatusRootView.swift): `Sources/Insomnia/UI/StatusRootView.swift`
- [Duration entry](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/DurationInput.swift): `Sources/Insomnia/UI/DurationInput.swift`
- [Settings window](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/UI/SettingsView.swift): `Sources/Insomnia/UI/SettingsView.swift`

### Session and recovery

- [Session manager](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SessionManager.swift): `Sources/Insomnia/Core/SessionManager.swift`
- [Session timing](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SessionMath.swift): `Sources/Insomnia/Core/SessionMath.swift`
- [Service coordinator](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/AppServices.swift): `Sources/Insomnia/Core/AppServices.swift`
- [Recovery backstop](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/LaunchdBackstop.swift): `Sources/Insomnia/Core/LaunchdBackstop.swift`

### Mac integrations

- [Lid actions](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/LidActions.swift): `Sources/Insomnia/Core/LidActions.swift`
- [Sleep prevention](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/SleepGuard.swift): `Sources/Insomnia/Core/SleepGuard.swift`
- [App freezing](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/Freezer.swift): `Sources/Insomnia/System/Freezer.swift`
- [Battery and heat rules](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/PowerMonitor.swift): `Sources/Insomnia/System/PowerMonitor.swift`
- [Hotspot failover](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/NetworkFailover.swift): `Sources/Insomnia/System/NetworkFailover.swift`
- [tmux nudges](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/System/TmuxNudge.swift): `Sources/Insomnia/System/TmuxNudge.swift`

### Settings and state

- [User configuration](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Model/Config.swift): `Sources/Insomnia/Model/Config.swift`
- [Active session](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Model/Session.swift): `Sources/Insomnia/Model/Session.swift`
- [Session journal and state](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Store/Store.swift): `Sources/Insomnia/Store/Store.swift`
- [Persistent paths](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Store/Paths.swift): `Sources/Insomnia/Store/Paths.swift`
- [Activity log](https://github.com/krishhgg/insomnia/blob/main/Sources/Insomnia/Core/Log.swift): `Sources/Insomnia/Core/Log.swift`

### Other components

- **Mac user**

## Connections

- Mac user → Status controls: controls sessions (evidence: `README.md`)
- Mac user → Settings window: configures rules (evidence: `README.md`)
- App lifecycle → Status controls: creates interface (evidence: `Sources/Insomnia/InsomniaApp.swift`)
- Status controls → Countdown view: hosts view (evidence: `Sources/Insomnia/UI/StatusItemController.swift`)
- Status controls → Session manager: starts and ends (evidence: `Sources/Insomnia/UI/StatusItemController.swift`)
- Status controls → Duration entry: reads duration (evidence: `Sources/Insomnia/UI/StatusItemController.swift`)
- Countdown view → Session manager: shows session state (evidence: `Sources/Insomnia/UI/StatusRootView.swift`)
- Settings window → Session manager: updates settings (evidence: `Sources/Insomnia/UI/SettingsView.swift`)
- Session manager → Session timing: calculates deadlines (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Session manager → Active session: tracks session (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Session manager → Session journal and state: persists recovery state (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Session manager → Service coordinator: starts integrations (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Service coordinator → Lid actions: dispatches lid events (evidence: `Sources/Insomnia/Core/AppServices.swift`)
- Service coordinator → Battery and heat rules: runs power rules (evidence: `Sources/Insomnia/Core/AppServices.swift`)
- Lid actions → App freezing: freezes configured apps (evidence: `Sources/Insomnia/Core/LidActions.swift`)
- Session manager → Sleep prevention: prevents sleep (evidence: `README.md`)
- Session manager → Recovery backstop: arms recovery (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Recovery backstop → Session journal and state: checks due recovery (evidence: `README.md`)
- Settings window → User configuration: edits preferences (evidence: `Sources/Insomnia/UI/SettingsView.swift`)
- Session manager → User configuration: uses preferences (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Session journal and state → Persistent paths: resolves files (evidence: `Sources/Insomnia/Store/Store.swift`)
- Session manager → Activity log: records activity (evidence: `Sources/Insomnia/Core/SessionManager.swift`)
- Service coordinator → Hotspot failover: manages hotspot (evidence: `Sources/Insomnia/Core/AppServices.swift`)
- Hotspot failover → tmux nudges: triggers pane nudges (evidence: `Sources/Insomnia/System/NetworkFailover.swift`)
