# rudrakshsoni-dev/medisaathi architecture

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

- Interactive diagram: https://gitdiagram.com/rudrakshsoni-dev/medisaathi
- Repository: https://github.com/rudrakshsoni-dev/medisaathi

## Overview

MediSaathi is an offline-first medication companion: patients manage medicines and doses in the Android app, while caregivers monitor linked patients through a web dashboard. The patient workflow spans authentication, medication scheduling, daily dose tracking, reminders, history, and optional AI proposal approval; caregiver links, alerts, and health records form a distinct oversight workflow. The backend supplies authenticated APIs, deterministic drug-safety checks, proposal handling, and scheduled alerts. Some feature wiring is documented in the README but its implementation was not sampled; those relationships are cited as documentation.

Main entry points: [`MediSaathi/client/src/app/routes.jsx`](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/app/routes.jsx) (App shell and routes), [`MediSaathi/server/src/lib/firebase.js`](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/lib/firebase.js) (Firestore data), [`MediSaathi/server/src/routes/agent.js`](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/routes/agent.js) (Proposal API), [`MediSaathi/client/src/hooks/useDoseEvents.js`](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/hooks/useDoseEvents.js) (Dose and medicine data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Patient app"]
  node_app["App shell and routes<br/>[routes.jsx]"]
  node_auth["Sign-in and session<br/>[session.js]"]
  node_meds["Medicine management<br/>[MedFormScreen.jsx]"]
  node_today["Today doses<br/>[TodayScreen.jsx]"]
  node_dosehooks["Dose and medicine data<br/>[useDoseEvents.js]"]
  node_remindersync["Reminder synchronization<br/>[useReminderSync.js]"]
  node_notifications["Local notifications<br/>[notifications.js]"]
  node_history["History and records<br/>[HistoryScreen.jsx]"]
  node_profile["Profile and preferences<br/>[ProfileScreen.jsx]"]
end

subgraph group_care["Caregiver oversight"]
  node_careboard["Caregiver dashboard"]
  node_patientdetail["Patient detail"]
  node_carelink["Caregiver linking<br/>[LinkScreen.jsx]"]
end

subgraph group_server["Backend services"]
  node_api["API routing<br/>[app.js]"]
  node_authmw["Token and role checks<br/>[auth.js]"]
  node_firestore[("Firestore data<br/>[firebase.js]")]
  node_careapi["Caregiver API<br/>[caregiver.js]"]
  node_jobs["Missed and refill jobs<br/>[runJobs.js]"]
  node_pushes["Caregiver push delivery<br/>[pushes.js]"]
  node_drugindex[("Drug index<br/>[drugIndex.js]")]
end

subgraph group_agent["Assistant and safety"]
  node_assistant["Assistant screen"]
  node_agentroute["Proposal API<br/>[agent.js]"]
  node_agentcore["Agent orchestration<br/>[runAgent.js]"]
  node_agenttools["Read-only tools<br/>[tools.js]"]
  node_safety["Emergency and guards<br/>[guards.js]"]
end

subgraph group_shared["Shared domain logic"]
  node_sharedschedule["Schedule builder<br/>[schedule.js]"]
  node_shareddoses["Dose event generation<br/>[doseEvents.js]"]
end

node_patient(("Patient"))
node_caregiver(("Caregiver"))
node_externalllm["Gemini service"]
node_externalpush["FCM push service"]
node_ddinter[("DDInter data")]

node_patient -->|"uses"| node_app
node_caregiver -->|"monitors"| node_careboard
node_app -->|"initializes"| node_auth
node_app -->|"routes to"| node_meds
node_app -->|"routes to"| node_today
node_app -->|"routes to"| node_history
node_app -->|"routes to"| node_profile
node_app -->|"routes to"| node_assistant
node_app -->|"routes to"| node_careboard
node_app -->|"routes to"| node_patientdetail
node_app -->|"routes to"| node_carelink
node_meds -->|"reads and updates"| node_dosehooks
node_today -.->|"tracks doses"| node_dosehooks
node_remindersync -->|"reads"| node_dosehooks
node_remindersync -->|"synchronizes"| node_notifications
node_dosehooks -->|"reads"| node_firestore
node_auth -->|"listens to profile"| node_firestore
node_careboard -.->|"live reads"| node_firestore
node_patientdetail -.->|"reads records"| node_firestore
node_api -->|"applies"| node_authmw
node_api -->|"mounts"| node_careapi
node_authmw -->|"loads profile"| node_firestore
node_careapi -->|"reads and writes"| node_firestore
node_jobs -->|"checks alerts"| node_firestore
node_jobs -->|"dispatches"| node_pushes
node_pushes -.->|"sends"| node_externalpush
node_assistant -.->|"requests proposals"| node_agentroute
node_agentroute -->|"checks emergency"| node_safety
node_agentroute -->|"runs"| node_agentcore
node_agentcore -->|"invokes tools"| node_agenttools
node_agentcore -.->|"calls model"| node_externalllm
node_agenttools -.->|"reads context"| node_firestore
node_agenttools -.->|"looks up drugs"| node_drugindex
node_safety -.->|"checks interactions"| node_ddinter
node_agentroute -->|"stores proposal"| node_firestore
node_agentroute -->|"generates on approval"| node_shareddoses
node_remindersync -.->|"uses dose window"| node_sharedschedule
node_shareddoses -->|"uses schedule logic"| node_sharedschedule
node_profile -.->|"configures reminders"| node_notifications

click node_app "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/app/routes.jsx"
click node_auth "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/store/session.js"
click node_meds "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/meds/MedFormScreen.jsx"
click node_today "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/today/TodayScreen.jsx"
click node_dosehooks "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/hooks/useDoseEvents.js"
click node_remindersync "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/hooks/useReminderSync.js"
click node_notifications "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/native/notifications.js"
click node_history "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/history/HistoryScreen.jsx"
click node_profile "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/profile/ProfileScreen.jsx"
click node_careboard "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/caregiver/DashboardScreen.jsx"
click node_patientdetail "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/caregiver/PatientDetailScreen.jsx"
click node_carelink "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/caregiver/LinkScreen.jsx"
click node_api "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/app.js"
click node_authmw "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/middleware/auth.js"
click node_firestore "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/lib/firebase.js"
click node_careapi "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/routes/caregiver.js"
click node_jobs "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/jobs/runJobs.js"
click node_pushes "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/jobs/pushes.js"
click node_assistant "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/assistant/AssistantScreen.jsx"
click node_agentroute "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/routes/agent.js"
click node_agentcore "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/agent/runAgent.js"
click node_agenttools "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/agent/tools.js"
click node_safety "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/agent/guards.js"
click node_drugindex "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/services/drugIndex.js"
click node_sharedschedule "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/shared/src/schedule.js"
click node_shareddoses "https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/shared/src/doseEvents.js"

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_auth,node_meds,node_today,node_dosehooks,node_remindersync,node_notifications,node_history,node_profile toneBlue
class node_careboard,node_patientdetail,node_carelink,node_ddinter toneAmber
class node_api,node_authmw,node_firestore,node_careapi,node_jobs,node_pushes,node_drugindex toneMint
class node_assistant,node_agentroute,node_agentcore,node_agenttools,node_safety toneRose
class node_sharedschedule,node_shareddoses,node_patient,node_caregiver,node_externalllm,node_externalpush toneIndigo
```

## Components

### Patient app

- [App shell and routes](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/app/routes.jsx): `MediSaathi/client/src/app/routes.jsx`
- [Sign-in and session](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/store/session.js): `MediSaathi/client/src/store/session.js`
- [Medicine management](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/meds/MedFormScreen.jsx): `MediSaathi/client/src/features/meds/MedFormScreen.jsx`
- [Today doses](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/today/TodayScreen.jsx): `MediSaathi/client/src/features/today/TodayScreen.jsx`
- [Dose and medicine data](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/hooks/useDoseEvents.js): `MediSaathi/client/src/hooks/useDoseEvents.js`
- [Reminder synchronization](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/hooks/useReminderSync.js): `MediSaathi/client/src/hooks/useReminderSync.js`
- [Local notifications](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/native/notifications.js): `MediSaathi/client/src/native/notifications.js`
- [History and records](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/history/HistoryScreen.jsx): `MediSaathi/client/src/features/history/HistoryScreen.jsx`
- [Profile and preferences](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/profile/ProfileScreen.jsx): `MediSaathi/client/src/features/profile/ProfileScreen.jsx`

### Caregiver oversight

- [Caregiver dashboard](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/caregiver/DashboardScreen.jsx): `MediSaathi/client/src/features/caregiver/DashboardScreen.jsx`
- [Patient detail](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/caregiver/PatientDetailScreen.jsx): `MediSaathi/client/src/features/caregiver/PatientDetailScreen.jsx`
- [Caregiver linking](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/caregiver/LinkScreen.jsx): `MediSaathi/client/src/features/caregiver/LinkScreen.jsx`

### Backend services

- [API routing](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/app.js): `MediSaathi/server/src/app.js`
- [Token and role checks](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/middleware/auth.js): `MediSaathi/server/src/middleware/auth.js`
- [Firestore data](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/lib/firebase.js): `MediSaathi/server/src/lib/firebase.js`
- [Caregiver API](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/routes/caregiver.js): `MediSaathi/server/src/routes/caregiver.js`
- [Missed and refill jobs](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/jobs/runJobs.js): `MediSaathi/server/src/jobs/runJobs.js`
- [Caregiver push delivery](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/jobs/pushes.js): `MediSaathi/server/src/jobs/pushes.js`
- [Drug index](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/services/drugIndex.js): `MediSaathi/server/src/services/drugIndex.js`

### Assistant and safety

- [Assistant screen](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/client/src/features/assistant/AssistantScreen.jsx): `MediSaathi/client/src/features/assistant/AssistantScreen.jsx`
- [Proposal API](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/routes/agent.js): `MediSaathi/server/src/routes/agent.js`
- [Agent orchestration](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/agent/runAgent.js): `MediSaathi/server/src/agent/runAgent.js`
- [Read-only tools](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/agent/tools.js): `MediSaathi/server/src/agent/tools.js`
- [Emergency and guards](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/server/src/agent/guards.js): `MediSaathi/server/src/agent/guards.js`

### Shared domain logic

- [Schedule builder](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/shared/src/schedule.js): `MediSaathi/shared/src/schedule.js`
- [Dose event generation](https://github.com/rudrakshsoni-dev/medisaathi/blob/main/MediSaathi/shared/src/doseEvents.js): `MediSaathi/shared/src/doseEvents.js`

### Other components

- **Patient**
- **Caregiver**
- **Gemini service**
- **FCM push service**
- **DDInter data**

## Connections

- Patient → App shell and routes: uses (evidence: `README.md`)
- Caregiver → Caregiver dashboard: monitors (evidence: `README.md`)
- App shell and routes → Sign-in and session: initializes (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Medicine management: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Today doses: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → History and records: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Profile and preferences: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Assistant screen: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Caregiver dashboard: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Patient detail: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- App shell and routes → Caregiver linking: routes to (evidence: `MediSaathi/client/src/app/routes.jsx`)
- Medicine management → Dose and medicine data: reads and updates (evidence: `MediSaathi/client/src/features/meds/MedFormScreen.jsx`)
- Today doses → Dose and medicine data: tracks doses (evidence: `README.md`)
- Reminder synchronization → Dose and medicine data: reads (evidence: `MediSaathi/client/src/hooks/useReminderSync.js`)
- Reminder synchronization → Local notifications: synchronizes (evidence: `MediSaathi/client/src/hooks/useReminderSync.js`)
- Dose and medicine data → Firestore data: reads (evidence: `MediSaathi/client/src/hooks/useDoseEvents.js`)
- Sign-in and session → Firestore data: listens to profile (evidence: `MediSaathi/client/src/store/session.js`)
- Caregiver dashboard → Firestore data: live reads (evidence: `README.md`)
- Patient detail → Firestore data: reads records (evidence: `README.md`)
- API routing → Token and role checks: applies (evidence: `MediSaathi/server/src/app.js`)
- API routing → Caregiver API: mounts (evidence: `MediSaathi/server/src/app.js`)
- Token and role checks → Firestore data: loads profile (evidence: `MediSaathi/server/src/middleware/auth.js`)
- Caregiver API → Firestore data: reads and writes (evidence: `MediSaathi/server/src/routes/caregiver.js`)
- Missed and refill jobs → Firestore data: checks alerts (evidence: `MediSaathi/server/src/jobs/runJobs.js`)
- Missed and refill jobs → Caregiver push delivery: dispatches (evidence: `MediSaathi/server/src/jobs/runJobs.js`)
- Caregiver push delivery → FCM push service: sends (evidence: `README.md`)
- Assistant screen → Proposal API: requests proposals (evidence: `README.md`)
- Proposal API → Emergency and guards: checks emergency (evidence: `MediSaathi/server/src/routes/agent.js`)
- Proposal API → Agent orchestration: runs (evidence: `MediSaathi/server/src/routes/agent.js`)
- Agent orchestration → Read-only tools: invokes tools (evidence: `MediSaathi/server/src/agent/runAgent.js`)
- Agent orchestration → Gemini service: calls model (evidence: `README.md`)
- Read-only tools → Firestore data: reads context
- Read-only tools → Drug index: looks up drugs
- Emergency and guards → DDInter data: checks interactions (evidence: `README.md`)
- Proposal API → Firestore data: stores proposal (evidence: `MediSaathi/server/src/routes/agent.js`)
- Proposal API → Dose event generation: generates on approval (evidence: `MediSaathi/server/src/routes/agent.js`)
- Reminder synchronization → Schedule builder: uses dose window (evidence: `MediSaathi/client/src/hooks/useReminderSync.js`)
- Dose event generation → Schedule builder: uses schedule logic (evidence: `MediSaathi/shared/src/doseEvents.js`)
- Profile and preferences → Local notifications: configures reminders (evidence: `README.md`)
