# mohamedelsayedelbadwy/cliniq-ai-service architecture

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

- Interactive diagram: https://gitdiagram.com/mohamedelsayedelbadwy/cliniq-ai-service
- Repository: https://github.com/mohamedelsayedelbadwy/cliniq-ai-service

## Overview

ClinIQ AI Service is a FastAPI backend with two user-facing capabilities: turn-based Voice Call and Brain MRI image classification. The voice workflow records browser audio, submits a turn with conversation history, runs Groq transcription, response generation, and speech synthesis, then returns text and audio for playback. The MRI workflow accepts an image upload, checks predictor availability, preprocesses the image, and returns model-class probabilities. The graph reflects the sampled implementation and documented endpoints; it does not include the separate class-mapping verification utility or the README’s future RAG idea.

Main entry points: [`voice/service.py`](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/service.py) (Voice turn service), [`mri/service.py`](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/service.py) (MRI predictor), [`main.py`](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/main.py) (FastAPI app), [`voice/router.py`](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/router.py) (Voice endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hosting["Service hosting"]
  node_fastapi_app["FastAPI app<br/>[main.py]"]
end

subgraph group_web["Voice interface"]
  node_voice_ui["Voice Call UI<br/>[app.js]"]
end

subgraph group_voice["Voice pipeline"]
  node_voice_api["Voice endpoint<br/>[router.py]"]
  node_voice_schema["Voice response<br/>[schemas.py]"]
  node_voice_service["Voice turn service<br/>[service.py]"]
  node_voice_config["Groq settings<br/>[config.py]"]
end

subgraph group_mri["MRI classification"]
  node_mri_api["MRI endpoints<br/>[router.py]"]
  node_mri_schema["MRI responses<br/>[schemas.py]"]
  node_mri_service["MRI predictor<br/>[service.py]"]
  node_mri_config["MRI settings<br/>[config.py]"]
  node_mri_weights["MRI model weights"]
  node_class_mapping["Class mapping<br/>[class_names.json]"]
end

node_browser_user(("Browser user"))
node_groq_stt["Groq transcription"]
node_groq_llm["Groq language model"]
node_groq_tts["Groq speech synthesis"]

node_fastapi_app -->|"mounts routes"| node_voice_api
node_fastapi_app -->|"mounts routes"| node_mri_api
node_fastapi_app -->|"initializes predictor"| node_mri_service
node_fastapi_app -->|"serves interface"| node_voice_ui
node_browser_user -.->|"uses"| node_voice_ui
node_voice_ui -->|"posts audio turn"| node_voice_api
node_voice_api -->|"processes turn"| node_voice_service
node_voice_api -->|"returns response"| node_voice_schema
node_voice_service -->|"loads settings"| node_voice_config
node_voice_service -->|"transcribes audio"| node_groq_stt
node_voice_service -->|"generates reply"| node_groq_llm
node_voice_service -->|"synthesizes speech"| node_groq_tts
node_browser_user -.->|"uploads scan"| node_mri_api
node_mri_api -->|"requests prediction"| node_mri_service
node_mri_api -->|"returns response"| node_mri_schema
node_mri_service -->|"finds artifacts"| node_mri_config
node_mri_service -.->|"loads model"| node_mri_weights
node_mri_service -.->|"loads labels"| node_class_mapping

click node_fastapi_app "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/main.py"
click node_voice_api "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/router.py"
click node_voice_schema "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/schemas.py"
click node_voice_service "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/service.py"
click node_voice_config "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/config.py"
click node_voice_ui "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/web/app.js"
click node_mri_api "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/router.py"
click node_mri_schema "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/schemas.py"
click node_mri_service "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/service.py"
click node_mri_config "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/config.py"
click node_mri_weights "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/models/mri_xception_selective_finetuning_best.keras"
click node_class_mapping "https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/models/class_names.json"

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_fastapi_app,node_browser_user toneBlue
class node_voice_ui toneAmber
class node_voice_api,node_voice_schema,node_voice_service,node_voice_config toneMint
class node_mri_api,node_mri_schema,node_mri_service,node_mri_config,node_mri_weights,node_class_mapping toneRose
class node_groq_stt,node_groq_llm,node_groq_tts toneIndigo
```

## Components

### Service hosting

- [FastAPI app](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/main.py): `main.py`

### Voice interface

- [Voice Call UI](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/web/app.js): `web/app.js`

### Voice pipeline

- [Voice endpoint](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/router.py): `voice/router.py`
- [Voice response](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/schemas.py): `voice/schemas.py`
- [Voice turn service](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/service.py): `voice/service.py`
- [Groq settings](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/voice/config.py): `voice/config.py`

### MRI classification

- [MRI endpoints](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/router.py): `mri/router.py`
- [MRI responses](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/schemas.py): `mri/schemas.py`
- [MRI predictor](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/service.py): `mri/service.py`
- [MRI settings](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/mri/config.py): `mri/config.py`
- [MRI model weights](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/models/mri_xception_selective_finetuning_best.keras): `models/mri_xception_selective_finetuning_best.keras`
- [Class mapping](https://github.com/mohamedelsayedelbadwy/cliniq-ai-service/blob/main/models/class_names.json): `models/class_names.json`

### Other components

- **Browser user**
- **Groq transcription**
- **Groq language model**
- **Groq speech synthesis**

## Connections

- FastAPI app → Voice endpoint: mounts routes (evidence: `main.py`)
- FastAPI app → MRI endpoints: mounts routes (evidence: `main.py`)
- FastAPI app → MRI predictor: initializes predictor (evidence: `main.py`)
- FastAPI app → Voice Call UI: serves interface (evidence: `main.py`)
- Browser user → Voice Call UI: uses
- Voice Call UI → Voice endpoint: posts audio turn (evidence: `web/app.js`)
- Voice endpoint → Voice turn service: processes turn (evidence: `voice/router.py`)
- Voice endpoint → Voice response: returns response (evidence: `voice/router.py`)
- Voice turn service → Groq settings: loads settings (evidence: `voice/service.py`)
- Voice turn service → Groq transcription: transcribes audio (evidence: `voice/service.py`)
- Voice turn service → Groq language model: generates reply (evidence: `voice/service.py`)
- Voice turn service → Groq speech synthesis: synthesizes speech (evidence: `voice/service.py`)
- Browser user → MRI endpoints: uploads scan
- MRI endpoints → MRI predictor: requests prediction (evidence: `mri/router.py`)
- MRI endpoints → MRI responses: returns response (evidence: `mri/router.py`)
- MRI predictor → MRI settings: finds artifacts (evidence: `mri/service.py`)
- MRI predictor → MRI model weights: loads model
- MRI predictor → Class mapping: loads labels
