# bob299-bob/aihealth_services architecture

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

- Interactive diagram: https://gitdiagram.com/bob299-bob/aihealth_services
- Repository: https://github.com/bob299-bob/aihealth_services

## Overview

This is a FastAPI AI healthcare API. A user reaches registered endpoints through the application, with capabilities for account access, heart-disease prediction, X-ray analysis, healthcare chat, and PDF question answering. The sampled code shows endpoint-owned processing, SQLite-backed accounts, in-memory document indexes, and Groq-backed responses. The README is empty; some model and preprocessing modules are indexed but unsampled, so their internal behavior and connections are not inferred beyond indexed references.

Main entry points: [`main.py`](https://github.com/bob299-bob/aihealth_services/blob/main/main.py) (FastAPI application), [`routers/auth_router.py`](https://github.com/bob299-bob/aihealth_services/blob/main/routers/auth_router.py) (Account endpoints), [`routers/chat_router.py`](https://github.com/bob299-bob/aihealth_services/blob/main/routers/chat_router.py) (Healthcare chat), [`routers/rag.py`](https://github.com/bob299-bob/aihealth_services/blob/main/routers/rag.py) (PDF question endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["FastAPI application<br/>[main.py]"]
  node_auth_routes["Account endpoints<br/>[auth_router.py]"]
  node_auth["Token and password auth<br/>[auth.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_clinical["Clinical analysis"]
  node_ml_routes["Heart prediction endpoint<br/>[ml_router.py]"]
  node_heart_model["Heart disease model<br/>[modelDP.py]"]
  node_heart_prep["Heart data preprocessing<br/>[preprocessing.py]"]
  node_image_routes["X-ray analysis endpoint<br/>[image_router.py]"]
  node_model_loader["X-ray model loader<br/>[model_loader.py]"]
end

subgraph group_assistant["AI assistants"]
  node_chat_routes["Healthcare chat<br/>[chat_router.py]"]
  node_rag_routes["PDF question endpoints<br/>[rag.py]"]
  node_doc_brain["Document retrieval and answers<br/>[docBrain.py]"]
end

subgraph group_storage["Account storage"]
  node_database[("SQLite database<br/>[database.py]")]
  node_user_model["Account record model<br/>[models.py]"]
end

subgraph group_vision["Vision model preparation"]
  node_mri_model["MRI CNN model<br/>[modelMRI.py]"]
  node_mri_prep["MRI CNN preprocessing"]
  node_xray_model["X-ray CNN model<br/>[modelXray.py]"]
  node_xray_prep["X-ray CNN preprocessing"]
end

node_user(("API user"))
node_groq["Groq API"]

node_user -->|"calls API"| node_app
node_app -->|"registers routes"| node_auth_routes
node_app -->|"registers routes"| node_ml_routes
node_app -->|"registers routes"| node_image_routes
node_app -->|"registers routes"| node_chat_routes
node_app -->|"registers routes"| node_rag_routes
node_app -->|"creates tables"| node_database
node_app -->|"loads metadata"| node_user_model
node_auth_routes -->|"queries and writes"| node_database
node_auth_routes -->|"queries and creates"| node_user_model
node_auth_routes -->|"uses auth functions"| node_auth
node_auth_routes -->|"validates requests"| node_schemas
node_ml_routes -->|"validates input"| node_schemas
node_image_routes -->|"loads model"| node_model_loader
node_chat_routes -->|"checks token"| node_auth
node_chat_routes -->|"validates request"| node_schemas
node_chat_routes -->|"requests completion"| node_groq
node_rag_routes -->|"checks token"| node_auth
node_rag_routes -->|"validates question"| node_schemas
node_rag_routes -->|"processes and answers"| node_doc_brain
node_doc_brain -->|"requests completion"| node_groq
node_mri_model -->|"references preprocessing"| node_mri_prep
node_xray_model -->|"references preprocessing"| node_mri_prep
node_heart_model -->|"references preprocessing"| node_heart_prep

click node_app "https://github.com/bob299-bob/aihealth_services/blob/main/main.py"
click node_auth_routes "https://github.com/bob299-bob/aihealth_services/blob/main/routers/auth_router.py"
click node_auth "https://github.com/bob299-bob/aihealth_services/blob/main/auth.py"
click node_schemas "https://github.com/bob299-bob/aihealth_services/blob/main/schemas.py"
click node_ml_routes "https://github.com/bob299-bob/aihealth_services/blob/main/routers/ml_router.py"
click node_heart_model "https://github.com/bob299-bob/aihealth_services/blob/main/Services/ML/DiseasePrediction/modelDP.py"
click node_heart_prep "https://github.com/bob299-bob/aihealth_services/blob/main/Services/ML/DiseasePrediction/preprocessing.py"
click node_image_routes "https://github.com/bob299-bob/aihealth_services/blob/main/routers/image_router.py"
click node_model_loader "https://github.com/bob299-bob/aihealth_services/blob/main/Services/model_loader.py"
click node_chat_routes "https://github.com/bob299-bob/aihealth_services/blob/main/routers/chat_router.py"
click node_rag_routes "https://github.com/bob299-bob/aihealth_services/blob/main/routers/rag.py"
click node_doc_brain "https://github.com/bob299-bob/aihealth_services/blob/main/Services/docBrain.py"
click node_database "https://github.com/bob299-bob/aihealth_services/blob/main/database.py"
click node_user_model "https://github.com/bob299-bob/aihealth_services/blob/main/models.py"
click node_mri_model "https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/MRI%20Analysis/modelMRI.py"
click node_mri_prep "https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/MRI%20Analysis/preprocessingCNN.py"
click node_xray_model "https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/X-RayAnalysis/modelXray.py"
click node_xray_prep "https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/X-RayAnalysis/preprocessingCNN.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_app,node_auth_routes,node_auth,node_schemas,node_user toneBlue
class node_ml_routes,node_heart_model,node_heart_prep,node_image_routes,node_model_loader toneAmber
class node_chat_routes,node_rag_routes,node_doc_brain,node_groq toneMint
class node_database,node_user_model toneRose
class node_mri_model,node_mri_prep,node_xray_model,node_xray_prep toneIndigo
```

## Components

### API and access

- [FastAPI application](https://github.com/bob299-bob/aihealth_services/blob/main/main.py): `main.py`
- [Account endpoints](https://github.com/bob299-bob/aihealth_services/blob/main/routers/auth_router.py): `routers/auth_router.py`
- [Token and password auth](https://github.com/bob299-bob/aihealth_services/blob/main/auth.py): `auth.py`
- [Request schemas](https://github.com/bob299-bob/aihealth_services/blob/main/schemas.py): `schemas.py`

### Clinical analysis

- [Heart prediction endpoint](https://github.com/bob299-bob/aihealth_services/blob/main/routers/ml_router.py): `routers/ml_router.py`
- [Heart disease model](https://github.com/bob299-bob/aihealth_services/blob/main/Services/ML/DiseasePrediction/modelDP.py): `Services/ML/DiseasePrediction/modelDP.py`
- [Heart data preprocessing](https://github.com/bob299-bob/aihealth_services/blob/main/Services/ML/DiseasePrediction/preprocessing.py): `Services/ML/DiseasePrediction/preprocessing.py`
- [X-ray analysis endpoint](https://github.com/bob299-bob/aihealth_services/blob/main/routers/image_router.py): `routers/image_router.py`
- [X-ray model loader](https://github.com/bob299-bob/aihealth_services/blob/main/Services/model_loader.py): `Services/model_loader.py`

### AI assistants

- [Healthcare chat](https://github.com/bob299-bob/aihealth_services/blob/main/routers/chat_router.py): `routers/chat_router.py`
- [PDF question endpoints](https://github.com/bob299-bob/aihealth_services/blob/main/routers/rag.py): `routers/rag.py`
- [Document retrieval and answers](https://github.com/bob299-bob/aihealth_services/blob/main/Services/docBrain.py): `Services/docBrain.py`

### Account storage

- [SQLite database](https://github.com/bob299-bob/aihealth_services/blob/main/database.py): `database.py`
- [Account record model](https://github.com/bob299-bob/aihealth_services/blob/main/models.py): `models.py`

### Vision model preparation

- [MRI CNN model](https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/MRI%20Analysis/modelMRI.py): `Services/CNN/MRI Analysis/modelMRI.py`
- [MRI CNN preprocessing](https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/MRI%20Analysis/preprocessingCNN.py): `Services/CNN/MRI Analysis/preprocessingCNN.py`
- [X-ray CNN model](https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/X-RayAnalysis/modelXray.py): `Services/CNN/X-RayAnalysis/modelXray.py`
- [X-ray CNN preprocessing](https://github.com/bob299-bob/aihealth_services/blob/main/Services/CNN/X-RayAnalysis/preprocessingCNN.py): `Services/CNN/X-RayAnalysis/preprocessingCNN.py`

### Other components

- **API user**
- **Groq API**

## Connections

- API user → FastAPI application: calls API (evidence: `main.py`)
- FastAPI application → Account endpoints: registers routes (evidence: `main.py`)
- FastAPI application → Heart prediction endpoint: registers routes (evidence: `main.py`)
- FastAPI application → X-ray analysis endpoint: registers routes (evidence: `main.py`)
- FastAPI application → Healthcare chat: registers routes (evidence: `main.py`)
- FastAPI application → PDF question endpoints: registers routes (evidence: `main.py`)
- FastAPI application → SQLite database: creates tables (evidence: `main.py`)
- FastAPI application → Account record model: loads metadata (evidence: `main.py`)
- Account endpoints → SQLite database: queries and writes (evidence: `routers/auth_router.py`)
- Account endpoints → Account record model: queries and creates (evidence: `routers/auth_router.py`)
- Account endpoints → Token and password auth: uses auth functions (evidence: `routers/auth_router.py`)
- Account endpoints → Request schemas: validates requests (evidence: `routers/auth_router.py`)
- Heart prediction endpoint → Request schemas: validates input (evidence: `routers/ml_router.py`)
- X-ray analysis endpoint → X-ray model loader: loads model (evidence: `routers/image_router.py`)
- Healthcare chat → Token and password auth: checks token (evidence: `routers/chat_router.py`)
- Healthcare chat → Request schemas: validates request (evidence: `routers/chat_router.py`)
- Healthcare chat → Groq API: requests completion (evidence: `routers/chat_router.py`)
- PDF question endpoints → Token and password auth: checks token (evidence: `routers/rag.py`)
- PDF question endpoints → Request schemas: validates question (evidence: `routers/rag.py`)
- PDF question endpoints → Document retrieval and answers: processes and answers (evidence: `routers/rag.py`)
- Document retrieval and answers → Groq API: requests completion (evidence: `Services/docBrain.py`)
- MRI CNN model → MRI CNN preprocessing: references preprocessing (evidence: `Services/CNN/MRI Analysis/modelMRI.py`)
- X-ray CNN model → MRI CNN preprocessing: references preprocessing (evidence: `Services/CNN/X-RayAnalysis/modelXray.py`)
- Heart disease model → Heart data preprocessing: references preprocessing (evidence: `Services/ML/DiseasePrediction/modelDP.py`)
