# shewaks/glucosafe architecture

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

- Interactive diagram: https://gitdiagram.com/shewaks/glucosafe
- Repository: https://github.com/shewaks/glucosafe

## Overview

GlucoSafe is a diabetes-management platform for patients and guardians: users sign in, then record and review glucose-related data, assess hypoglycemia risk, use food and meal tools, or monitor linked patients. The React client calls a FastAPI backend that exposes authentication, telemetry, prediction, food, guardian, and chat capabilities backed by MongoDB and ML services. The tree also contains a separate `backend/app` implementation; its sampled database uses SQLite, unlike the README-documented MongoDB backend. Some feature-to-service wiring is therefore left unspecified.

Main entry points: [`backend/main.py`](https://github.com/shewaks/glucosafe/blob/main/backend/main.py) (FastAPI entry), [`frontend/src/services/api.js`](https://github.com/shewaks/glucosafe/blob/main/frontend/src/services/api.js) (API client), [`backend/database/connection.py`](https://github.com/shewaks/glucosafe/blob/main/backend/database/connection.py) (Database access), [`backend/routes/auth.py`](https://github.com/shewaks/glucosafe/blob/main/backend/routes/auth.py) (Authentication routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_web["React application<br/>[App.jsx]"]
  node_session["Session state<br/>[AuthContext.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_patient_views["Patient views<br/>[Dashboard.jsx]"]
  node_food_view["Food recognition"]
  node_history_view["History and support<br/>[History.jsx]"]
  node_guardian_views["Guardian portal<br/>[GuardianPortal.jsx]"]
end

subgraph group_api["Unified API"]
  node_api_entry["FastAPI entry<br/>[main.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_patient_routes["Patient telemetry<br/>[patient.py]"]
  node_guardian_routes["Guardian monitoring<br/>[guardian.py]"]
  node_predict_routes["Risk assessment<br/>[predict.py]"]
  node_food_routes["Food endpoints<br/>[food.py]"]
  node_hypo_routes["Real-time hypo risk<br/>[hypo_risk.py]"]
  node_chat_routes["Chat endpoint<br/>[chat.py]"]
  node_chat_service["Chat assistant<br/>[chat_service.py]"]
end

subgraph group_health["Patient health features"]
  node_hypo_service["Hypoglycemia model"]
  node_food_service["Food ML and bolus<br/>[food_ml_service.py]"]
end

subgraph group_platform["Identity and persistence"]
  node_auth_guard["Auth guards<br/>[dependencies.py]"]
  node_token_security["Token security<br/>[security.py]"]
  node_mongo[("MongoDB")]
  node_mongo_access["Database access<br/>[connection.py]"]
end

subgraph group_alternate["Alternate app implementation"]
  node_alternate_entry["Alternate FastAPI app<br/>[main.py]"]
  node_sqlite_access[("SQLite database<br/>[database.py]")]
  node_alternate_config["Alternate app config<br/>[config.py]"]
end

node_patient(("Patient"))
node_guardian(("Guardian"))

node_patient -->|"uses"| node_web
node_guardian -->|"uses"| node_web
node_web -->|"provides session"| node_session
node_session -->|"authenticates through"| node_api_client
node_patient_views -->|"requests data"| node_api_client
node_food_view -->|"requests food analysis"| node_api_client
node_history_view -->|"requests history"| node_api_client
node_guardian_views -.->|"requests monitoring"| node_api_client
node_api_client -->|"calls auth endpoints"| node_auth_routes
node_api_client -->|"calls patient endpoints"| node_patient_routes
node_api_client -->|"calls guardian endpoints"| node_guardian_routes
node_api_client -->|"calls food endpoints"| node_food_routes
node_api_entry -->|"registers router"| node_auth_routes
node_api_entry -->|"registers router"| node_patient_routes
node_api_entry -->|"registers router"| node_guardian_routes
node_api_entry -->|"registers router"| node_predict_routes
node_api_entry -->|"registers router"| node_food_routes
node_api_entry -->|"registers router"| node_hypo_routes
node_api_entry -->|"registers router"| node_chat_routes
node_chat_routes -->|"delegates to"| node_chat_service
node_auth_routes -->|"authenticates with"| node_auth_guard
node_auth_guard -->|"verifies tokens"| node_token_security
node_auth_guard -->|"loads users"| node_mongo_access
node_auth_routes -->|"reads and writes users"| node_mongo_access
node_patient_routes -->|"reads and writes telemetry"| node_mongo_access
node_guardian_routes -->|"reads patient data"| node_mongo_access
node_food_routes -->|"searches foods"| node_mongo_access
node_api_entry -->|"initializes database"| node_mongo_access
node_mongo_access -->|"persists data"| node_mongo
node_api_entry -->|"loads model service"| node_hypo_service
node_api_entry -->|"loads model service"| node_food_service
node_predict_routes -.->|"uses for prediction"| node_hypo_service
node_food_routes -.->|"uses for food analysis"| node_food_service
node_hypo_routes -.->|"uses for risk forecast"| node_food_service
node_api_entry -.->|"separate implementation"| node_alternate_entry
node_alternate_entry -->|"uses database"| node_sqlite_access
node_alternate_entry -->|"loads configuration"| node_alternate_config
node_sqlite_access -->|"uses project path"| node_alternate_config

click node_web "https://github.com/shewaks/glucosafe/blob/main/frontend/src/App.jsx"
click node_session "https://github.com/shewaks/glucosafe/blob/main/frontend/src/context/AuthContext.jsx"
click node_api_client "https://github.com/shewaks/glucosafe/blob/main/frontend/src/services/api.js"
click node_patient_views "https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/Dashboard.jsx"
click node_food_view "https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/FoodRecognition.jsx"
click node_history_view "https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/History.jsx"
click node_guardian_views "https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/GuardianPortal.jsx"
click node_api_entry "https://github.com/shewaks/glucosafe/blob/main/backend/main.py"
click node_auth_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/auth.py"
click node_patient_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/patient.py"
click node_guardian_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/guardian.py"
click node_predict_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/predict.py"
click node_food_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/food.py"
click node_hypo_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/hypo_risk.py"
click node_chat_routes "https://github.com/shewaks/glucosafe/blob/main/backend/routes/chat.py"
click node_chat_service "https://github.com/shewaks/glucosafe/blob/main/backend/services/chat_service.py"
click node_hypo_service "https://github.com/shewaks/glucosafe/blob/main/backend/services/hypoglycemia_service.py"
click node_food_service "https://github.com/shewaks/glucosafe/blob/main/backend/services/food_ml_service.py"
click node_auth_guard "https://github.com/shewaks/glucosafe/blob/main/backend/auth/dependencies.py"
click node_token_security "https://github.com/shewaks/glucosafe/blob/main/backend/auth/security.py"
click node_mongo_access "https://github.com/shewaks/glucosafe/blob/main/backend/database/connection.py"
click node_alternate_entry "https://github.com/shewaks/glucosafe/blob/main/backend/app/main.py"
click node_sqlite_access "https://github.com/shewaks/glucosafe/blob/main/backend/app/database.py"
click node_alternate_config "https://github.com/shewaks/glucosafe/blob/main/backend/app/config.py"

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_web,node_session,node_api_client,node_patient_views,node_food_view,node_history_view,node_guardian_views toneBlue
class node_api_entry,node_auth_routes,node_patient_routes,node_guardian_routes,node_predict_routes,node_food_routes,node_hypo_routes,node_chat_routes,node_chat_service toneAmber
class node_hypo_service,node_food_service toneMint
class node_auth_guard,node_token_security,node_mongo,node_mongo_access toneRose
class node_alternate_entry,node_sqlite_access,node_alternate_config,node_patient,node_guardian toneIndigo
```

## Components

### Web application

- [React application](https://github.com/shewaks/glucosafe/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Session state](https://github.com/shewaks/glucosafe/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [API client](https://github.com/shewaks/glucosafe/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`
- [Patient views](https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Food recognition](https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/FoodRecognition.jsx): `frontend/src/pages/FoodRecognition.jsx`
- [History and support](https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/History.jsx): `frontend/src/pages/History.jsx`
- [Guardian portal](https://github.com/shewaks/glucosafe/blob/main/frontend/src/pages/GuardianPortal.jsx): `frontend/src/pages/GuardianPortal.jsx`

### Unified API

- [FastAPI entry](https://github.com/shewaks/glucosafe/blob/main/backend/main.py): `backend/main.py`
- [Authentication routes](https://github.com/shewaks/glucosafe/blob/main/backend/routes/auth.py): `backend/routes/auth.py`
- [Patient telemetry](https://github.com/shewaks/glucosafe/blob/main/backend/routes/patient.py): `backend/routes/patient.py`
- [Guardian monitoring](https://github.com/shewaks/glucosafe/blob/main/backend/routes/guardian.py): `backend/routes/guardian.py`
- [Risk assessment](https://github.com/shewaks/glucosafe/blob/main/backend/routes/predict.py): `backend/routes/predict.py`
- [Food endpoints](https://github.com/shewaks/glucosafe/blob/main/backend/routes/food.py): `backend/routes/food.py`
- [Real-time hypo risk](https://github.com/shewaks/glucosafe/blob/main/backend/routes/hypo_risk.py): `backend/routes/hypo_risk.py`
- [Chat endpoint](https://github.com/shewaks/glucosafe/blob/main/backend/routes/chat.py): `backend/routes/chat.py`
- [Chat assistant](https://github.com/shewaks/glucosafe/blob/main/backend/services/chat_service.py): `backend/services/chat_service.py`

### Patient health features

- [Hypoglycemia model](https://github.com/shewaks/glucosafe/blob/main/backend/services/hypoglycemia_service.py): `backend/services/hypoglycemia_service.py`
- [Food ML and bolus](https://github.com/shewaks/glucosafe/blob/main/backend/services/food_ml_service.py): `backend/services/food_ml_service.py`

### Identity and persistence

- [Auth guards](https://github.com/shewaks/glucosafe/blob/main/backend/auth/dependencies.py): `backend/auth/dependencies.py`
- [Token security](https://github.com/shewaks/glucosafe/blob/main/backend/auth/security.py): `backend/auth/security.py`
- **MongoDB**
- [Database access](https://github.com/shewaks/glucosafe/blob/main/backend/database/connection.py): `backend/database/connection.py`

### Alternate app implementation

- [Alternate FastAPI app](https://github.com/shewaks/glucosafe/blob/main/backend/app/main.py): `backend/app/main.py`
- [SQLite database](https://github.com/shewaks/glucosafe/blob/main/backend/app/database.py): `backend/app/database.py`
- [Alternate app config](https://github.com/shewaks/glucosafe/blob/main/backend/app/config.py): `backend/app/config.py`

### Other components

- **Patient**
- **Guardian**

## Connections

- Patient → React application: uses (evidence: `frontend/src/App.jsx`)
- Guardian → React application: uses (evidence: `frontend/src/App.jsx`)
- React application → Session state: provides session (evidence: `frontend/src/App.jsx`)
- Session state → API client: authenticates through (evidence: `frontend/src/context/AuthContext.jsx`)
- Patient views → API client: requests data (evidence: `frontend/src/pages/Dashboard.jsx`)
- Food recognition → API client: requests food analysis (evidence: `frontend/src/pages/FoodRecognition.jsx`)
- History and support → API client: requests history (evidence: `frontend/src/pages/History.jsx`)
- Guardian portal → API client: requests monitoring
- API client → Authentication routes: calls auth endpoints (evidence: `frontend/src/services/api.js`)
- API client → Patient telemetry: calls patient endpoints (evidence: `frontend/src/services/api.js`)
- API client → Guardian monitoring: calls guardian endpoints (evidence: `frontend/src/services/api.js`)
- API client → Food endpoints: calls food endpoints (evidence: `frontend/src/services/api.js`)
- FastAPI entry → Authentication routes: registers router (evidence: `backend/main.py`)
- FastAPI entry → Patient telemetry: registers router (evidence: `backend/main.py`)
- FastAPI entry → Guardian monitoring: registers router (evidence: `backend/main.py`)
- FastAPI entry → Risk assessment: registers router (evidence: `backend/main.py`)
- FastAPI entry → Food endpoints: registers router (evidence: `backend/main.py`)
- FastAPI entry → Real-time hypo risk: registers router (evidence: `backend/main.py`)
- FastAPI entry → Chat endpoint: registers router (evidence: `backend/main.py`)
- Chat endpoint → Chat assistant: delegates to (evidence: `backend/routes/chat.py`)
- Authentication routes → Auth guards: authenticates with (evidence: `backend/routes/auth.py`)
- Auth guards → Token security: verifies tokens (evidence: `backend/auth/dependencies.py`)
- Auth guards → Database access: loads users (evidence: `backend/auth/dependencies.py`)
- Authentication routes → Database access: reads and writes users (evidence: `backend/routes/auth.py`)
- Patient telemetry → Database access: reads and writes telemetry (evidence: `backend/routes/patient.py`)
- Guardian monitoring → Database access: reads patient data (evidence: `backend/routes/guardian.py`)
- Food endpoints → Database access: searches foods (evidence: `backend/routes/food.py`)
- FastAPI entry → Database access: initializes database (evidence: `backend/main.py`)
- Database access → MongoDB: persists data (evidence: `backend/database/connection.py`)
- FastAPI entry → Hypoglycemia model: loads model service (evidence: `backend/main.py`)
- FastAPI entry → Food ML and bolus: loads model service (evidence: `backend/main.py`)
- Risk assessment → Hypoglycemia model: uses for prediction
- Food endpoints → Food ML and bolus: uses for food analysis
- Real-time hypo risk → Food ML and bolus: uses for risk forecast
- FastAPI entry → Alternate FastAPI app: separate implementation
- Alternate FastAPI app → SQLite database: uses database (evidence: `backend/app/main.py`)
- Alternate FastAPI app → Alternate app config: loads configuration (evidence: `backend/app/main.py`)
- SQLite database → Alternate app config: uses project path (evidence: `backend/app/database.py`)
