Full-stack intelligent care monitoring prototype built for role-based review of activity patterns.
This repository currently includes:
- FastAPI backend with live in-memory IoT activity simulation
- Rule-based anomaly detection and alert management workflow
- Optional Gemini-generated explanations with safe fallback responses
- React + Vite frontend dashboard for caregiver, supervisor, and family views
- Backend service starts with a FastAPI lifespan hook and automatically starts the simulator.
- Activity events are generated continuously with scenario changes (
normal routine,inactivity,irregular behavior). - Anomaly engine detects:
- prolonged inactivity
- activity pattern deviation (drop/spike)
- activity variability
- missing routine event
- Alerts are generated, listed, and actioned (
approve/reject). - Supervisor demo alert can be seeded from API/UI.
- AI explanation pipeline works in both modes:
- live Gemini mode when enabled and configured
- deterministic fallback mode when disabled/unavailable
- Frontend dashboard consumes backend APIs for activity, status, alerts, and insight.
- Role-aware behavior is implemented (
caregiver,supervisor,family).
backend/app/db/*, many files inbackend/app/models/*, and several files inbackend/app/schemas/*are present but mostly empty scaffolds.backend/app/pipelines/pipeline.pyandbackend/app/utils/helpers.pyare placeholders.docker/Dockerfileanddocker/docker-compose.ymlare present but currently empty.- Frontend sidebar includes links for
/alerts,/activity,/settings, but only/is fully implemented. - Frontend API base URL is hardcoded in components (
http://127.0.0.1:8000).
backend/main.pyexposes app frombackend/app/main.py.- On startup, FastAPI lifespan starts the simulator and logs Gemini status.
- Simulator writes synthetic activity events into an in-memory rolling window.
alert_service.pypulls recent events and runs anomaly detection (anamoly.py).- Alerts and explanation payloads are assembled (Gemini live or fallback).
- Frontend polls/selectively fetches backend endpoints and renders role-based views.
backend/app/main.py: FastAPI app setup, CORS, lifespan startup/shutdown.backend/app/api/router.py: active API routes used by frontend.backend/app/services/simulator.py: event generator and simulator control.backend/app/services/behaviour.py: expected activity profiles by time of day.backend/app/services/anamoly.py: anomaly detection logic (note filename typo kept as-is in code).backend/app/services/alert_service.py: alert composition, dashboard response, action state.backend/app/services/gemini_client.py: Gemini integration, prompting, parsing, fallback handling, status.backend/app/models/schemas.py: small set of active Pydantic models.backend/app/schemas/iot.py: IoT schema model.
frontend/src/pages/Index.tsx: main dashboard composition and status polling.frontend/src/components/dashboard/ActivityChart.tsx: chart from/activitydata.frontend/src/components/dashboard/AlertsPanel.tsx: alert list + approve/reject + demo seed.frontend/src/components/dashboard/AIExplanation.tsx: insight card from/insight.frontend/src/components/dashboard/StatusSummary.tsx: top-level state summary.frontend/src/components/dashboard/ActivityTimeline.tsx: static timeline visualization.frontend/src/components/dashboard/FamilyView.tsx: simplified family-facing view.frontend/src/components/layout/*: app shell, sidebar, navbar.frontend/src/contexts/RoleContext.tsx: role state and role switcher context.
backend/
main.py # entrypoint importing app.main:app
app/
main.py # FastAPI app + lifespan + CORS
api/
router.py # active routes
alerts.py # scaffold (empty)
ingestion.py # scaffold (empty)
services/
simulator.py # synthetic IoT event stream
behaviour.py # expected behavior windows
anamoly.py # anomaly detection rules
alert_service.py # alert/dashboard composition
gemini_client.py # Gemini + fallback explanation layer
processing.py # scaffold (empty)
db/ # scaffold (empty files)
models/ # mostly scaffold; schemas.py has active models
schemas/ # mostly scaffold; iot.py active
pipelines/ # scaffold (empty)
utils/ # scaffold (empty)
frontend/
src/
pages/
Index.tsx # implemented dashboard route
NotFound.tsx # fallback route
components/
dashboard/ # dashboard widgets and cards
layout/ # sidebar/navbar/layout shell
ui/ # UI primitives used by app
contexts/RoleContext.tsx # role switching context
hooks/ # helper hooks
lib/utils.ts # className merge helper
test/ # Vitest setup + basic example test
vite.config.ts # Vite dev server config (port 8080)
vitest.config.ts # test configuration
docker/
Dockerfile # placeholder (empty)
docker-compose.yml # placeholder (empty)
GET /activity?role=caregiver|supervisor|familyGET /alerts?role=caregiver|supervisor|familyGET /insight?role=caregiver|supervisor|familyGET /dashboard?role=caregiver|supervisor|familyPOST /alerts/action- body:
{ "alert_id": <int>, "action": "approve" | "reject" }
- body:
POST /alerts/demo/seed?role=supervisorPOST /simulate/startPOST /simulate/stopGET /simulate/statusGET /gemini/status
Create .env at repository root for Gemini mode:
GEMINI_ENABLED=true
GEMINI_API_KEY=your_key_here
GEMINI_MODEL=gemini-2.5-flash
GEMINI_TIMEOUT_SECONDS=6If GEMINI_ENABLED=false, explanations are served from fallback logic.
From repository root:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000Backend: http://127.0.0.1:8000
In a second terminal:
cd frontend
npm install
npm run devFrontend: http://localhost:8080
Many areas are intentionally simplified or scaffolded for this demo prototype.
This is currently a demo build for the proposal. Active development is in progress.