# brook-sheet/med-reminder-web-app architecture

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

- Interactive diagram: https://gitdiagram.com/brook-sheet/med-reminder-web-app
- Repository: https://github.com/brook-sheet/med-reminder-web-app

## Overview

Rx Box is a medication-adherence product spanning patient and family web/mobile interfaces, a connected pillbox, and predictive risk awareness. The principal workflow configures medicines and schedules, receives device or manual medication events, records adherence, and presents history and monitoring information with reminders or selected risk notifications. The graph also preserves authentication, chat, food monitoring, and reporting capabilities documented or represented in the repository. Some subsystem wiring is inferred only from README descriptions; those relationships cite the README rather than unsampled implementation.

Main entry points: [`app/api/history/route.ts`](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/history/route.ts) (Medication history API), [`app/api/dashboard/route.ts`](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/dashboard/route.ts) (Dashboard API), [`app/api/auth/login/route.ts`](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/auth/login/route.ts) (Authentication API), [`app/api/medicines/route.ts`](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/medicines/route.ts) (Medicine API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and accounts"]
  node_authui["Account screens<br/>[page.tsx]"]
  node_authapi["Authentication API<br/>[route.ts]"]
  node_authlib["JWT authentication<br/>[auth.ts]"]
end

subgraph group_medication["Medication adherence"]
  node_medicineui["Medicine schedules<br/>[page.tsx]"]
  node_medicineapi["Medicine API<br/>[route.ts]"]
  node_deviceapi["Device event APIs<br/>[route.ts]"]
  node_verification["Medication verification"]
  node_historyapi["Medication history API<br/>[route.ts]"]
  node_historyui["History view<br/>[page.tsx]"]
end

subgraph group_monitor["Monitoring and insights"]
  node_adherence["Adherence engine<br/>[adherenceEngine.ts]"]
  node_dashboardapi["Dashboard API<br/>[route.ts]"]
  node_dashboardui["Patient dashboard<br/>[page.tsx]"]
  node_prediction["Risk prediction"]
  node_monitorui["Family monitoring<br/>[page.tsx]"]
  node_report["Medication reports<br/>[route.ts]"]
  node_food["Food monitoring<br/>[route.ts]"]
end

subgraph group_communication["Notifications and chat"]
  node_alertengine["Risk alert engine<br/>[alertEngine.ts]"]
  node_notification["Notification channels"]
  node_chatui["Family chat"]
  node_chatapi["Chat API<br/>[route.ts]"]
end

subgraph group_storage["Persistence and services"]
  node_database[("MongoDB Atlas")]
  node_userrecords["User records<br/>[User.ts]"]
  node_medicine_records["Medicine schedules<br/>[Medicine.ts]"]
  node_medlogs["Medication logs<br/>[MedicationLog.ts]"]
  node_monitorrecords["Monitoring requests"]
  node_notificationrecords["Notification records<br/>[Notification.ts]"]
end

node_patient(("Patient / family"))
node_device{{"ESP32 pillbox"}}

node_patient -->|"starts account"| node_authui
node_authui -.->|"submits credentials"| node_authapi
node_authapi -.->|"verifies identity"| node_authlib
node_patient -->|"sets schedule"| node_medicineui
node_medicineui -->|"manages medicines"| node_medicineapi
node_medicineapi -->|"reads and writes"| node_medicine_records
node_device -->|"sends events"| node_deviceapi
node_deviceapi -.->|"records activity"| node_verification
node_verification -.->|"updates outcomes"| node_medlogs
node_patient -->|"reviews history"| node_historyui
node_historyui -->|"requests records"| node_historyapi
node_historyapi -->|"finalizes events"| node_verification
node_historyapi -.->|"reads and writes"| node_medlogs
node_dashboardapi -->|"calculates adherence"| node_adherence
node_dashboardapi -.->|"reads outcomes"| node_medlogs
node_dashboardui -.->|"loads dashboard"| node_dashboardapi
node_adherence -.->|"provides behavior features"| node_prediction
node_prediction -.->|"identifies risk"| node_alertengine
node_patient -->|"views family status"| node_monitorui
node_monitorui -.->|"requests reports"| node_report
node_patient -->|"submits questionnaire"| node_food
node_alertengine -->|"dispatches alerts"| node_notification
node_notification -.->|"records delivery"| node_notificationrecords
node_patient -->|"communicates"| node_chatui
node_chatui -->|"uses chat API"| node_chatapi
node_chatapi -->|"sends push"| node_notification
node_chatapi -->|"checks monitoring link"| node_monitorrecords
node_medicineapi -->|"persists schedules"| node_database
node_historyapi -->|"connects database"| node_database
node_dashboardapi -->|"connects database"| node_database
node_authapi -.->|"uses account data"| node_userrecords

click node_authui "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(auth)/sign-in/page.tsx"
click node_authapi "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/auth/login/route.ts"
click node_authlib "https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/auth.ts"
click node_medicineui "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/medicines/page.tsx"
click node_medicineapi "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/medicines/route.ts"
click node_deviceapi "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/esp32/event/route.ts"
click node_verification "https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/medicationVerification.ts"
click node_historyapi "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/history/route.ts"
click node_historyui "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/history/page.tsx"
click node_adherence "https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/adherenceEngine.ts"
click node_dashboardapi "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/dashboard/route.ts"
click node_dashboardui "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/page.tsx"
click node_prediction "https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/prediction/adherencePrediction.ts"
click node_monitorui "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/monitor/%5BpatientID%5D/page.tsx"
click node_report "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/reports/medication/route.ts"
click node_food "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/food-monitoring/route.ts"
click node_alertengine "https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/alertEngine.ts"
click node_notification "https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/notificationChannels.ts"
click node_chatui "https://github.com/brook-sheet/med-reminder-web-app/blob/main/components/chats/ChatsPageClient.tsx"
click node_chatapi "https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/chats/route.ts"
click node_userrecords "https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/User.ts"
click node_medicine_records "https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/Medicine.ts"
click node_medlogs "https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/MedicationLog.ts"
click node_monitorrecords "https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/MonitoringRequest.ts"
click node_notificationrecords "https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/Notification.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_authui,node_authapi,node_authlib toneBlue
class node_medicineui,node_medicineapi,node_deviceapi,node_verification,node_historyapi,node_historyui toneAmber
class node_adherence,node_dashboardapi,node_dashboardui,node_prediction,node_monitorui,node_report,node_food toneMint
class node_alertengine,node_notification,node_chatui,node_chatapi toneRose
class node_database,node_userrecords,node_medicine_records,node_medlogs,node_monitorrecords,node_notificationrecords,node_patient,node_device toneIndigo
```

## Components

### Access and accounts

- [Account screens](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(auth)/sign-in/page.tsx): `app/(auth)/sign-in/page.tsx`
- [Authentication API](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/auth/login/route.ts): `app/api/auth/login/route.ts`
- [JWT authentication](https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/auth.ts): `lib/auth.ts`

### Medication adherence

- [Medicine schedules](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/medicines/page.tsx): `app/(main)/medicines/page.tsx`
- [Medicine API](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/medicines/route.ts): `app/api/medicines/route.ts`
- [Device event APIs](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/esp32/event/route.ts): `app/api/esp32/event/route.ts`
- [Medication verification](https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/medicationVerification.ts): `lib/medicationVerification.ts`
- [Medication history API](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/history/route.ts): `app/api/history/route.ts`
- [History view](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/history/page.tsx): `app/(main)/history/page.tsx`

### Monitoring and insights

- [Adherence engine](https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/adherenceEngine.ts): `lib/adherenceEngine.ts`
- [Dashboard API](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/dashboard/route.ts): `app/api/dashboard/route.ts`
- [Patient dashboard](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/page.tsx): `app/(main)/page.tsx`
- [Risk prediction](https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/prediction/adherencePrediction.ts): `lib/prediction/adherencePrediction.ts`
- [Family monitoring](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/(main)/monitor/%5BpatientID%5D/page.tsx): `app/(main)/monitor/[patientID]/page.tsx`
- [Medication reports](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/reports/medication/route.ts): `app/api/reports/medication/route.ts`
- [Food monitoring](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/food-monitoring/route.ts): `app/api/food-monitoring/route.ts`

### Notifications and chat

- [Risk alert engine](https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/alertEngine.ts): `lib/alertEngine.ts`
- [Notification channels](https://github.com/brook-sheet/med-reminder-web-app/blob/main/lib/notificationChannels.ts): `lib/notificationChannels.ts`
- [Family chat](https://github.com/brook-sheet/med-reminder-web-app/blob/main/components/chats/ChatsPageClient.tsx): `components/chats/ChatsPageClient.tsx`
- [Chat API](https://github.com/brook-sheet/med-reminder-web-app/blob/main/app/api/chats/route.ts): `app/api/chats/route.ts`

### Persistence and services

- **MongoDB Atlas**
- [User records](https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/User.ts): `models/User.ts`
- [Medicine schedules](https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/Medicine.ts): `models/Medicine.ts`
- [Medication logs](https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/MedicationLog.ts): `models/MedicationLog.ts`
- [Monitoring requests](https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/MonitoringRequest.ts): `models/MonitoringRequest.ts`
- [Notification records](https://github.com/brook-sheet/med-reminder-web-app/blob/main/models/Notification.ts): `models/Notification.ts`

### Other components

- **Patient / family**
- **ESP32 pillbox**

## Connections

- Patient / family → Account screens: starts account (evidence: `README.md`)
- Account screens → Authentication API: submits credentials
- Authentication API → JWT authentication: verifies identity
- Patient / family → Medicine schedules: sets schedule (evidence: `README.md`)
- Medicine schedules → Medicine API: manages medicines (evidence: `app/(main)/medicines/page.tsx`)
- Medicine API → Medicine schedules: reads and writes (evidence: `app/api/medicines/route.ts`)
- ESP32 pillbox → Device event APIs: sends events (evidence: `README.md`)
- Device event APIs → Medication verification: records activity
- Medication verification → Medication logs: updates outcomes (evidence: `lib/medicationVerification.ts`)
- Patient / family → History view: reviews history (evidence: `README.md`)
- History view → Medication history API: requests records (evidence: `app/(main)/history/page.tsx`)
- Medication history API → Medication verification: finalizes events (evidence: `app/api/history/route.ts`)
- Medication history API → Medication logs: reads and writes (evidence: `app/api/history/route.ts`)
- Dashboard API → Adherence engine: calculates adherence (evidence: `app/api/dashboard/route.ts`)
- Dashboard API → Medication logs: reads outcomes (evidence: `app/api/dashboard/route.ts`)
- Patient dashboard → Dashboard API: loads dashboard
- Adherence engine → Risk prediction: provides behavior features
- Risk prediction → Risk alert engine: identifies risk (evidence: `README.md`)
- Patient / family → Family monitoring: views family status (evidence: `README.md`)
- Family monitoring → Medication reports: requests reports
- Patient / family → Food monitoring: submits questionnaire (evidence: `README.md`)
- Risk alert engine → Notification channels: dispatches alerts (evidence: `lib/alertEngine.ts`)
- Notification channels → Notification records: records delivery
- Patient / family → Family chat: communicates (evidence: `README.md`)
- Family chat → Chat API: uses chat API (evidence: `components/chats/ChatsPageClient.tsx`)
- Chat API → Notification channels: sends push (evidence: `app/api/chats/route.ts`)
- Chat API → Monitoring requests: checks monitoring link (evidence: `app/api/chats/route.ts`)
- Medicine API → MongoDB Atlas: persists schedules
- Medication history API → MongoDB Atlas: connects database (evidence: `app/api/history/route.ts`)
- Dashboard API → MongoDB Atlas: connects database (evidence: `app/api/dashboard/route.ts`)
- Authentication API → User records: uses account data
