# kidneybeanhealth/beanhealth architecture

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

- Interactive diagram: https://gitdiagram.com/kidneybeanhealth/beanhealth
- Repository: https://github.com/kidneybeanhealth/beanhealth

## Overview

BeanHealth is a patient–doctor healthcare management platform with an enterprise-care branch. The main user journey is signing in, reviewing or updating patient health information, and coordinating care through records, messaging, alerts, and prescriptions. CKD rule evaluation and snapshots provide a clinical-monitoring layer. The README documents product capabilities not fully represented in the sampled excerpts; those branches are included at the subsystem level, while uncertain internal wiring is omitted.

Main entry points: [`src/App.tsx`](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/App.tsx) (Application shell), [`src/components/PatientDashboard.tsx`](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/PatientDashboard.tsx) (Patient dashboard), [`src/lib/supabase.ts`](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/lib/supabase.ts) (Supabase), [`src/components/DoctorDashboardMain.tsx`](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/DoctorDashboardMain.tsx) (Doctor dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and navigation"]
  node_app["Application shell<br/>[App.tsx]"]
  node_routes["Routes and guards<br/>[index.tsx]"]
  node_auth["Authentication state<br/>[AuthContext.tsx]"]
  node_auth_service["Authentication service<br/>[authService.ts]"]
end

subgraph group_patient["Patient health"]
  node_patient_dashboard["Patient dashboard"]
  node_records["Medical records"]
  node_labs["Lab results"]
  node_medications["Medication management"]
  node_progress["Progress and vitals<br/>[CKDDashboard.tsx]"]
end

subgraph group_care["Care coordination"]
  node_doctor_dashboard["Doctor dashboard"]
  node_chat["Secure messaging<br/>[chatService.ts]"]
  node_realtime["Realtime updates"]
  node_alerts["Alerts and notifications<br/>[alertService.ts]"]
  node_prescriptions["Prescriptions"]
  node_enterprise["Enterprise workflows"]
end

subgraph group_platform["Clinical platform"]
  node_rule_engine["CKD rule engine"]
  node_rule_evaluator["Rule evaluation<br/>[ruleEvaluator.ts]"]
  node_rule_admin["Rule administration"]
  node_storage_service["File storage service<br/>[storageService.ts]"]
  node_gemini["Gemini analysis<br/>[geminiService.ts]"]
  node_supabase[("Supabase<br/>[supabase.ts]")]
end

node_patient_actor(("Patient"))
node_doctor_actor(("Doctor"))
node_staff_actor(("Enterprise staff"))
node_gemini_api{{"Google Gemini API"}}

node_patient_actor -->|"uses"| node_app
node_doctor_actor -->|"uses"| node_app
node_staff_actor -->|"uses"| node_app
node_app -->|"renders"| node_routes
node_app -->|"provides state"| node_auth
node_app -->|"hosts"| node_patient_dashboard
node_app -->|"hosts"| node_doctor_dashboard
node_auth -->|"authenticates"| node_auth_service
node_auth_service -->|"uses auth"| node_supabase
node_patient_dashboard -->|"shows records"| node_records
node_patient_dashboard -->|"shows labs"| node_labs
node_patient_dashboard -->|"shows medications"| node_medications
node_patient_dashboard -->|"shows progress"| node_progress
node_doctor_dashboard -->|"communicates via"| node_chat
node_patient_dashboard -->|"communicates via"| node_chat
node_chat -->|"updates through"| node_realtime
node_chat -->|"persists messages"| node_supabase
node_records -->|"stores documents"| node_storage_service
node_storage_service -->|"uploads files"| node_supabase
node_records -.->|"requests analysis"| node_gemini
node_gemini -.->|"analyzes documents"| node_gemini_api
node_doctor_dashboard -->|"creates prescriptions"| node_prescriptions
node_prescriptions -->|"delivers prescription"| node_chat
node_doctor_dashboard -->|"reviews alerts"| node_alerts
node_alerts -->|"reads and writes"| node_supabase
node_enterprise -->|"supports care"| node_doctor_dashboard
node_enterprise -->|"manages prescriptions"| node_prescriptions
node_rule_admin -->|"manages rule versions"| node_supabase
node_rule_engine -->|"loads lab context"| node_labs
node_rule_engine -->|"evaluates rules"| node_rule_evaluator
node_rule_engine -->|"loads rules and saves snapshots"| node_supabase
node_rule_engine -->|"produces monitoring results"| node_alerts

click node_app "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/App.tsx"
click node_routes "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/routes/index.tsx"
click node_auth "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/contexts/AuthContext.tsx"
click node_auth_service "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/authService.ts"
click node_patient_dashboard "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/PatientDashboard.tsx"
click node_records "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/medicalRecordsService.ts"
click node_labs "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/labResultsService.ts"
click node_medications "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/medicationService.ts"
click node_progress "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/CKDDashboard.tsx"
click node_doctor_dashboard "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/DoctorDashboardMain.tsx"
click node_chat "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/chatService.ts"
click node_realtime "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/hooks/useRealTimeChatV2.ts"
click node_alerts "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/alertService.ts"
click node_prescriptions "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/prescriptionService.ts"
click node_enterprise "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/enterprise/EnterpriseDashboardHome.tsx"
click node_rule_engine "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/ruleEngineService.ts"
click node_rule_evaluator "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/ruleEvaluator.ts"
click node_rule_admin "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/RuleEngineAdmin.tsx"
click node_storage_service "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/storageService.ts"
click node_gemini "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/geminiService.ts"
click node_supabase "https://github.com/kidneybeanhealth/beanhealth/blob/main/src/lib/supabase.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_app,node_routes,node_auth,node_auth_service toneBlue
class node_patient_dashboard,node_records,node_labs,node_medications,node_progress toneAmber
class node_doctor_dashboard,node_chat,node_realtime,node_alerts,node_prescriptions,node_enterprise,node_gemini_api toneMint
class node_rule_engine,node_rule_evaluator,node_rule_admin,node_storage_service,node_gemini,node_supabase toneRose
class node_patient_actor,node_doctor_actor,node_staff_actor toneIndigo
```

## Components

### Access and navigation

- [Application shell](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/App.tsx): `src/App.tsx`
- [Routes and guards](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/routes/index.tsx): `src/routes/index.tsx`
- [Authentication state](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/contexts/AuthContext.tsx): `src/contexts/AuthContext.tsx`
- [Authentication service](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/authService.ts): `src/services/authService.ts`

### Patient health

- [Patient dashboard](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/PatientDashboard.tsx): `src/components/PatientDashboard.tsx`
- [Medical records](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/medicalRecordsService.ts): `src/services/medicalRecordsService.ts`
- [Lab results](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/labResultsService.ts): `src/services/labResultsService.ts`
- [Medication management](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/medicationService.ts): `src/services/medicationService.ts`
- [Progress and vitals](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/CKDDashboard.tsx): `src/components/CKDDashboard.tsx`

### Care coordination

- [Doctor dashboard](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/DoctorDashboardMain.tsx): `src/components/DoctorDashboardMain.tsx`
- [Secure messaging](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/chatService.ts): `src/services/chatService.ts`
- [Realtime updates](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/hooks/useRealTimeChatV2.ts): `src/hooks/useRealTimeChatV2.ts`
- [Alerts and notifications](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/alertService.ts): `src/services/alertService.ts`
- [Prescriptions](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/prescriptionService.ts): `src/services/prescriptionService.ts`
- [Enterprise workflows](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/enterprise/EnterpriseDashboardHome.tsx): `src/components/enterprise/EnterpriseDashboardHome.tsx`

### Clinical platform

- [CKD rule engine](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/ruleEngineService.ts): `src/services/ruleEngineService.ts`
- [Rule evaluation](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/ruleEvaluator.ts): `src/services/ruleEvaluator.ts`
- [Rule administration](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/components/RuleEngineAdmin.tsx): `src/components/RuleEngineAdmin.tsx`
- [File storage service](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/storageService.ts): `src/services/storageService.ts`
- [Gemini analysis](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/services/geminiService.ts): `src/services/geminiService.ts`
- [Supabase](https://github.com/kidneybeanhealth/beanhealth/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`

### Other components

- **Patient**
- **Doctor**
- **Enterprise staff**
- **Google Gemini API**

## Connections

- Patient → Application shell: uses
- Doctor → Application shell: uses
- Enterprise staff → Application shell: uses
- Application shell → Routes and guards: renders
- Application shell → Authentication state: provides state
- Application shell → Patient dashboard: hosts
- Application shell → Doctor dashboard: hosts
- Authentication state → Authentication service: authenticates
- Authentication service → Supabase: uses auth
- Patient dashboard → Medical records: shows records
- Patient dashboard → Lab results: shows labs
- Patient dashboard → Medication management: shows medications
- Patient dashboard → Progress and vitals: shows progress
- Doctor dashboard → Secure messaging: communicates via
- Patient dashboard → Secure messaging: communicates via
- Secure messaging → Realtime updates: updates through
- Secure messaging → Supabase: persists messages
- Medical records → File storage service: stores documents
- File storage service → Supabase: uploads files
- Medical records → Gemini analysis: requests analysis
- Gemini analysis → Google Gemini API: analyzes documents
- Doctor dashboard → Prescriptions: creates prescriptions
- Prescriptions → Secure messaging: delivers prescription
- Doctor dashboard → Alerts and notifications: reviews alerts
- Alerts and notifications → Supabase: reads and writes
- Enterprise workflows → Doctor dashboard: supports care
- Enterprise workflows → Prescriptions: manages prescriptions
- Rule administration → Supabase: manages rule versions
- CKD rule engine → Lab results: loads lab context
- CKD rule engine → Rule evaluation: evaluates rules
- CKD rule engine → Supabase: loads rules and saves snapshots
- CKD rule engine → Alerts and notifications: produces monitoring results
