# balayuvaraj2812/health architecture

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

- Interactive diagram: https://gitdiagram.com/balayuvaraj2812/health
- Repository: https://github.com/balayuvaraj2812/health

## Overview

MedSafe is a medication-management web application. Patients sign in, manage medication schedules, record doses, and receive reminder and safety information; they can also upload prescriptions for OCR extraction and review. The dashboard includes calendar, history, timeline, and AI-insight views, while the interface supports English and Telugu. The graph follows relationships visible in excerpts and the source index; unsampled dashboard links and reminder dispatch wiring are not asserted.

Main entry points: [`src/context/MedicationContext.tsx`](https://github.com/balayuvaraj2812/health/blob/main/src/context/MedicationContext.tsx) (Medication state), [`src/lib/firebase-admin.ts`](https://github.com/balayuvaraj2812/health/blob/main/src/lib/firebase-admin.ts) (Firebase admin access), [`src/app/ePrescription/page.tsx`](https://github.com/balayuvaraj2812/health/blob/main/src/app/ePrescription/page.tsx) (Prescription workspace), [`src/app/api/medications/route.ts`](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/medications/route.ts) (Medication API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_patient_app["Patient experience"]
  node_dashboard["Dashboard overview<br/>[page.tsx]"]
  node_medication_views["Medication views<br/>[page.tsx]"]
  node_calendar_view["Schedule calendar<br/>[page.tsx]"]
  node_history_view["Medication history<br/>[page.tsx]"]
  node_timeline_view["Dose timeline<br/>[page.tsx]"]
  node_alerts_view["Safety alerts<br/>[page.tsx]"]
  node_ai_view["AI insights"]
  node_translation["Language context"]
end

subgraph group_medication["Medication management"]
  node_med_context["Medication state"]
  node_medication_api["Medication API<br/>[route.ts]"]
  node_dose_api["Dose recording API<br/>[route.ts]"]
  node_medication_types["Medication models<br/>[medication.ts]"]
end

subgraph group_prescriptions["Prescription processing"]
  node_prescription_ui["Prescription workspace<br/>[page.tsx]"]
  node_prescription_upload["Prescription upload API<br/>[route.ts]"]
  node_prescription_ocr["Prescription OCR API<br/>[route.ts]"]
  node_ocr_script["OCR engine"]
  node_prescription_save["Prescription save API<br/>[route.ts]"]
end

subgraph group_identity["Identity and persistence"]
  node_auth_api["Authentication APIs<br/>[route.ts]"]
  node_jwt["JWT sessions<br/>[jwt.ts]"]
  node_prisma["Prisma client<br/>[prisma.ts]"]
  node_relational_store[("Relational database")]
  node_firebase_admin["Firebase admin access<br/>[firebase-admin.ts]"]
  node_firestore[("Firestore")]
  node_firebase_storage[("Firebase Storage")]
end

subgraph group_reminders["Reminders and alerts"]
  node_reminder_api["Reminder API<br/>[route.ts]"]
  node_reminder_status["Reminder status API<br/>[route.ts]"]
  node_scheduler["Reminder scheduler"]
  node_notifications["Notification service"]
end

node_patient(("Patient"))
node_sms_gateway["SMS gateway"]

node_patient -.->|"opens"| node_dashboard
node_patient -.->|"uploads prescription"| node_prescription_ui
node_prescription_ui -->|"uses state"| node_med_context
node_prescription_ui -.->|"uploads image"| node_prescription_upload
node_prescription_ui -.->|"requests OCR"| node_prescription_ocr
node_prescription_ui -.->|"saves prescription"| node_prescription_save
node_prescription_ocr -->|"runs"| node_ocr_script
node_prescription_ocr -->|"gets storage and database"| node_firebase_admin
node_prescription_upload -->|"uses Firebase"| node_firebase_admin
node_prescription_save -->|"uses Firestore"| node_firebase_admin
node_firebase_admin -->|"accesses"| node_firestore
node_firebase_admin -->|"accesses"| node_firebase_storage
node_medication_views -.->|"uses state"| node_med_context
node_calendar_view -.->|"uses schedule"| node_med_context
node_history_view -.->|"uses history"| node_med_context
node_timeline_view -.->|"uses doses"| node_med_context
node_alerts_view -.->|"uses alerts"| node_med_context
node_ai_view -->|"reads medication state"| node_med_context
node_med_context -->|"fetches and creates"| node_medication_api
node_med_context -->|"updates dose state"| node_reminder_api
node_med_context -->|"uses models"| node_medication_types
node_medication_api -->|"authenticates"| node_jwt
node_medication_api -->|"queries medications"| node_prisma
node_dose_api -->|"authenticates"| node_jwt
node_dose_api -->|"uses Firebase"| node_firebase_admin
node_reminder_api -->|"authenticates"| node_jwt
node_reminder_api -->|"queries reminders"| node_prisma
node_reminder_status -->|"uses scheduler"| node_scheduler
node_reminder_status -->|"uses Firebase"| node_firebase_admin
node_scheduler -->|"dispatches notifications"| node_notifications
node_notifications -->|"records notifications"| node_firebase_admin
node_notifications -.->|"optionally dispatches SMS"| node_sms_gateway
node_prisma -.->|"queries"| node_relational_store

click node_dashboard "https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/page.tsx"
click node_medication_views "https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/medications/page.tsx"
click node_calendar_view "https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/calendar/page.tsx"
click node_history_view "https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/history/page.tsx"
click node_timeline_view "https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/timeline/page.tsx"
click node_alerts_view "https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/alerts/page.tsx"
click node_ai_view "https://github.com/balayuvaraj2812/health/blob/main/src/components/dashboard/AIInsightsPanel.tsx"
click node_translation "https://github.com/balayuvaraj2812/health/blob/main/src/context/LanguageContext.tsx"
click node_med_context "https://github.com/balayuvaraj2812/health/blob/main/src/context/MedicationContext.tsx"
click node_medication_api "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/medications/route.ts"
click node_dose_api "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/medications/take-dose/route.ts"
click node_medication_types "https://github.com/balayuvaraj2812/health/blob/main/src/types/medication.ts"
click node_prescription_ui "https://github.com/balayuvaraj2812/health/blob/main/src/app/ePrescription/page.tsx"
click node_prescription_upload "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/prescriptions/upload/route.ts"
click node_prescription_ocr "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/prescriptions/ocr/route.ts"
click node_ocr_script "https://github.com/balayuvaraj2812/health/blob/main/scripts/ocr_prescription.py"
click node_prescription_save "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/prescriptions/save/route.ts"
click node_auth_api "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/auth/login/route.ts"
click node_jwt "https://github.com/balayuvaraj2812/health/blob/main/src/lib/jwt.ts"
click node_prisma "https://github.com/balayuvaraj2812/health/blob/main/src/lib/prisma.ts"
click node_firebase_admin "https://github.com/balayuvaraj2812/health/blob/main/src/lib/firebase-admin.ts"
click node_reminder_api "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/reminders/route.ts"
click node_reminder_status "https://github.com/balayuvaraj2812/health/blob/main/src/app/api/reminders/status/route.ts"
click node_scheduler "https://github.com/balayuvaraj2812/health/blob/main/src/lib/reminder-scheduler.ts"
click node_notifications "https://github.com/balayuvaraj2812/health/blob/main/src/lib/notification-service.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_dashboard,node_medication_views,node_calendar_view,node_history_view,node_timeline_view,node_alerts_view,node_ai_view,node_translation toneBlue
class node_med_context,node_medication_api,node_dose_api,node_medication_types toneAmber
class node_prescription_ui,node_prescription_upload,node_prescription_ocr,node_ocr_script,node_prescription_save toneMint
class node_auth_api,node_jwt,node_prisma,node_relational_store,node_firebase_admin,node_firestore,node_firebase_storage toneRose
class node_reminder_api,node_reminder_status,node_scheduler,node_notifications,node_patient,node_sms_gateway toneIndigo
```

## Components

### Patient experience

- [Dashboard overview](https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Medication views](https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/medications/page.tsx): `src/app/dashboard/medications/page.tsx`
- [Schedule calendar](https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/calendar/page.tsx): `src/app/dashboard/calendar/page.tsx`
- [Medication history](https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/history/page.tsx): `src/app/dashboard/history/page.tsx`
- [Dose timeline](https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/timeline/page.tsx): `src/app/dashboard/timeline/page.tsx`
- [Safety alerts](https://github.com/balayuvaraj2812/health/blob/main/src/app/dashboard/alerts/page.tsx): `src/app/dashboard/alerts/page.tsx`
- [AI insights](https://github.com/balayuvaraj2812/health/blob/main/src/components/dashboard/AIInsightsPanel.tsx): `src/components/dashboard/AIInsightsPanel.tsx`
- [Language context](https://github.com/balayuvaraj2812/health/blob/main/src/context/LanguageContext.tsx): `src/context/LanguageContext.tsx`

### Medication management

- [Medication state](https://github.com/balayuvaraj2812/health/blob/main/src/context/MedicationContext.tsx): `src/context/MedicationContext.tsx`
- [Medication API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/medications/route.ts): `src/app/api/medications/route.ts`
- [Dose recording API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/medications/take-dose/route.ts): `src/app/api/medications/take-dose/route.ts`
- [Medication models](https://github.com/balayuvaraj2812/health/blob/main/src/types/medication.ts): `src/types/medication.ts`

### Prescription processing

- [Prescription workspace](https://github.com/balayuvaraj2812/health/blob/main/src/app/ePrescription/page.tsx): `src/app/ePrescription/page.tsx`
- [Prescription upload API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/prescriptions/upload/route.ts): `src/app/api/prescriptions/upload/route.ts`
- [Prescription OCR API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/prescriptions/ocr/route.ts): `src/app/api/prescriptions/ocr/route.ts`
- [OCR engine](https://github.com/balayuvaraj2812/health/blob/main/scripts/ocr_prescription.py): `scripts/ocr_prescription.py`
- [Prescription save API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/prescriptions/save/route.ts): `src/app/api/prescriptions/save/route.ts`

### Identity and persistence

- [Authentication APIs](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/auth/login/route.ts): `src/app/api/auth/login/route.ts`
- [JWT sessions](https://github.com/balayuvaraj2812/health/blob/main/src/lib/jwt.ts): `src/lib/jwt.ts`
- [Prisma client](https://github.com/balayuvaraj2812/health/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`
- **Relational database**
- [Firebase admin access](https://github.com/balayuvaraj2812/health/blob/main/src/lib/firebase-admin.ts): `src/lib/firebase-admin.ts`
- **Firestore**
- **Firebase Storage**

### Reminders and alerts

- [Reminder API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/reminders/route.ts): `src/app/api/reminders/route.ts`
- [Reminder status API](https://github.com/balayuvaraj2812/health/blob/main/src/app/api/reminders/status/route.ts): `src/app/api/reminders/status/route.ts`
- [Reminder scheduler](https://github.com/balayuvaraj2812/health/blob/main/src/lib/reminder-scheduler.ts): `src/lib/reminder-scheduler.ts`
- [Notification service](https://github.com/balayuvaraj2812/health/blob/main/src/lib/notification-service.ts): `src/lib/notification-service.ts`

### Other components

- **Patient**
- **SMS gateway**

## Connections

- Patient → Dashboard overview: opens
- Patient → Prescription workspace: uploads prescription
- Prescription workspace → Medication state: uses state (evidence: `src/app/ePrescription/page.tsx`)
- Prescription workspace → Prescription upload API: uploads image
- Prescription workspace → Prescription OCR API: requests OCR
- Prescription workspace → Prescription save API: saves prescription
- Prescription OCR API → OCR engine: runs (evidence: `src/app/api/prescriptions/ocr/route.ts`)
- Prescription OCR API → Firebase admin access: gets storage and database (evidence: `src/app/api/prescriptions/ocr/route.ts`)
- Prescription upload API → Firebase admin access: uses Firebase (evidence: `src/app/api/prescriptions/upload/route.ts`)
- Prescription save API → Firebase admin access: uses Firestore (evidence: `src/app/api/prescriptions/save/route.ts`)
- Firebase admin access → Firestore: accesses (evidence: `src/lib/firebase-admin.ts`)
- Firebase admin access → Firebase Storage: accesses (evidence: `src/lib/firebase-admin.ts`)
- Medication views → Medication state: uses state
- Schedule calendar → Medication state: uses schedule
- Medication history → Medication state: uses history
- Dose timeline → Medication state: uses doses
- Safety alerts → Medication state: uses alerts
- AI insights → Medication state: reads medication state (evidence: `src/components/dashboard/AIInsightsPanel.tsx`)
- Medication state → Medication API: fetches and creates (evidence: `src/context/MedicationContext.tsx`)
- Medication state → Reminder API: updates dose state (evidence: `src/context/MedicationContext.tsx`)
- Medication state → Medication models: uses models (evidence: `src/context/MedicationContext.tsx`)
- Medication API → JWT sessions: authenticates (evidence: `src/app/api/medications/route.ts`)
- Medication API → Prisma client: queries medications (evidence: `src/app/api/medications/route.ts`)
- Dose recording API → JWT sessions: authenticates (evidence: `src/app/api/medications/take-dose/route.ts`)
- Dose recording API → Firebase admin access: uses Firebase (evidence: `src/app/api/medications/take-dose/route.ts`)
- Reminder API → JWT sessions: authenticates (evidence: `src/app/api/reminders/route.ts`)
- Reminder API → Prisma client: queries reminders (evidence: `src/app/api/reminders/route.ts`)
- Reminder status API → Reminder scheduler: uses scheduler (evidence: `src/app/api/reminders/status/route.ts`)
- Reminder status API → Firebase admin access: uses Firebase (evidence: `src/app/api/reminders/status/route.ts`)
- Reminder scheduler → Notification service: dispatches notifications (evidence: `src/lib/reminder-scheduler.ts`)
- Notification service → Firebase admin access: records notifications (evidence: `src/lib/notification-service.ts`)
- Notification service → SMS gateway: optionally dispatches SMS (evidence: `src/lib/notification-service.ts`)
- Prisma client → Relational database: queries
