# loopkit/loop architecture

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

- Interactive diagram: https://gitdiagram.com/loopkit/loop
- Repository: https://github.com/loopkit/loop

## Overview

Loop is an experimental iOS app template for automated insulin delivery, built on LoopKit. Its central runtime manager updates glucose and dosing state, may enact an automatic dose, and reports completion; the source index also shows its store, meal-detection, analytics, and live-activity dependencies. The app includes status and alert surfaces, pump/CGM plugin support, and Watch and widget experiences. Edges are limited to the supplied excerpts, source-index references, or README; unsampled details and integrations are not inferred as verified calls.

Main entry points: [`Loop/Managers/LoopDataManager.swift`](https://github.com/loopkit/loop/blob/dev/Loop/Managers/LoopDataManager.swift) (Loop runtime), [`Loop/View Controllers/StatusTableViewController.swift`](https://github.com/loopkit/loop/blob/dev/Loop/View%20Controllers/StatusTableViewController.swift) (Status screen), [`LoopCore/LoopSettings.swift`](https://github.com/loopkit/loop/blob/dev/LoopCore/LoopSettings.swift) (Loop settings), [`LoopCore/PersistenceController.swift`](https://github.com/loopkit/loop/blob/dev/LoopCore/PersistenceController.swift) (Persistence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dosing["Dosing runtime"]
  node_loopmanager["Loop runtime"]
  node_settings["Loop settings<br/>[LoopSettings.swift]"]
  node_persistence[("Persistence")]
  node_carbs["Carb store"]
  node_glucose["Glucose store"]
  node_doses["Dose store"]
  node_decisions["Decision store"]
  node_meals["Meal detection"]
  node_analytics["Analytics"]
end

subgraph group_devices["Devices and alerts"]
  node_plugins["Plugin manager"]
  node_pump["Pump manager<br/>[PumpManager.swift]"]
  node_alerts["Alert manager<br/>[AlertManager.swift]"]
  node_alertstore[("Alert store<br/>[AlertStore.swift]")]
end

subgraph group_surfaces["App surfaces"]
  node_status["Status screen"]
  node_statushud["Status extension"]
  node_insulinui["Insulin delivery UI"]
  node_learn["Lessons"]
end

subgraph group_companion["Companion apps"]
  node_watch["Watch app"]
  node_watchentry["Watch entry"]
  node_widget["Widgets<br/>[LoopWidgets.swift]"]
  node_liveactivity["Live activity"]
end

node_person(("Person"))

node_loopmanager -->|"uses store"| node_carbs
node_loopmanager -->|"uses store"| node_glucose
node_loopmanager -->|"uses store"| node_doses
node_loopmanager -->|"stores decisions"| node_decisions
node_loopmanager -->|"uses detection"| node_meals
node_loopmanager -->|"reports outcomes"| node_analytics
node_loopmanager -->|"updates proxy"| node_liveactivity
node_plugins -->|"discovers types"| node_pump
node_alerts -->|"queries entries"| node_alertstore
node_status -->|"renders status"| node_statushud
node_person -.->|"views status"| node_status
node_person -.->|"enters doses"| node_insulinui
node_person -.->|"enters on watch"| node_watchentry
node_person -.->|"takes lessons"| node_learn
node_persistence -.->|"provides persistence"| node_loopmanager
node_settings -.->|"configures dosing"| node_loopmanager
node_widget -.->|"reads status"| node_loopmanager
node_watch -.->|"syncs context"| node_loopmanager

click node_loopmanager "https://github.com/loopkit/loop/blob/dev/Loop/Managers/LoopDataManager.swift"
click node_settings "https://github.com/loopkit/loop/blob/dev/LoopCore/LoopSettings.swift"
click node_persistence "https://github.com/loopkit/loop/blob/dev/LoopCore/PersistenceController.swift"
click node_carbs "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/CarbStoreProtocol.swift"
click node_glucose "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/GlucoseStoreProtocol.swift"
click node_doses "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/DoseStoreProtocol.swift"
click node_decisions "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/DosingDecisionStoreProtocol.swift"
click node_meals "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Missed%20Meal%20Detection/MealDetectionManager.swift"
click node_analytics "https://github.com/loopkit/loop/blob/dev/Loop/Managers/AnalyticsServicesManager.swift"
click node_plugins "https://github.com/loopkit/loop/blob/dev/Loop/Plugins/PluginManager.swift"
click node_pump "https://github.com/loopkit/loop/blob/dev/Common/Models/PumpManager.swift"
click node_alerts "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Alerts/AlertManager.swift"
click node_alertstore "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Alerts/AlertStore.swift"
click node_status "https://github.com/loopkit/loop/blob/dev/Loop/View%20Controllers/StatusTableViewController.swift"
click node_statushud "https://github.com/loopkit/loop/blob/dev/Loop%20Status%20Extension/StatusViewController.swift"
click node_insulinui "https://github.com/loopkit/loop/blob/dev/Loop/View%20Controllers/InsulinDeliveryTableViewController.swift"
click node_learn "https://github.com/loopkit/loop/blob/dev/Learn/View%20Controllers/LessonResultsViewController.swift"
click node_watch "https://github.com/loopkit/loop/blob/dev/WatchApp%20Extension/Managers/LoopDataManager.swift"
click node_watchentry "https://github.com/loopkit/loop/blob/dev/WatchApp%20Extension/Views/Carb%20Entry%20%26%20Bolus/CarbAndBolusFlow.swift"
click node_widget "https://github.com/loopkit/loop/blob/dev/Loop%20Widget%20Extension/LoopWidgets.swift"
click node_liveactivity "https://github.com/loopkit/loop/blob/dev/Loop/Managers/Live%20Activity/LiveActivityManager.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_loopmanager,node_settings,node_persistence,node_carbs,node_glucose,node_doses,node_decisions,node_meals,node_analytics toneBlue
class node_plugins,node_pump,node_alerts,node_alertstore toneAmber
class node_status,node_statushud,node_insulinui,node_learn toneMint
class node_watch,node_watchentry,node_widget,node_liveactivity toneRose
class node_person toneIndigo
```

## Components

### Dosing runtime

- [Loop runtime](https://github.com/loopkit/loop/blob/dev/Loop/Managers/LoopDataManager.swift): `Loop/Managers/LoopDataManager.swift`
- [Loop settings](https://github.com/loopkit/loop/blob/dev/LoopCore/LoopSettings.swift): `LoopCore/LoopSettings.swift`
- [Persistence](https://github.com/loopkit/loop/blob/dev/LoopCore/PersistenceController.swift): `LoopCore/PersistenceController.swift`
- [Carb store](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/CarbStoreProtocol.swift): `Loop/Managers/Store Protocols/CarbStoreProtocol.swift`
- [Glucose store](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/GlucoseStoreProtocol.swift): `Loop/Managers/Store Protocols/GlucoseStoreProtocol.swift`
- [Dose store](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/DoseStoreProtocol.swift): `Loop/Managers/Store Protocols/DoseStoreProtocol.swift`
- [Decision store](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Store%20Protocols/DosingDecisionStoreProtocol.swift): `Loop/Managers/Store Protocols/DosingDecisionStoreProtocol.swift`
- [Meal detection](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Missed%20Meal%20Detection/MealDetectionManager.swift): `Loop/Managers/Missed Meal Detection/MealDetectionManager.swift`
- [Analytics](https://github.com/loopkit/loop/blob/dev/Loop/Managers/AnalyticsServicesManager.swift): `Loop/Managers/AnalyticsServicesManager.swift`

### Devices and alerts

- [Plugin manager](https://github.com/loopkit/loop/blob/dev/Loop/Plugins/PluginManager.swift): `Loop/Plugins/PluginManager.swift`
- [Pump manager](https://github.com/loopkit/loop/blob/dev/Common/Models/PumpManager.swift): `Common/Models/PumpManager.swift`
- [Alert manager](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Alerts/AlertManager.swift): `Loop/Managers/Alerts/AlertManager.swift`
- [Alert store](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Alerts/AlertStore.swift): `Loop/Managers/Alerts/AlertStore.swift`

### App surfaces

- [Status screen](https://github.com/loopkit/loop/blob/dev/Loop/View%20Controllers/StatusTableViewController.swift): `Loop/View Controllers/StatusTableViewController.swift`
- [Status extension](https://github.com/loopkit/loop/blob/dev/Loop%20Status%20Extension/StatusViewController.swift): `Loop Status Extension/StatusViewController.swift`
- [Insulin delivery UI](https://github.com/loopkit/loop/blob/dev/Loop/View%20Controllers/InsulinDeliveryTableViewController.swift): `Loop/View Controllers/InsulinDeliveryTableViewController.swift`
- [Lessons](https://github.com/loopkit/loop/blob/dev/Learn/View%20Controllers/LessonResultsViewController.swift): `Learn/View Controllers/LessonResultsViewController.swift`

### Companion apps

- [Watch app](https://github.com/loopkit/loop/blob/dev/WatchApp%20Extension/Managers/LoopDataManager.swift): `WatchApp Extension/Managers/LoopDataManager.swift`
- [Watch entry](https://github.com/loopkit/loop/blob/dev/WatchApp%20Extension/Views/Carb%20Entry%20%26%20Bolus/CarbAndBolusFlow.swift): `WatchApp Extension/Views/Carb Entry & Bolus/CarbAndBolusFlow.swift`
- [Widgets](https://github.com/loopkit/loop/blob/dev/Loop%20Widget%20Extension/LoopWidgets.swift): `Loop Widget Extension/LoopWidgets.swift`
- [Live activity](https://github.com/loopkit/loop/blob/dev/Loop/Managers/Live%20Activity/LiveActivityManager.swift): `Loop/Managers/Live Activity/LiveActivityManager.swift`

### Other components

- **Person**

## Connections

- Loop runtime → Carb store: uses store (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop runtime → Glucose store: uses store (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop runtime → Dose store: uses store (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop runtime → Decision store: stores decisions (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop runtime → Meal detection: uses detection (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop runtime → Analytics: reports outcomes (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop runtime → Live activity: updates proxy (evidence: `Loop/Managers/LoopDataManager.swift`)
- Plugin manager → Pump manager: discovers types (evidence: `Loop/Plugins/PluginManager.swift`)
- Alert manager → Alert store: queries entries (evidence: `Loop/Managers/Alerts/AlertManager.swift`)
- Status screen → Status extension: renders status (evidence: `Loop/View Controllers/StatusTableViewController.swift`)
- Person → Status screen: views status (evidence: `README.md`)
- Person → Insulin delivery UI: enters doses (evidence: `README.md`)
- Person → Watch entry: enters on watch (evidence: `README.md`)
- Person → Lessons: takes lessons
- Persistence → Loop runtime: provides persistence (evidence: `Loop/Managers/LoopDataManager.swift`)
- Loop settings → Loop runtime: configures dosing (evidence: `Loop/Managers/LoopDataManager.swift`)
- Widgets → Loop runtime: reads status (evidence: `Loop/Managers/LoopDataManager.swift`)
- Watch app → Loop runtime: syncs context
