# amit2900-ydv/medreminder architecture

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

- Interactive diagram: https://gitdiagram.com/amit2900-ydv/medreminder
- Repository: https://github.com/amit2900-ydv/medreminder

## Overview

1. **Overall shape**
   - MedReminder is a **hybrid mobile/web app**: a React + TypeScript frontend built with Vite, wrapped for Android with **Capacitor**, and backed by a separate **Node.js/Express API** with **MongoDB/Mongoose** persistence.
   - The architecture is split into three main boundaries: **client UI**, **backend services**, and **database / external AI services**.

2. **Frontend application shell**
   - The user-facing app lives in `src/`, with `src/main.tsx` bootstrapping `src/app/App.tsx`.
   - `src/app/components/` contains the actual product screens: dashboard, login, caregiver/caretaker views, medication scheduling, reports, logs, scanner, settings, notifications, and AI assistant screens.
   - The app is designed as a **single-page experience** with screen-based navigation rather than separate pages.

3. **Shared UI and state management**
   - Reusable UI primitives are centralized under `src/app/components/ui/` and appear to be a component library layer used across screens.
   - Global state is split by concern using React context: `AuthContext`, `PatientContext`, and `LanguageContext`.
   - This suggests the app keeps authentication, selected patient data, and localization/voice language separate from individual screens.

4. **Client-to-server data flow**
   - Frontend API access is abstracted through `src/services/api.ts`, which is the main bridge from UI to backend.
   - Screens such as medication management, patient linking, logs, reports, and AI features likely call this API layer instead of talking to the backend directly.
   - `mockData.ts` indicates there is also local fallback/sample data for development or demo flows.

5. **Backend service boundary**
   - The backend is a standalone Express app in `backend/`, with `backend/server.js` as the entry point.
   - Routes are separated by domain: `auth`, `patients`, `caretakers`, `medications`, `logs`, and `ai`.
   - This is a classic resource-oriented API structure, with each route module owning one part of the domain.

6. **Persistence model**
   - MongoDB is accessed through Mongoose models in `backend/models/`: `User`, `Patient`, and `Caretaker`.
   - A `db.js`/`config/db.js` pair indicates centralized database connection setup.
   - The data model implies the system tracks users plus role-specific entities and relationships between patients and caretakers.

7. **Security and access control**
   - `backend/middleware/auth.js` is the main protection boundary for secured API routes.
   - The presence of login-related frontend screens plus an auth backend route indicates token/session-based access is likely used to gate patient, caretaker, and medication operations.
   - Role separation is important to the architecture: the UI includes both patient-facing and caretaker-facing screens.

8. **AI subsystem**
   - The `backend/routes/ai.js` endpoint is the dedicated server-side integration point for AI features.
   - The README says the AI assistant uses **Google Gemini**, so the backend likely acts as the broker between the UI and Gemini rather than exposing the AI key to the client.
   - AI-related frontend components include chatbot, AI dashboard, assistant screen, and floating orb entry points.

9. **Medication reminders, notifications, and scheduling**
   - Notification functionality is mostly client-side, with dedicated components for permission, scheduling, bell UI, sound, and medication notifications.
   - The repo includes `public/service-worker.js` and `src/app/utils/serviceWorkerUtils.ts`, so reminder delivery likely uses a **service worker / PWA-style notification layer** in addition to in-app UI.
   - This subsystem is separate from core CRUD data; it turns medication schedule data into alerts and reminder interactions.

10. **Role-specific user journeys**
   - The frontend clearly supports at least two personas: **patient/caregiver** and **caretaker**.
   - Caretaker-specific screens include dashboard, patients, reports, and settings, while patient-oriented screens include home, schedule, scan, logs, reports, notifications, and medication management.
   - `LinkPatientModal` suggests a caretaker can be associated with one or more patients, which is a key domain relationship in the system.

