How lokesh848-code/elder_guard works
Purpose and Entry Points
ElderGuard AI is a multi-role elder-care platform: elder, caregiver, doctor, hospital, and pharmacy portals share healthcare records and operational workflows. The React/Vite client starts at frontend/src/main.jsx and routes through frontend/src/App.jsx. FastAPI starts from backend/app/main.py, exposing HTTP APIs plus elder-scoped WebSockets.
Client Application and Role Portals
The frontend maintains authentication and notification state, then presents role-specific dashboards and workflows. API service modules form the boundary to backend endpoints; hooks encapsulate connected/realtime data use.
• frontend/src/context/AuthContext.jsx
• frontend/src/components/layout/DashboardLayout.jsx
• frontend/src/pages/elder/ElderDashboard.jsx
• frontend/src/pages/caregiver/CaregiverDashboard.jsx
• frontend/src/services/api.js
Identity, Profiles, and Access Boundary
Authentication, role/profile management, and elder–caregiver links establish authorization. Connected records are owned by elder_id; caregiver reads and writes must be constrained by active caregiver links, while pending or view-only links do not grant equivalent access.
• backend/app/auth/routes.py
• backend/app/profiles/routes.py
• backend/app/profiles/links.py
• backend/supabase/migrations/013_connected_portals.sql
Connected Care Data and Realtime Fan-out
The connected subsystem is the cross-portal synchronization layer for medicines, vitals, check-ins, appointments, SOS, messages, notifications, and audit history. Backend mutations persist shared records, then publish named events to the elder:{elderId} WebSocket room; clients invalidate/refetch relevant cached data.
• backend/app/connected/routes.py
• backend/app/connected/realtime.py
• backend/app/connected/storage.py
• frontend/src/hooks/useConnectedPortal.js
Clinical Workflows
Appointments, medicine reminders, vitals, and emergency SOS are domain services with route/model/schema layers. Scheduler and queue modules imply time- or dispatch-oriented work beyond request handling. Emergency delivery is server-side: SOS persistence, linked-caregiver notification timing, notifications, and realtime broadcast.
• backend/app/appointments/service.py
• backend/app/appointments/queue.py
• backend/app/medicines/service.py
• backend/app/vitals/scheduler.py
• backend/app/emergency/service.py
Notifications and External Delivery
Notifications are modeled and dispatched centrally, with in-app, Firebase Cloud Messaging push, and Telegram channel adapters. These channels are downstream effects of care events rather than the source of authorization or record ownership.
• backend/app/notifications/service.py
• backend/app/notifications/channels/in_app.py
• backend/app/notifications/channels/push_fcm.py
• backend/app/notifications/channels/telegram.py
Persistence, Infrastructure, and Extended Services
The backend supports local SQLite fallback and PostgreSQL/Supabase migrations; database and security configuration are centralized in core. Docker Compose supports the full stack. Additional bounded domains include AI companion, OCR, reports/analytics, community events, doctor records, and hospital operations.
• backend/app/core/database.py
• backend/app/core/config.py
• backend/supabase/migrations/001_initial_schema.sql
• backend/supabase/combined_migrations.sql
• docker-compose.yml
Components 22
React Client
- Vite entry & routes · Starts the client and selects portal routes.
frontend/src/main.jsx - Auth state
frontend/src/context/AuthContext.jsx - Role dashboard shell
frontend/src/components/layout/DashboardLayout.jsx - Elder portal
frontend/src/pages/elder/ElderDashboard.jsx - Caregiver portal
frontend/src/pages/caregiver/CaregiverDashboard.jsx - API client
frontend/src/services/api.js - Connected portal hook · Refetches connected data after elder-room events.
frontend/src/hooks/useConnectedPortal.js
Identity & Access
- Authentication
backend/app/auth/routes.py - Profiles & roles
backend/app/profiles/routes.py - Caregiver access links · Active links determine caregiver access to elder-owned records.
backend/app/profiles/links.py
Connected Care
- FastAPI application
backend/app/main.py - Connected care API · Handles cross-portal medicines, vitals, check-ins, appointments, SOS, and messages.
backend/app/connected/routes.py - Connected record storage · Shared records are scoped by elder_id.
backend/app/connected/storage.py - Elder WebSocket rooms · Publishes named events to elder:{elderId} rooms.
backend/app/connected/realtime.py - Clinical workflows · Appointments, medicines, vitals scheduling, and SOS delivery run beyond route handling.
backend/app/emergency/service.py
Notifications
- Notification dispatcher · Turns care events into in-app and external deliveries.
backend/app/notifications/service.py - In-app notifications
backend/app/notifications/channels/in_app.py - FCM push
backend/app/notifications/channels/push_fcm.py - Telegram
backend/app/notifications/channels/telegram.py
Platform Data
- Database layer · Supports local SQLite fallback and PostgreSQL/Supabase.
backend/app/core/database.py - Supabase schema · Defines connected-portal data and access schema.
backend/supabase/migrations/013_connected_portals.sql - Full-stack deployment
docker-compose.yml
Connections 24
- Vite entry & routes → Auth state: initializes
- Vite entry & routes → Role dashboard shell: routes to
- Role dashboard shell → Elder portal: hosts
- Role dashboard shell → Caregiver portal: hosts
- Elder portal → API client: uses
- Caregiver portal → API client: uses
- API client → FastAPI application: HTTP / WebSocket
- FastAPI application → Authentication: mounts
- FastAPI application → Profiles & roles: mounts
- FastAPI application → Connected care API: mounts
- Profiles & roles → Caregiver access links: manages
- Caregiver access links → Connected care API: authorizes caregiver access
- Connected care API → Connected record storage: persists shared records
- Connected care API → Clinical workflows: invokes workflows
- Connected care API → Elder WebSocket rooms: publishes mutations
- Clinical workflows → Notification dispatcher: emits care events
- Notification dispatcher → In-app notifications: delivers
- Notification dispatcher → FCM push: delivers
- Notification dispatcher → Telegram: delivers
- Elder WebSocket rooms → Connected portal hook: elder room events
- Connected portal hook → API client: invalidates and refetches
- Connected record storage → Database layer: reads and writes
- Supabase schema → Database layer: defines schema
- Full-stack deployment → FastAPI application: runs