# shark204/codeblue-sounds architecture

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

- Interactive diagram: https://gitdiagram.com/shark204/codeblue-sounds
- Repository: https://github.com/shark204/codeblue-sounds

## Overview

Code Blue is an ECG education and clinical decision-support application with two principal experiences: image-based ECG analysis and interactive heart/breath sound learning. In the ECG workflow, a user submits an ECG in the diagnostic studio; the app extracts local measurements and can request visual-AI analysis, then combines findings with clinical rules into a displayed report. Separate branches provide educational single-lead analysis, auscultation simulations, and account/subscription management. Edges reflect the supplied source index, excerpts, or README; unsampled integrations are shown only where explicitly documented.

Main entry points: [`lib/ecgHybridEngine.ts`](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgHybridEngine.ts) (Hybrid diagnosis), [`features/ecg/EcgDiagnosticStudio.tsx`](https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgDiagnosticStudio.tsx) (Diagnostic studio), [`app/page.tsx`](https://github.com/shark204/codeblue-sounds/blob/main/app/page.tsx) (Home experience), [`app/api/ecg-analyze/route.ts`](https://github.com/shark204/codeblue-sounds/blob/main/app/api/ecg-analyze/route.ts) (Analysis endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ecg_workflow["ECG Analysis"]
  node_studio["Diagnostic studio"]
  node_api_client["ECG API client<br/>[ecgApiClient.ts]"]
  node_analyze_route["Analysis endpoint<br/>[route.ts]"]
  node_visual_ai["Visual AI backend<br/>[modal_app.py]"]
  node_image_engine["Image extraction<br/>[ecgImageEngine.ts]"]
  node_single_lead["Single-lead mode"]
  node_diagnosis_view["Diagnosis report"]
end

subgraph group_clinical_engine["Clinical Engine"]
  node_hybrid_engine["Hybrid diagnosis<br/>[ecgHybridEngine.ts]"]
  node_rules["ECG rules<br/>[ecgRules.ts]"]
  node_fusion["Finding fusion<br/>[ecgFusionEngine.ts]"]
  node_clinical_library["Clinical reference"]
  node_vitals_rules["Vitals rules<br/>[ecgVitalsRules.ts]"]
end

subgraph group_sounds_lab["Sounds Lab"]
  node_breath_controls["Breath controls<br/>[BreathControls.tsx]"]
  node_breath_sim["Breath simulation<br/>[breathing.ts]"]
  node_heart_controls["Heart controls<br/>[HeartControls.tsx]"]
  node_heart_sound["Heart sounds<br/>[heartSound.ts]"]
  node_rhythms["Rhythm simulation<br/>[rhythms.ts]"]
  node_breath_store["Breath state<br/>[breathStore.ts]"]
  node_heart_store["Heart state<br/>[heartStore.ts]"]
end

subgraph group_accounts["Accounts"]
  node_auth["Authentication gate<br/>[AuthGate.tsx]"]
  node_account_modals["Account management"]
  node_pricing["Plans and pricing<br/>[PricingModal.tsx]"]
  node_supabase[("Supabase client<br/>[supabase.ts]")]
  node_admin_api[("Admin database access<br/>[supabaseAdmin.ts]")]
  node_revenuecat["RevenueCat billing"]
end

node_user(("Learner / clinician"))
node_home["Home experience<br/>[page.tsx]"]
node_supabase_service[("Supabase service")]

node_user -->|"opens"| node_home
node_home -->|"renders"| node_studio
node_studio -->|"requests analysis"| node_api_client
node_api_client -->|"posts ECG"| node_analyze_route
node_analyze_route -->|"forwards image"| node_visual_ai
node_studio -->|"extracts locally"| node_image_engine
node_studio -->|"runs diagnosis"| node_hybrid_engine
node_studio -->|"renders mode"| node_single_lead
node_diagnosis_view -->|"uses results"| node_hybrid_engine
node_hybrid_engine -->|"evaluates findings"| node_rules
node_hybrid_engine -->|"computes availability"| node_fusion
node_hybrid_engine -->|"looks up entries"| node_clinical_library
node_hybrid_engine -->|"applies vitals"| node_vitals_rules
node_home -->|"opens lab"| node_breath_controls
node_home -->|"opens lab"| node_heart_controls
node_breath_controls -->|"configures simulation"| node_breath_sim
node_breath_controls -->|"updates state"| node_breath_store
node_breath_store -->|"uses patterns"| node_breath_sim
node_heart_store -->|"uses sounds"| node_heart_sound
node_heart_store -->|"uses rhythms"| node_rhythms
node_heart_sound -->|"uses rhythm data"| node_rhythms
node_home -->|"renders gate"| node_auth
node_auth -->|"opens dialogs"| node_account_modals
node_auth -->|"opens plans"| node_pricing
node_account_modals -->|"uses auth"| node_supabase
node_pricing -->|"uses auth"| node_supabase
node_account_modals -->|"uses billing"| node_revenuecat
node_pricing -->|"uses billing"| node_revenuecat
node_analyze_route -->|"verifies user"| node_admin_api
node_admin_api -->|"authenticates against"| node_supabase_service
node_supabase -.->|"connects to"| node_supabase_service

click node_home "https://github.com/shark204/codeblue-sounds/blob/main/app/page.tsx"
click node_studio "https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgDiagnosticStudio.tsx"
click node_api_client "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgApiClient.ts"
click node_analyze_route "https://github.com/shark204/codeblue-sounds/blob/main/app/api/ecg-analyze/route.ts"
click node_visual_ai "https://github.com/shark204/codeblue-sounds/blob/main/hf_ecg_space/modal_app.py"
click node_image_engine "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgImageEngine.ts"
click node_single_lead "https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgSingleLeadCard.tsx"
click node_diagnosis_view "https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgDiagnosisView.tsx"
click node_hybrid_engine "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgHybridEngine.ts"
click node_rules "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgRules.ts"
click node_fusion "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgFusionEngine.ts"
click node_clinical_library "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgClinicalLibrary.ts"
click node_vitals_rules "https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgVitalsRules.ts"
click node_breath_controls "https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/BreathControls.tsx"
click node_breath_sim "https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/breathing.ts"
click node_heart_controls "https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/HeartControls.tsx"
click node_heart_sound "https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/heartSound.ts"
click node_rhythms "https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/rhythms.ts"
click node_breath_store "https://github.com/shark204/codeblue-sounds/blob/main/stores/breathStore.ts"
click node_heart_store "https://github.com/shark204/codeblue-sounds/blob/main/stores/heartStore.ts"
click node_auth "https://github.com/shark204/codeblue-sounds/blob/main/components/AuthGate.tsx"
click node_account_modals "https://github.com/shark204/codeblue-sounds/blob/main/components/AccountMenuModals.tsx"
click node_pricing "https://github.com/shark204/codeblue-sounds/blob/main/components/PricingModal.tsx"
click node_supabase "https://github.com/shark204/codeblue-sounds/blob/main/lib/supabase.ts"
click node_admin_api "https://github.com/shark204/codeblue-sounds/blob/main/lib/supabaseAdmin.ts"
click node_revenuecat "https://github.com/shark204/codeblue-sounds/blob/main/lib/revenuecatNative.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_studio,node_api_client,node_analyze_route,node_visual_ai,node_image_engine,node_single_lead,node_diagnosis_view toneBlue
class node_hybrid_engine,node_rules,node_fusion,node_clinical_library,node_vitals_rules,node_supabase_service toneAmber
class node_breath_controls,node_breath_sim,node_heart_controls,node_heart_sound,node_rhythms,node_breath_store,node_heart_store toneMint
class node_auth,node_account_modals,node_pricing,node_supabase,node_admin_api,node_revenuecat toneRose
class node_user toneIndigo
class node_home toneTeal
```

## Components

### ECG Analysis

- [Diagnostic studio](https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgDiagnosticStudio.tsx): `features/ecg/EcgDiagnosticStudio.tsx`
- [ECG API client](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgApiClient.ts): `lib/ecgApiClient.ts`
- [Analysis endpoint](https://github.com/shark204/codeblue-sounds/blob/main/app/api/ecg-analyze/route.ts): `app/api/ecg-analyze/route.ts`
- [Visual AI backend](https://github.com/shark204/codeblue-sounds/blob/main/hf_ecg_space/modal_app.py): `hf_ecg_space/modal_app.py`
- [Image extraction](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgImageEngine.ts): `lib/ecgImageEngine.ts`
- [Single-lead mode](https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgSingleLeadCard.tsx): `features/ecg/EcgSingleLeadCard.tsx`
- [Diagnosis report](https://github.com/shark204/codeblue-sounds/blob/main/features/ecg/EcgDiagnosisView.tsx): `features/ecg/EcgDiagnosisView.tsx`

### Clinical Engine

- [Hybrid diagnosis](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgHybridEngine.ts): `lib/ecgHybridEngine.ts`
- [ECG rules](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgRules.ts): `lib/ecgRules.ts`
- [Finding fusion](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgFusionEngine.ts): `lib/ecgFusionEngine.ts`
- [Clinical reference](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgClinicalLibrary.ts): `lib/ecgClinicalLibrary.ts`
- [Vitals rules](https://github.com/shark204/codeblue-sounds/blob/main/lib/ecgVitalsRules.ts): `lib/ecgVitalsRules.ts`

### Sounds Lab

- [Breath controls](https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/BreathControls.tsx): `features/viewer/BreathControls.tsx`
- [Breath simulation](https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/breathing.ts): `features/viewer/breathing.ts`
- [Heart controls](https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/HeartControls.tsx): `features/viewer/HeartControls.tsx`
- [Heart sounds](https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/heartSound.ts): `features/viewer/heartSound.ts`
- [Rhythm simulation](https://github.com/shark204/codeblue-sounds/blob/main/features/viewer/rhythms.ts): `features/viewer/rhythms.ts`
- [Breath state](https://github.com/shark204/codeblue-sounds/blob/main/stores/breathStore.ts): `stores/breathStore.ts`
- [Heart state](https://github.com/shark204/codeblue-sounds/blob/main/stores/heartStore.ts): `stores/heartStore.ts`

### Accounts

- [Authentication gate](https://github.com/shark204/codeblue-sounds/blob/main/components/AuthGate.tsx): `components/AuthGate.tsx`
- [Account management](https://github.com/shark204/codeblue-sounds/blob/main/components/AccountMenuModals.tsx): `components/AccountMenuModals.tsx`
- [Plans and pricing](https://github.com/shark204/codeblue-sounds/blob/main/components/PricingModal.tsx): `components/PricingModal.tsx`
- [Supabase client](https://github.com/shark204/codeblue-sounds/blob/main/lib/supabase.ts): `lib/supabase.ts`
- [Admin database access](https://github.com/shark204/codeblue-sounds/blob/main/lib/supabaseAdmin.ts): `lib/supabaseAdmin.ts`
- [RevenueCat billing](https://github.com/shark204/codeblue-sounds/blob/main/lib/revenuecatNative.ts): `lib/revenuecatNative.ts`

### Other components

- **Learner / clinician**
- [Home experience](https://github.com/shark204/codeblue-sounds/blob/main/app/page.tsx): `app/page.tsx`
- **Supabase service**

## Connections

- Learner / clinician → Home experience: opens (evidence: `app/page.tsx`)
- Home experience → Diagnostic studio: renders (evidence: `app/page.tsx`)
- Diagnostic studio → ECG API client: requests analysis (evidence: `features/ecg/EcgDiagnosticStudio.tsx`)
- ECG API client → Analysis endpoint: posts ECG (evidence: `lib/ecgApiClient.ts`)
- Analysis endpoint → Visual AI backend: forwards image (evidence: `app/api/ecg-analyze/route.ts`)
- Diagnostic studio → Image extraction: extracts locally (evidence: `features/ecg/EcgDiagnosticStudio.tsx`)
- Diagnostic studio → Hybrid diagnosis: runs diagnosis (evidence: `features/ecg/EcgDiagnosticStudio.tsx`)
- Diagnostic studio → Single-lead mode: renders mode (evidence: `features/ecg/EcgDiagnosticStudio.tsx`)
- Diagnosis report → Hybrid diagnosis: uses results (evidence: `features/ecg/EcgDiagnosisView.tsx`)
- Hybrid diagnosis → ECG rules: evaluates findings (evidence: `lib/ecgHybridEngine.ts`)
- Hybrid diagnosis → Finding fusion: computes availability (evidence: `lib/ecgHybridEngine.ts`)
- Hybrid diagnosis → Clinical reference: looks up entries (evidence: `lib/ecgHybridEngine.ts`)
- Hybrid diagnosis → Vitals rules: applies vitals (evidence: `lib/ecgHybridEngine.ts`)
- Home experience → Breath controls: opens lab (evidence: `app/page.tsx`)
- Home experience → Heart controls: opens lab (evidence: `app/page.tsx`)
- Breath controls → Breath simulation: configures simulation (evidence: `features/viewer/BreathControls.tsx`)
- Breath controls → Breath state: updates state (evidence: `features/viewer/BreathControls.tsx`)
- Breath state → Breath simulation: uses patterns (evidence: `stores/breathStore.ts`)
- Heart state → Heart sounds: uses sounds (evidence: `stores/heartStore.ts`)
- Heart state → Rhythm simulation: uses rhythms (evidence: `stores/heartStore.ts`)
- Heart sounds → Rhythm simulation: uses rhythm data (evidence: `features/viewer/heartSound.ts`)
- Home experience → Authentication gate: renders gate (evidence: `app/page.tsx`)
- Authentication gate → Account management: opens dialogs (evidence: `components/AuthGate.tsx`)
- Authentication gate → Plans and pricing: opens plans (evidence: `components/AuthGate.tsx`)
- Account management → Supabase client: uses auth (evidence: `components/AccountMenuModals.tsx`)
- Plans and pricing → Supabase client: uses auth (evidence: `components/PricingModal.tsx`)
- Account management → RevenueCat billing: uses billing (evidence: `components/AccountMenuModals.tsx`)
- Plans and pricing → RevenueCat billing: uses billing (evidence: `components/PricingModal.tsx`)
- Analysis endpoint → Admin database access: verifies user (evidence: `app/api/ecg-analyze/route.ts`)
- Admin database access → Supabase service: authenticates against (evidence: `lib/supabaseAdmin.ts`)
- Supabase client → Supabase service: connects to