11. **Analytics and adherence reporting**
   - Reports and dashboard screens consume medication event data to compute adherence, missed doses, and taken/missed ratios.
   - The README defines adherence as `(Taken Medicines / Total Scheduled Medicines) × 100`, so the backend/frontend likely share this domain logic for summaries and charts.
   - `backend/routes/logs.js` is likely the source of truth for dose events used in analytics.

12. **Android packaging layer**
   - The `android/` directory is a Capacitor-generated native shell for Android, with `MainActivity.java`, manifest, resources, and Gradle config.
   - This layer is not the core business logic; it packages the web app into a native mobile container and enables access to mobile capabilities through Capacitor.
   - The architecture diagram should treat Android as the **deployment/runtime wrapper** around the frontend, not as a separate product backend.

13. **Development and support assets**
   - `seed.js`, `.env.example`, and test scripts (`test-login.*`, `test_chat.js`) indicate the backend has local bootstrap/testing helpers.
   - `guidelines/Guidelines.md`, `NOTIFICATION_GUIDE.md`, and `ATTRIBUTIONS.md` are support docs rather than runtime components.
   - `public/manifest.json` and service-worker assets suggest the app also has PWA-style deployment concerns alongside the Android shell.

Main entry points: [`src/app/App.tsx`](https://github.com/amit2900-ydv/medreminder/blob/main/src/app/App.tsx) (App shell), [`backend/server.js`](https://github.com/amit2900-ydv/medreminder/blob/main/backend/server.js) (API server), [`src/app/components`](https://github.com/amit2900-ydv/medreminder/tree/main/src/app/components) (Screens), [`src/services/api.ts`](https://github.com/amit2900-ydv/medreminder/blob/main/src/services/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client app"]
  node_main["Entry point<br/>Vite bootstrap<br/>[main.tsx]"]
  node_app["App shell<br/>SPA root<br/>[App.tsx]"]
  node_screens["Screens<br/>feature UI"]
  node_ui["UI kit<br/>shared components"]
  node_contexts["App state<br/>React context"]
  node_api["API client<br/>HTTP bridge<br/>[api.ts]"]
  node_mock["Mock data<br/>fallback data<br/>[mockData.ts]"]
  node_notif["Reminders<br/>notification layer"]
  node_aiui["AI features<br/>assistant UI"]
  node_service_worker["Service worker<br/>pwa runtime<br/>[service-worker.js]"]
end

subgraph group_backend["Backend API"]
  node_backend_entry["API server<br/>Express entry<br/>[server.js]"]
  node_auth_route["Auth route<br/>api route<br/>[auth.js]"]
  node_domain_routes["Domain routes<br/>api routes<br/>[patients.js]"]
  node_auth_mw["Auth middleware<br/>guard<br/>[auth.js]"]
  node_models["Data models<br/>Mongoose models"]
  node_db["Database config<br/>MongoDB setup<br/>[db.js]"]
  node_ai_route["AI broker<br/>ai route<br/>[ai.js]"]
end

subgraph group_mobile["Android shell"]
  node_android_main["MainActivity<br/>Android shell<br/>[MainActivity.java]"]
  node_manifest["Android manifest<br/>native config"]
end

node_main -->|"boots"| node_app
node_app -->|"renders"| node_screens
node_app -->|"uses"| node_ui
node_app -->|"reads state"| node_contexts
node_screens -->|"calls"| node_api
node_screens -->|"triggers"| node_notif
node_screens -->|"opens"| node_aiui
node_api -->|"requests"| node_backend_entry
node_api -.->|"fallback"| node_mock
node_backend_entry -->|"mounts"| node_auth_route
node_backend_entry -->|"mounts"| node_domain_routes
node_backend_entry -->|"mounts"| node_ai_route
node_domain_routes -->|"protects"| node_auth_mw
node_domain_routes -->|"uses"| node_models
node_models -->|"connects"| node_db
node_ai_route -.->|"served by"| node_backend_entry
node_notif -->|"registers"| node_service_worker
node_android_main -->|"configured by"| node_manifest
node_android_main -->|"wraps"| node_app

click node_main "https://github.com/amit2900-ydv/medreminder/blob/main/src/main.tsx"
click node_app "https://github.com/amit2900-ydv/medreminder/blob/main/src/app/App.tsx"
click node_screens "https://github.com/amit2900-ydv/medreminder/tree/main/src/app/components"
click node_ui "https://github.com/amit2900-ydv/medreminder/tree/main/src/app/components/ui"
click node_contexts "https://github.com/amit2900-ydv/medreminder/tree/main/src/app/context"
click node_api "https://github.com/amit2900-ydv/medreminder/blob/main/src/services/api.ts"
click node_mock "https://github.com/amit2900-ydv/medreminder/blob/main/src/app/data/mockData.ts"
click node_notif "https://github.com/amit2900-ydv/medreminder/blob/main/src/app/components/NotificationScheduler.tsx"
click node_aiui "https://github.com/amit2900-ydv/medreminder/blob/main/src/app/components/AIAssistantScreen.tsx"
click node_backend_entry "https://github.com/amit2900-ydv/medreminder/blob/main/backend/server.js"
click node_auth_route "https://github.com/amit2900-ydv/medreminder/blob/main/backend/routes/auth.js"
click node_domain_routes "https://github.com/amit2900-ydv/medreminder/blob/main/backend/routes/patients.js"
click node_auth_mw "https://github.com/amit2900-ydv/medreminder/blob/main/backend/middleware/auth.js"
click node_models "https://github.com/amit2900-ydv/medreminder/tree/main/backend/models"
click node_db "https://github.com/amit2900-ydv/medreminder/blob/main/backend/config/db.js"
click node_ai_route "https://github.com/amit2900-ydv/medreminder/blob/main/backend/routes/ai.js"
click node_android_main "https://github.com/amit2900-ydv/medreminder/blob/main/android/app/src/main/java/com/adherai/app/MainActivity.java"
click node_manifest "https://github.com/amit2900-ydv/medreminder/blob/main/android/app/src/main/AndroidManifest.xml"
click node_service_worker "https://github.com/amit2900-ydv/medreminder/blob/main/public/service-worker.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_main,node_app,node_screens,node_ui,node_contexts,node_api,node_mock,node_notif,node_aiui,node_service_worker toneBlue
class node_backend_entry,node_auth_route,node_domain_routes,node_auth_mw,node_models,node_db,node_ai_route toneAmber
class node_android_main,node_manifest toneMint
```

## Components

### Client app

React + TypeScript SPA inside the mobile/web shell

- [Entry point](https://github.com/amit2900-ydv/medreminder/blob/main/src/main.tsx): Vite bootstrap · Bootstraps the React app · `src/main.tsx`
- [App shell](https://github.com/amit2900-ydv/medreminder/blob/main/src/app/App.tsx): SPA root · Top-level application router and shell · `src/app/App.tsx`
- [Screens](https://github.com/amit2900-ydv/medreminder/tree/main/src/app/components): feature UI · Primary patient and caretaker screens · `src/app/components`
- [UI kit](https://github.com/amit2900-ydv/medreminder/tree/main/src/app/components/ui): shared components · Reusable visual primitives used across screens · `src/app/components/ui`
- [App state](https://github.com/amit2900-ydv/medreminder/tree/main/src/app/context): React context · Auth, patient selection, and language state · `src/app/context`
- [API client](https://github.com/amit2900-ydv/medreminder/blob/main/src/services/api.ts): HTTP bridge · Frontend bridge to backend endpoints · `src/services/api.ts`
- [Mock data](https://github.com/amit2900-ydv/medreminder/blob/main/src/app/data/mockData.ts): fallback data · Local sample data for dev or demo flows · `src/app/data/mockData.ts`
- [Reminders](https://github.com/amit2900-ydv/medreminder/blob/main/src/app/components/NotificationScheduler.tsx): notification layer · Notification UI, scheduling, sounds, and service-worker hooks · `src/app/components/NotificationScheduler.tsx`
- [AI features](https://github.com/amit2900-ydv/medreminder/blob/main/src/app/components/AIAssistantScreen.tsx): assistant UI · Chatbot, dashboard, and assistant screens for AI workflows · `src/app/components/AIAssistantScreen.tsx`
- [Service worker](https://github.com/amit2900-ydv/medreminder/blob/main/public/service-worker.js): pwa runtime · Client-side background worker for reminder delivery · `public/service-worker.js`

### Backend API

Express service, data models, and protected domain routes

- [API server](https://github.com/amit2900-ydv/medreminder/blob/main/backend/server.js): Express entry · Starts the Node.js backend · `backend/server.js`
- [Auth route](https://github.com/amit2900-ydv/medreminder/blob/main/backend/routes/auth.js): api route · Login and authentication endpoints · `backend/routes/auth.js`
- [Domain routes](https://github.com/amit2900-ydv/medreminder/blob/main/backend/routes/patients.js): api routes · Patients, caretakers, medications, logs, and AI endpoints · `backend/routes/patients.js`
- [Auth middleware](https://github.com/amit2900-ydv/medreminder/blob/main/backend/middleware/auth.js): guard · Protects secured backend routes · `backend/middleware/auth.js`
- [Data models](https://github.com/amit2900-ydv/medreminder/tree/main/backend/models): Mongoose models · User, patient, and caretaker schemas · `backend/models`
- [Database config](https://github.com/amit2900-ydv/medreminder/blob/main/backend/config/db.js): MongoDB setup · Central MongoDB connection configuration · `backend/config/db.js`
- [AI broker](https://github.com/amit2900-ydv/medreminder/blob/main/backend/routes/ai.js): ai route · Server-side integration point for Gemini-backed features · `backend/routes/ai.js`

### Android shell

Capacitor-generated Android wrapper around the web app

- [MainActivity](https://github.com/amit2900-ydv/medreminder/blob/main/android/app/src/main/java/com/adherai/app/MainActivity.java): Android shell · Native host activity for the Capacitor app · `android/app/src/main/java/com/adherai/app/MainActivity.java`
- [Android manifest](https://github.com/amit2900-ydv/medreminder/blob/main/android/app/src/main/AndroidManifest.xml): native config · Android app configuration and permissions · `android/app/src/main/AndroidManifest.xml`

## Connections

- Entry point → App shell: boots · Application entry mounts the SPA shell
- App shell → Screens: renders · Shell coordinates the screen-based user experience
- App shell → UI kit: uses · Screens compose shared UI primitives
- App shell → App state: reads state · Global concerns are provided through React context
- Screens → API client: calls · Feature screens fetch and mutate data through the API layer
- Screens → Reminders: triggers · Medication and reminder screens drive notifications
- Screens → AI features: opens · AI screens and entry points surface assistant workflows
- API client → API server: requests · Frontend HTTP calls target the Express backend
- API client → Mock data: fallback · Local sample data supports development or demo flows
- API server → Auth route: mounts · Server exposes authentication endpoints
- API server → Domain routes: mounts · Server exposes resource-oriented domain routes
- API server → AI broker: mounts · Server exposes the AI integration endpoint
- Domain routes → Auth middleware: protects · Secured routes are guarded by auth middleware
- Domain routes → Data models: uses · Domain handlers read and write Mongoose models
- Data models → Database config: connects · Models persist through the shared MongoDB connection
- AI broker → API server: served by · AI integration is part of the backend API surface
- Reminders → Service worker: registers · Reminder delivery uses the PWA background worker
- MainActivity → Android manifest: configured by · Native host is defined by Android app configuration
- MainActivity → App shell: wraps · Capacitor embeds the web app inside Android
