# lucasshyc/trio architecture

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

- Interactive diagram: https://gitdiagram.com/lucasshyc/trio
- Repository: https://github.com/lucasshyc/trio

## Overview

Trio is an iOS open-source automated insulin delivery system built around an adapted OpenAPS algorithm. Its principal workflow gathers glucose, pump, carbohydrate, and therapy-setting data; computes a dosing determination; and coordinates insulin-delivery-related app behavior. The repository also includes configuration and treatment-entry screens, persistent storage, Nightscout upload, and Apple Watch and Live Activity surfaces. The graph uses sampled code and SOURCE INDEX references for concrete relationships; broader integrations are shown only as unverified links because their wiring was not sampled.

Main entry points: [`Trio/Sources/APS/OpenAPS/OpenAPS.swift`](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/OpenAPS/OpenAPS.swift) (OpenAPS data assembly), [`Trio/Sources/Application/TrioApp.swift`](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Application/TrioApp.swift) (Trio app), [`Trio/Sources/APS/APSManager.swift`](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/APSManager.swift) (APS coordinator), [`Trio/Sources/APS/Storage/GlucoseStorage.swift`](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/GlucoseStorage.swift) (Glucose storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and treatment"]
  node_trio["Trio app<br/>[TrioApp.swift]"]
  node_home["Home dashboard"]
  node_treatment["Treatment entry"]
  node_adjustments["Therapy adjustments"]
  node_settings["Settings"]
end

subgraph group_algorithm["AID algorithm"]
  node_aps["APS coordinator<br/>[APSManager.swift]"]
  node_openaps["OpenAPS data assembly<br/>[OpenAPS.swift]"]
  node_engine["Dosing engine<br/>[DosingEngine.swift]"]
end

subgraph group_data["Data and persistence"]
  node_glucose[("Glucose storage")]
  node_carbs[("Carbohydrate storage<br/>[CarbsStorage.swift]")]
  node_pumphistory[("Pump history storage")]
  node_determinations[("Determination storage")]
  node_overrides[("Override storage")]
  node_temptargets[("Temp target storage")]
  node_coredata[("Core Data stack")]
  node_files[("File storage<br/>[FileStorage.swift]")]
end

subgraph group_integrations["Device and sharing"]
  node_cgm["CGM sources"]
  node_pump["Pump and device managers"]
  node_nightscout["Nightscout upload"]
end

subgraph group_surfaces["Companion surfaces"]
  node_watch["Apple Watch app<br/>[WatchState.swift]"]
  node_liveactivity["Live Activity"]
end

node_person(("Person with diabetes"))

node_person -->|"uses"| node_trio
node_trio -.->|"coordinates"| node_aps
node_aps -->|"assembles inputs"| node_openaps
node_openaps -->|"reads glucose"| node_glucose
node_openaps -->|"reads carbs"| node_carbs
node_openaps -->|"reads history"| node_pumphistory
node_openaps -->|"reads targets"| node_temptargets
node_openaps -->|"reads settings"| node_files
node_openaps -.->|"runs dosing"| node_engine
node_aps -->|"uses storage"| node_determinations
node_aps -->|"uses storage"| node_overrides
node_cgm -.->|"supplies readings"| node_glucose
node_pump -.->|"supplies events"| node_pumphistory
node_glucose -->|"persists records"| node_coredata
node_carbs -->|"persists records"| node_coredata
node_pumphistory -->|"persists records"| node_coredata
node_settings -->|"saves settings"| node_files
node_trio -.->|"offers entry"| node_treatment
node_trio -.->|"offers controls"| node_adjustments
node_nightscout -.->|"uploads readings"| node_glucose
node_nightscout -.->|"uploads entries"| node_carbs
node_nightscout -.->|"uploads events"| node_pumphistory
node_trio -.->|"shares state"| node_watch
node_trio -.->|"updates display"| node_liveactivity

click node_trio "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Application/TrioApp.swift"
click node_home "https://github.com/lucasshyc/trio/tree/main/Trio/Sources/Modules/Home"
click node_treatment "https://github.com/lucasshyc/trio/tree/main/Trio/Sources/Modules/AddCarbs"
click node_adjustments "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/Adjustments/AdjustmentManager.swift"
click node_settings "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/SettingsManager/SettingsManager.swift"
click node_aps "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/APSManager.swift"
click node_openaps "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/OpenAPS/OpenAPS.swift"
click node_engine "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift"
click node_cgm "https://github.com/lucasshyc/trio/tree/main/Trio/Sources/APS/CGM"
click node_pump "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Devices/DeviceCatalog.swift"
click node_nightscout "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/Network/Nightscout/NightscoutUploadPipeline.swift"
click node_glucose "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/GlucoseStorage.swift"
click node_carbs "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/CarbsStorage.swift"
click node_pumphistory "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/PumpHistoryStorage.swift"
click node_determinations "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/DeterminationStorage.swift"
click node_overrides "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/OverrideStorage.swift"
click node_temptargets "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/TempTargetsStorage.swift"
click node_coredata "https://github.com/lucasshyc/trio/blob/main/Model/CoreDataStack.swift"
click node_files "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/Storage/FileStorage.swift"
click node_watch "https://github.com/lucasshyc/trio/blob/main/Trio%20Watch%20App%20Extension/WatchState.swift"
click node_liveactivity "https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/LiveActivity/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_trio,node_home,node_treatment,node_adjustments,node_settings toneBlue
class node_aps,node_openaps,node_engine toneAmber
class node_glucose,node_carbs,node_pumphistory,node_determinations,node_overrides,node_temptargets,node_coredata,node_files toneMint
class node_cgm,node_pump,node_nightscout toneRose
class node_watch,node_liveactivity,node_person toneIndigo
```

## Components

### App and treatment

- [Trio app](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Application/TrioApp.swift): `Trio/Sources/Application/TrioApp.swift`
- [Home dashboard](https://github.com/lucasshyc/trio/tree/main/Trio/Sources/Modules/Home): `Trio/Sources/Modules/Home`
- [Treatment entry](https://github.com/lucasshyc/trio/tree/main/Trio/Sources/Modules/AddCarbs): `Trio/Sources/Modules/AddCarbs`
- [Therapy adjustments](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/Adjustments/AdjustmentManager.swift): `Trio/Sources/Services/Adjustments/AdjustmentManager.swift`
- [Settings](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/SettingsManager/SettingsManager.swift): `Trio/Sources/Services/SettingsManager/SettingsManager.swift`

### AID algorithm

- [APS coordinator](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/APSManager.swift): `Trio/Sources/APS/APSManager.swift`
- [OpenAPS data assembly](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/OpenAPS/OpenAPS.swift): `Trio/Sources/APS/OpenAPS/OpenAPS.swift`
- [Dosing engine](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift): `Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift`

### Data and persistence

- [Glucose storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/GlucoseStorage.swift): `Trio/Sources/APS/Storage/GlucoseStorage.swift`
- [Carbohydrate storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/CarbsStorage.swift): `Trio/Sources/APS/Storage/CarbsStorage.swift`
- [Pump history storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/PumpHistoryStorage.swift): `Trio/Sources/APS/Storage/PumpHistoryStorage.swift`
- [Determination storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/DeterminationStorage.swift): `Trio/Sources/APS/Storage/DeterminationStorage.swift`
- [Override storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/OverrideStorage.swift): `Trio/Sources/APS/Storage/OverrideStorage.swift`
- [Temp target storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Storage/TempTargetsStorage.swift): `Trio/Sources/APS/Storage/TempTargetsStorage.swift`
- [Core Data stack](https://github.com/lucasshyc/trio/blob/main/Model/CoreDataStack.swift): `Model/CoreDataStack.swift`
- [File storage](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/Storage/FileStorage.swift): `Trio/Sources/Services/Storage/FileStorage.swift`

### Device and sharing

- [CGM sources](https://github.com/lucasshyc/trio/tree/main/Trio/Sources/APS/CGM): `Trio/Sources/APS/CGM`
- [Pump and device managers](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/APS/Devices/DeviceCatalog.swift): `Trio/Sources/APS/Devices/DeviceCatalog.swift`
- [Nightscout upload](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/Network/Nightscout/NightscoutUploadPipeline.swift): `Trio/Sources/Services/Network/Nightscout/NightscoutUploadPipeline.swift`

### Companion surfaces

- [Apple Watch app](https://github.com/lucasshyc/trio/blob/main/Trio%20Watch%20App%20Extension/WatchState.swift): `Trio Watch App Extension/WatchState.swift`
- [Live Activity](https://github.com/lucasshyc/trio/blob/main/Trio/Sources/Services/LiveActivity/LiveActivityManager.swift): `Trio/Sources/Services/LiveActivity/LiveActivityManager.swift`

### Other components

- **Person with diabetes**

## Connections

- Person with diabetes → Trio app: uses
- Trio app → APS coordinator: coordinates
- APS coordinator → OpenAPS data assembly: assembles inputs (evidence: `Trio/Sources/APS/APSManager.swift`)
- OpenAPS data assembly → Glucose storage: reads glucose (evidence: `Trio/Sources/APS/OpenAPS/OpenAPS.swift`)
- OpenAPS data assembly → Carbohydrate storage: reads carbs (evidence: `Trio/Sources/APS/OpenAPS/OpenAPS.swift`)
- OpenAPS data assembly → Pump history storage: reads history (evidence: `Trio/Sources/APS/OpenAPS/OpenAPS.swift`)
- OpenAPS data assembly → Temp target storage: reads targets (evidence: `Trio/Sources/APS/OpenAPS/OpenAPS.swift`)
- OpenAPS data assembly → File storage: reads settings (evidence: `Trio/Sources/APS/OpenAPS/OpenAPS.swift`)
- OpenAPS data assembly → Dosing engine: runs dosing
- APS coordinator → Determination storage: uses storage (evidence: `Trio/Sources/APS/APSManager.swift`)
- APS coordinator → Override storage: uses storage (evidence: `Trio/Sources/APS/APSManager.swift`)
- CGM sources → Glucose storage: supplies readings
- Pump and device managers → Pump history storage: supplies events
- Glucose storage → Core Data stack: persists records (evidence: `Trio/Sources/APS/Storage/GlucoseStorage.swift`)
- Carbohydrate storage → Core Data stack: persists records (evidence: `Trio/Sources/APS/Storage/CarbsStorage.swift`)
- Pump history storage → Core Data stack: persists records (evidence: `Trio/Sources/APS/Storage/PumpHistoryStorage.swift`)
- Settings → File storage: saves settings (evidence: `Trio/Sources/Services/SettingsManager/SettingsManager.swift`)
- Trio app → Treatment entry: offers entry
- Trio app → Therapy adjustments: offers controls
- Nightscout upload → Glucose storage: uploads readings
- Nightscout upload → Carbohydrate storage: uploads entries
- Nightscout upload → Pump history storage: uploads events
- Trio app → Apple Watch app: shares state
- Trio app → Live Activity: updates display
