# bretthoffman/glucose_guardian architecture

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

- Interactive diagram: https://gitdiagram.com/bretthoffman/glucose_guardian
- Repository: https://github.com/bretthoffman/glucose_guardian

## Overview

Glucose Guardian is a diabetes-monitoring and care-coordination product: patients use the mobile app to review glucose, log food and insulin, connect CGMs, and access predictions and messaging; clinicians have doctor-portal API routes. The API routes requests, while Convex provides backend functions and persisted state. CGM ingestion is a distinct unattended workflow with provider adapters and pure scheduling policy. The README is empty, so capabilities and connections here rely on the supplied source excerpts and SOURCE INDEX; unsampled route behavior is represented only at the route-module level.

Main entry points: [`artifacts/api-server/internal/routes/index.ts`](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/index.ts) (API route registry), [`convex/cgm/providers.ts`](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/providers.ts) (Dexcom and Libre), [`artifacts/api-server/internal/routes/doctor.ts`](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/doctor.ts) (Doctor portal), [`convex/cgmIngest.ts`](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgmIngest.ts) (Sync orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Patient mobile app"]
  node_mobile["Mobile screens<br/>[dashboard.tsx]"]
  node_auth["Mobile authentication<br/>[AuthContext.tsx]"]
  node_glucose["Glucose state<br/>[GlucoseContext.tsx]"]
end

subgraph group_api["HTTP API"]
  node_apiapp["Express app<br/>[app.ts]"]
  node_routes["API route registry<br/>[index.ts]"]
  node_cgmroute["CGM endpoints<br/>[cgm.ts]"]
  node_chatroute["Chat endpoints<br/>[chat.ts]"]
  node_doctorroute["Doctor portal<br/>[doctor.ts]"]
  node_foodroute["Food endpoints<br/>[food.ts]"]
  node_insulinroute["Insulin endpoints<br/>[insulin.ts]"]
  node_predictroute["Prediction endpoints<br/>[predict.ts]"]
  node_assistant["Doctor assistant"]
  node_doctorauth["Doctor authentication<br/>[doctor-auth.ts]"]
  node_doctoraccounts["Doctor account client"]
end

subgraph group_backend["Convex backend"]
  node_convex["Convex functions"]
  node_database[("Convex database<br/>[schema.ts]")]
  node_care["Care coordination<br/>[careCircle.ts]"]
  node_glucosebackend["Patient glucose<br/>[patientGlucose.ts]"]
end

subgraph group_cgm["CGM ingestion"]
  node_cgmingest["Sync orchestration<br/>[cgmIngest.ts]"]
  node_policy["Sync policy<br/>[core.ts]"]
  node_providers["Dexcom and Libre<br/>[providers.ts]"]
  node_diagnostics["Sync diagnostics<br/>[diagnostics.ts]"]
end

node_patient(("Patient or clinician"))
node_dexcom["Dexcom Share"]
node_libre["LibreLink Up"]

node_patient -.->|"uses"| node_mobile
node_patient -->|"requests"| node_apiapp
node_apiapp -->|"mounts"| node_routes
node_routes -->|"registers"| node_cgmroute
node_routes -->|"registers"| node_chatroute
node_routes -->|"registers"| node_doctorroute
node_routes -->|"registers"| node_foodroute
node_routes -->|"registers"| node_insulinroute
node_routes -->|"registers"| node_predictroute
node_doctorroute -->|"queries accounts"| node_doctoraccounts
node_doctorroute -->|"uses auth"| node_doctorauth
node_doctorroute -->|"uses assistant"| node_assistant
node_auth -->|"references schedule"| node_care
node_cgmingest -->|"plans sync"| node_policy
node_cgmingest -->|"runs provider sync"| node_providers
node_cgmingest -->|"reads and writes"| node_database
node_providers -->|"uses anomaly policy"| node_policy
node_providers -->|"classifies failures"| node_diagnostics
node_providers -->|"calls provider"| node_dexcom
node_providers -->|"calls provider"| node_libre
node_glucosebackend -.->|"persists readings"| node_database
node_care -.->|"persists care data"| node_database

click node_mobile "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/mobile/app/(tabs)/dashboard.tsx"
click node_auth "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/mobile/context/AuthContext.tsx"
click node_glucose "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/mobile/context/GlucoseContext.tsx"
click node_apiapp "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/app.ts"
click node_routes "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/index.ts"
click node_cgmroute "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/cgm.ts"
click node_chatroute "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/chat.ts"
click node_doctorroute "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/doctor.ts"
click node_foodroute "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/food.ts"
click node_insulinroute "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/insulin.ts"
click node_predictroute "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/predict.ts"
click node_assistant "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/doctor-assistant.ts"
click node_doctorauth "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/doctor-auth.ts"
click node_doctoraccounts "https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/convex-doctor-accounts.ts"
click node_convex "https://github.com/bretthoffman/glucose_guardian/tree/master/convex"
click node_database "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/schema.ts"
click node_care "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/careCircle.ts"
click node_glucosebackend "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/patientGlucose.ts"
click node_cgmingest "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgmIngest.ts"
click node_policy "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/core.ts"
click node_providers "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/providers.ts"
click node_diagnostics "https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/diagnostics.ts"

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_mobile,node_auth,node_glucose toneBlue
class node_apiapp,node_routes,node_cgmroute,node_chatroute,node_doctorroute,node_foodroute,node_insulinroute,node_predictroute,node_assistant,node_doctorauth,node_doctoraccounts toneAmber
class node_convex,node_database,node_care,node_glucosebackend toneMint
class node_cgmingest,node_policy,node_providers,node_diagnostics toneRose
class node_patient,node_dexcom,node_libre toneIndigo
```

## Components

### Patient mobile app

- [Mobile screens](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/mobile/app/(tabs)/dashboard.tsx): `artifacts/mobile/app/(tabs)/dashboard.tsx`
- [Mobile authentication](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/mobile/context/AuthContext.tsx): `artifacts/mobile/context/AuthContext.tsx`
- [Glucose state](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/mobile/context/GlucoseContext.tsx): `artifacts/mobile/context/GlucoseContext.tsx`

### HTTP API

- [Express app](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/app.ts): `artifacts/api-server/internal/app.ts`
- [API route registry](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/index.ts): `artifacts/api-server/internal/routes/index.ts`
- [CGM endpoints](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/cgm.ts): `artifacts/api-server/internal/routes/cgm.ts`
- [Chat endpoints](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/chat.ts): `artifacts/api-server/internal/routes/chat.ts`
- [Doctor portal](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/doctor.ts): `artifacts/api-server/internal/routes/doctor.ts`
- [Food endpoints](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/food.ts): `artifacts/api-server/internal/routes/food.ts`
- [Insulin endpoints](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/insulin.ts): `artifacts/api-server/internal/routes/insulin.ts`
- [Prediction endpoints](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/routes/predict.ts): `artifacts/api-server/internal/routes/predict.ts`
- [Doctor assistant](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/doctor-assistant.ts): `artifacts/api-server/internal/doctor-assistant.ts`
- [Doctor authentication](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/doctor-auth.ts): `artifacts/api-server/internal/doctor-auth.ts`
- [Doctor account client](https://github.com/bretthoffman/glucose_guardian/blob/master/artifacts/api-server/internal/convex-doctor-accounts.ts): `artifacts/api-server/internal/convex-doctor-accounts.ts`

### Convex backend

- [Convex functions](https://github.com/bretthoffman/glucose_guardian/tree/master/convex): `convex`
- [Convex database](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/schema.ts): `convex/schema.ts`
- [Care coordination](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/careCircle.ts): `convex/careCircle.ts`
- [Patient glucose](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/patientGlucose.ts): `convex/patientGlucose.ts`

### CGM ingestion

- [Sync orchestration](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgmIngest.ts): `convex/cgmIngest.ts`
- [Sync policy](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/core.ts): `convex/cgm/core.ts`
- [Dexcom and Libre](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/providers.ts): `convex/cgm/providers.ts`
- [Sync diagnostics](https://github.com/bretthoffman/glucose_guardian/blob/master/convex/cgm/diagnostics.ts): `convex/cgm/diagnostics.ts`

### Other components

- **Patient or clinician**
- **Dexcom Share**
- **LibreLink Up**

## Connections

- Patient or clinician → Mobile screens: uses
- Patient or clinician → Express app: requests (evidence: `artifacts/api-server/internal/app.ts`)
- Express app → API route registry: mounts (evidence: `artifacts/api-server/internal/app.ts`)
- API route registry → CGM endpoints: registers (evidence: `artifacts/api-server/internal/routes/index.ts`)
- API route registry → Chat endpoints: registers (evidence: `artifacts/api-server/internal/routes/index.ts`)
- API route registry → Doctor portal: registers (evidence: `artifacts/api-server/internal/routes/index.ts`)
- API route registry → Food endpoints: registers (evidence: `artifacts/api-server/internal/routes/index.ts`)
- API route registry → Insulin endpoints: registers (evidence: `artifacts/api-server/internal/routes/index.ts`)
- API route registry → Prediction endpoints: registers (evidence: `artifacts/api-server/internal/routes/index.ts`)
- Doctor portal → Doctor account client: queries accounts (evidence: `artifacts/api-server/internal/routes/doctor.ts`)
- Doctor portal → Doctor authentication: uses auth (evidence: `artifacts/api-server/internal/routes/doctor.ts`)
- Doctor portal → Doctor assistant: uses assistant (evidence: `artifacts/api-server/internal/routes/doctor.ts`)
- Mobile authentication → Care coordination: references schedule (evidence: `artifacts/mobile/context/AuthContext.tsx`)
- Sync orchestration → Sync policy: plans sync (evidence: `convex/cgmIngest.ts`)
- Sync orchestration → Dexcom and Libre: runs provider sync (evidence: `convex/cgmIngest.ts`)
- Sync orchestration → Convex database: reads and writes (evidence: `convex/cgmIngest.ts`)
- Dexcom and Libre → Sync policy: uses anomaly policy (evidence: `convex/cgm/providers.ts`)
- Dexcom and Libre → Sync diagnostics: classifies failures (evidence: `convex/cgm/providers.ts`)
- Dexcom and Libre → Dexcom Share: calls provider (evidence: `convex/cgm/providers.ts`)
- Dexcom and Libre → LibreLink Up: calls provider (evidence: `convex/cgm/providers.ts`)
- Patient glucose → Convex database: persists readings
- Care coordination → Convex database: persists care data
