How amit2900-ydv/medreminder works
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: App.tsx App shell · server.js API server · components Screens · api.ts API client
Components 19
Client app
React + TypeScript SPA inside the mobile/web shell
- Entry point · Bootstraps the React app
src/main.tsx - App shell · Top-level application router and shell
src/app/App.tsx - Screens · Primary patient and caretaker screens
src/app/components - UI kit · Reusable visual primitives used across screens
src/app/components/ui - App state · Auth, patient selection, and language state
src/app/context - API client · Frontend bridge to backend endpoints
src/services/api.ts - Mock data · Local sample data for dev or demo flows
src/app/data/mockData.ts - Reminders · Notification UI, scheduling, sounds, and service-worker hooks
src/app/components/NotificationScheduler.tsx - AI features · Chatbot, dashboard, and assistant screens for AI workflows
src/app/components/AIAssistantScreen.tsx - Service worker · Client-side background worker for reminder delivery
public/service-worker.js
Backend API
Express service, data models, and protected domain routes
- API server · Starts the Node.js backend
backend/server.js - Auth route · Login and authentication endpoints
backend/routes/auth.js - Domain routes · Patients, caretakers, medications, logs, and AI endpoints
backend/routes/patients.js - Auth middleware · Protects secured backend routes
backend/middleware/auth.js - Data models · User, patient, and caretaker schemas
backend/models - Database config · Central MongoDB connection configuration
backend/config/db.js - AI broker · Server-side integration point for Gemini-backed features
backend/routes/ai.js
Android shell
Capacitor-generated Android wrapper around the web app
- MainActivity · Native host activity for the Capacitor app
android/app/src/main/java/com/adherai/app/MainActivity.java - Android manifest · Android app configuration and permissions
android/app/src/main/AndroidManifest.xml
Connections 19
- 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