# shibaji157/medimate-ai architecture

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

- Interactive diagram: https://gitdiagram.com/shibaji157/medimate-ai
- Repository: https://github.com/shibaji157/medimate-ai

## Overview

MediMate AI is a medication-adherence web app: patients create medication schedules, the app evaluates doses and reminders, records patient responses, then supports adherence review and consent-based caregiver escalation. The graph includes major README capabilities and the principal sampled call paths. Some caregiver, reminder, and storage details are documented but not fully sampled, so those links cite the README or are omitted where wiring is uncertain.

Main entry points: [`lib/supabase/server.ts`](https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/server.ts) (Server data client), [`app/dashboard/page.tsx`](https://github.com/shibaji157/medimate-ai/blob/main/app/dashboard/page.tsx) (Dose dashboard), [`app/api/companion/route.ts`](https://github.com/shibaji157/medimate-ai/blob/main/app/api/companion/route.ts) (AI companion endpoint), [`lib/medication/doses.ts`](https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/doses.ts) (Dose and missed-dose logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_patient["Patient Workflow"]
  node_dashboard["Dose dashboard<br/>[page.tsx]"]
  node_medication_ui["Medication management<br/>[page.tsx]"]
  node_notifications["Notification history<br/>[page.tsx]"]
end

subgraph group_medication["Medication Operations"]
  node_medication_api["Medication and schedule API<br/>[route.ts]"]
  node_dose_api["Dose response API<br/>[route.ts]"]
  node_dose_logic["Dose and missed-dose logic<br/>[doses.ts]"]
  node_date_logic["Schedule date handling<br/>[dates.ts]"]
  node_reminder_logic["Reminder synchronization<br/>[reminders.ts]"]
  node_autonomous["Autonomous reminder engine"]
  node_cron["Scheduled reminder job<br/>[route.ts]"]
end

subgraph group_support["Support and Insights"]
  node_analytics["Adherence analytics<br/>[analytics.ts]"]
  node_analytics_page["Analytics view<br/>[page.tsx]"]
  node_charts["Adherence charts"]
  node_caregiver["Caregiver portal<br/>[page.tsx]"]
  node_caregiver_adherence["Patient adherence snapshots<br/>[adherence.ts]"]
  node_escalations["Caregiver escalation<br/>[escalations.ts]"]
  node_companion["AI companion endpoint<br/>[route.ts]"]
  node_companion_context["Companion context"]
  node_companion_safety["Companion safety checks"]
  node_feedback["Feedback submission<br/>[route.ts]"]
end

subgraph group_platform["Application Platform"]
  node_auth["Sign in and signup<br/>[page.tsx]"]
  node_settings["Profile and reminder settings<br/>[route.ts]"]
  node_supabase_server["Server data client<br/>[server.ts]"]
  node_supabase_client["Browser data client<br/>[client.ts]"]
  node_supabase_admin["Administrative data client<br/>[admin.ts]"]
end

node_patient(("Patient"))
node_database[("Supabase database and auth")]

node_patient -->|"signs in"| node_auth
node_patient -->|"reviews doses"| node_dashboard
node_patient -->|"manages medications"| node_medication_ui
node_medication_ui -.->|"saves schedules"| node_medication_api
node_medication_api -->|"creates client"| node_supabase_server
node_medication_api -->|"writes medication and schedules"| node_database
node_dashboard -->|"creates client"| node_supabase_server
node_dashboard -->|"syncs missed doses"| node_dose_logic
node_dashboard -->|"syncs reminders"| node_reminder_logic
node_dashboard -->|"gets local date"| node_date_logic
node_dose_logic -.->|"reads dose records"| node_database
node_patient -->|"records taken or skipped"| node_dose_api
node_dose_api -->|"creates client"| node_supabase_server
node_dose_api -->|"upserts dose event"| node_database
node_cron -->|"runs reminder engine"| node_autonomous
node_autonomous -.->|"evaluates schedules"| node_database
node_patient -->|"reviews notifications"| node_notifications
node_notifications -->|"syncs missed doses"| node_dose_logic
node_notifications -->|"syncs reminders"| node_reminder_logic
node_analytics_page -->|"syncs missed doses"| node_dose_logic
node_analytics_page -->|"loads seven-day analytics"| node_analytics
node_analytics_page -->|"renders charts"| node_charts
node_analytics -.->|"reads dose history"| node_database
node_caregiver -->|"loads patient snapshots"| node_caregiver_adherence
node_caregiver -->|"reads relationships and profiles"| node_supabase_admin
node_caregiver -.->|"reviews escalation history"| node_escalations
node_escalations -.->|"records authorized escalations"| node_database
node_patient -->|"asks companion"| node_companion
node_companion -->|"checks message safety"| node_companion_safety
node_companion -->|"builds user context"| node_companion_context
node_companion -->|"creates client"| node_supabase_server
node_patient -->|"submits feedback"| node_feedback
node_feedback -->|"creates client"| node_supabase_server
node_feedback -->|"inserts feedback"| node_database
node_patient -->|"updates preferences"| node_settings
node_settings -->|"creates client"| node_supabase_server
node_settings -->|"updates profile"| node_database
node_auth -->|"uses browser auth"| node_supabase_client
node_supabase_server -->|"connects server session"| node_database

click node_auth "https://github.com/shibaji157/medimate-ai/blob/main/app/login/page.tsx"
click node_dashboard "https://github.com/shibaji157/medimate-ai/blob/main/app/dashboard/page.tsx"
click node_medication_ui "https://github.com/shibaji157/medimate-ai/blob/main/app/medications/page.tsx"
click node_medication_api "https://github.com/shibaji157/medimate-ai/blob/main/app/api/medications/route.ts"
click node_dose_api "https://github.com/shibaji157/medimate-ai/blob/main/app/api/doses/route.ts"
click node_dose_logic "https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/doses.ts"
click node_date_logic "https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/dates.ts"
click node_reminder_logic "https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/reminders.ts"
click node_autonomous "https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/autonomous-reminders.ts"
click node_cron "https://github.com/shibaji157/medimate-ai/blob/main/app/api/cron/reminders/route.ts"
click node_notifications "https://github.com/shibaji157/medimate-ai/blob/main/app/notifications/page.tsx"
click node_analytics "https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/analytics.ts"
click node_analytics_page "https://github.com/shibaji157/medimate-ai/blob/main/app/analytics/page.tsx"
click node_charts "https://github.com/shibaji157/medimate-ai/blob/main/components/AdherenceCharts.tsx"
click node_caregiver "https://github.com/shibaji157/medimate-ai/blob/main/app/caregiver/page.tsx"
click node_caregiver_adherence "https://github.com/shibaji157/medimate-ai/blob/main/lib/caregiver/adherence.ts"
click node_escalations "https://github.com/shibaji157/medimate-ai/blob/main/lib/caregiver/escalations.ts"
click node_companion "https://github.com/shibaji157/medimate-ai/blob/main/app/api/companion/route.ts"
click node_companion_context "https://github.com/shibaji157/medimate-ai/blob/main/lib/ai/companion-context.ts"
click node_companion_safety "https://github.com/shibaji157/medimate-ai/blob/main/lib/ai/companion-safety.ts"
click node_feedback "https://github.com/shibaji157/medimate-ai/blob/main/app/api/feedback/route.ts"
click node_settings "https://github.com/shibaji157/medimate-ai/blob/main/app/api/settings/route.ts"
click node_supabase_server "https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/server.ts"
click node_supabase_client "https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/client.ts"
click node_supabase_admin "https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/admin.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_ui,node_notifications toneBlue
class node_medication_api,node_dose_api,node_dose_logic,node_date_logic,node_reminder_logic,node_autonomous,node_cron,node_database toneAmber
class node_analytics,node_analytics_page,node_charts,node_caregiver,node_caregiver_adherence,node_escalations,node_companion,node_companion_context,node_companion_safety,node_feedback toneMint
class node_auth,node_settings,node_supabase_server,node_supabase_client,node_supabase_admin toneRose
class node_patient toneIndigo
```

## Components

### Patient Workflow

- [Dose dashboard](https://github.com/shibaji157/medimate-ai/blob/main/app/dashboard/page.tsx): `app/dashboard/page.tsx`
- [Medication management](https://github.com/shibaji157/medimate-ai/blob/main/app/medications/page.tsx): `app/medications/page.tsx`
- [Notification history](https://github.com/shibaji157/medimate-ai/blob/main/app/notifications/page.tsx): `app/notifications/page.tsx`

### Medication Operations

- [Medication and schedule API](https://github.com/shibaji157/medimate-ai/blob/main/app/api/medications/route.ts): `app/api/medications/route.ts`
- [Dose response API](https://github.com/shibaji157/medimate-ai/blob/main/app/api/doses/route.ts): `app/api/doses/route.ts`
- [Dose and missed-dose logic](https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/doses.ts): `lib/medication/doses.ts`
- [Schedule date handling](https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/dates.ts): `lib/medication/dates.ts`
- [Reminder synchronization](https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/reminders.ts): `lib/medication/reminders.ts`
- [Autonomous reminder engine](https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/autonomous-reminders.ts): `lib/medication/autonomous-reminders.ts`
- [Scheduled reminder job](https://github.com/shibaji157/medimate-ai/blob/main/app/api/cron/reminders/route.ts): `app/api/cron/reminders/route.ts`

### Support and Insights

- [Adherence analytics](https://github.com/shibaji157/medimate-ai/blob/main/lib/medication/analytics.ts): `lib/medication/analytics.ts`
- [Analytics view](https://github.com/shibaji157/medimate-ai/blob/main/app/analytics/page.tsx): `app/analytics/page.tsx`
- [Adherence charts](https://github.com/shibaji157/medimate-ai/blob/main/components/AdherenceCharts.tsx): `components/AdherenceCharts.tsx`
- [Caregiver portal](https://github.com/shibaji157/medimate-ai/blob/main/app/caregiver/page.tsx): `app/caregiver/page.tsx`
- [Patient adherence snapshots](https://github.com/shibaji157/medimate-ai/blob/main/lib/caregiver/adherence.ts): `lib/caregiver/adherence.ts`
- [Caregiver escalation](https://github.com/shibaji157/medimate-ai/blob/main/lib/caregiver/escalations.ts): `lib/caregiver/escalations.ts`
- [AI companion endpoint](https://github.com/shibaji157/medimate-ai/blob/main/app/api/companion/route.ts): `app/api/companion/route.ts`
- [Companion context](https://github.com/shibaji157/medimate-ai/blob/main/lib/ai/companion-context.ts): `lib/ai/companion-context.ts`
- [Companion safety checks](https://github.com/shibaji157/medimate-ai/blob/main/lib/ai/companion-safety.ts): `lib/ai/companion-safety.ts`
- [Feedback submission](https://github.com/shibaji157/medimate-ai/blob/main/app/api/feedback/route.ts): `app/api/feedback/route.ts`

### Application Platform

- [Sign in and signup](https://github.com/shibaji157/medimate-ai/blob/main/app/login/page.tsx): `app/login/page.tsx`
- [Profile and reminder settings](https://github.com/shibaji157/medimate-ai/blob/main/app/api/settings/route.ts): `app/api/settings/route.ts`
- [Server data client](https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/server.ts): `lib/supabase/server.ts`
- [Browser data client](https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/client.ts): `lib/supabase/client.ts`
- [Administrative data client](https://github.com/shibaji157/medimate-ai/blob/main/lib/supabase/admin.ts): `lib/supabase/admin.ts`

### Other components

- **Patient**
- **Supabase database and auth**

## Connections

- Patient → Sign in and signup: signs in (evidence: `README.md`)
- Patient → Dose dashboard: reviews doses (evidence: `README.md`)
- Patient → Medication management: manages medications (evidence: `README.md`)
- Medication management → Medication and schedule API: saves schedules
- Medication and schedule API → Server data client: creates client (evidence: `app/api/medications/route.ts`)
- Medication and schedule API → Supabase database and auth: writes medication and schedules (evidence: `app/api/medications/route.ts`)
- Dose dashboard → Server data client: creates client (evidence: `app/dashboard/page.tsx`)
- Dose dashboard → Dose and missed-dose logic: syncs missed doses (evidence: `app/dashboard/page.tsx`)
- Dose dashboard → Reminder synchronization: syncs reminders (evidence: `app/dashboard/page.tsx`)
- Dose dashboard → Schedule date handling: gets local date (evidence: `app/dashboard/page.tsx`)
- Dose and missed-dose logic → Supabase database and auth: reads dose records
- Patient → Dose response API: records taken or skipped (evidence: `README.md`)
- Dose response API → Server data client: creates client (evidence: `app/api/doses/route.ts`)
- Dose response API → Supabase database and auth: upserts dose event (evidence: `app/api/doses/route.ts`)
- Scheduled reminder job → Autonomous reminder engine: runs reminder engine (evidence: `app/api/cron/reminders/route.ts`)
- Autonomous reminder engine → Supabase database and auth: evaluates schedules
- Patient → Notification history: reviews notifications (evidence: `README.md`)
- Notification history → Dose and missed-dose logic: syncs missed doses (evidence: `app/notifications/page.tsx`)
- Notification history → Reminder synchronization: syncs reminders (evidence: `app/notifications/page.tsx`)
- Analytics view → Dose and missed-dose logic: syncs missed doses (evidence: `app/analytics/page.tsx`)
- Analytics view → Adherence analytics: loads seven-day analytics (evidence: `app/analytics/page.tsx`)
- Analytics view → Adherence charts: renders charts (evidence: `app/analytics/page.tsx`)
- Adherence analytics → Supabase database and auth: reads dose history
- Caregiver portal → Patient adherence snapshots: loads patient snapshots (evidence: `app/caregiver/page.tsx`)
- Caregiver portal → Administrative data client: reads relationships and profiles (evidence: `app/caregiver/page.tsx`)
- Caregiver portal → Caregiver escalation: reviews escalation history
- Caregiver escalation → Supabase database and auth: records authorized escalations
- Patient → AI companion endpoint: asks companion (evidence: `README.md`)
- AI companion endpoint → Companion safety checks: checks message safety (evidence: `app/api/companion/route.ts`)
- AI companion endpoint → Companion context: builds user context (evidence: `app/api/companion/route.ts`)
- AI companion endpoint → Server data client: creates client (evidence: `app/api/companion/route.ts`)
- Patient → Feedback submission: submits feedback (evidence: `README.md`)
- Feedback submission → Server data client: creates client (evidence: `app/api/feedback/route.ts`)
- Feedback submission → Supabase database and auth: inserts feedback (evidence: `app/api/feedback/route.ts`)
- Patient → Profile and reminder settings: updates preferences (evidence: `README.md`)
- Profile and reminder settings → Server data client: creates client (evidence: `app/api/settings/route.ts`)
- Profile and reminder settings → Supabase database and auth: updates profile (evidence: `app/api/settings/route.ts`)
- Sign in and signup → Browser data client: uses browser auth (evidence: `app/login/page.tsx`)
- Server data client → Supabase database and auth: connects server session (evidence: `lib/supabase/server.ts`)
