# mahmoodbamatraf/strokeaegis-ai-platform architecture

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

- Interactive diagram: https://gitdiagram.com/mahmoodbamatraf/strokeaegis-ai-platform
- Repository: https://github.com/mahmoodbamatraf/strokeaegis-ai-platform

## Overview

StrokeAegis is a clinical decision-support platform for clinicians and patients, combining patient risk scoring, safety-gated CT diagnosis, multi-agent clinical guidance, and reports. The principal workflow is coordinated by the clinical flow and exposed through pipeline management; separate API capabilities support accounts, care teams, assessment history, and chatbot consultations. Edges are limited to relationships documented in the README or visible in the supplied source index and excerpts; unsampled subsystem internals are not inferred.

Main entry points: [`backend/crew/flow.py`](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/flow.py) (Clinical flow), [`backend/app.py`](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/app.py) (Application API), [`backend/clinical/router.py`](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/clinical/router.py) (Clinical and care routes), [`backend/crew/llm.py`](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/llm.py) (Gemini LLM setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clinical["Clinical assessment"]
  node_risk["Stroke risk scoring<br/>[ml_engine.py]"]
  node_worker["Risk model worker<br/>[ml_worker.py]"]
  node_gate["CT safety gate<br/>[gate_engine.py]"]
  node_ct["Stroke CT classifier"]
  node_flow["Clinical flow<br/>[flow.py]"]
  node_state["Flow state<br/>[state.py]"]
  node_pdf["PDF report generator<br/>[pdf_generator.py]"]
end

subgraph group_agents["Agent guidance"]
  node_validation["Safety validation"]
  node_prevention["Prevention guidance"]
  node_emergency["Emergency support<br/>[emergency_agent.py]"]
  node_agentreport["Agent report synthesis<br/>[report_agent.py]"]
  node_schemas["Clinical schemas<br/>[schemas.py]"]
  node_llm["Gemini LLM setup<br/>[llm.py]"]
  node_ragtools["Guideline retrieval tools<br/>[tools.py]"]
  node_rag["Medical RAG adapter<br/>[rag_client.py]"]
  node_chatbot["Clinical chatbot<br/>[service.py]"]
end

subgraph group_platform["Application platform"]
  node_api["Application API<br/>[app.py]"]
  node_pipeline["Pipeline manager"]
  node_models["Clinical data models<br/>[models.py]"]
  node_database[("Database sessions<br/>[database.py]")]
  node_frontend["Web interface<br/>[app.js]"]
end

subgraph group_care["Care coordination"]
  node_auth["Authentication routes<br/>[router.py]"]
  node_security["Password and JWT security<br/>[security.py]"]
  node_authdeps["Authenticated-user dependencies<br/>[dependencies.py]"]
  node_clinicalroutes["Clinical and care routes<br/>[router.py]"]
end

node_clinician(("Clinician / patient"))
node_guidelines[("Guideline retrieval service")]
node_gemini["Google Gemini"]
node_store[("PostgreSQL database")]

node_clinician -.->|"uses"| node_frontend
node_frontend -.->|"requests"| node_api
node_api -->|"starts pipeline"| node_pipeline
node_pipeline -->|"constructs"| node_flow
node_flow -->|"scores risk"| node_risk
node_risk -->|"runs model"| node_worker
node_flow -->|"checks scan"| node_gate
node_flow -->|"classifies scan"| node_ct
node_flow -.->|"updates"| node_state
node_flow -->|"invokes"| node_validation
node_flow -->|"invokes"| node_prevention
node_flow -->|"invokes"| node_emergency
node_flow -->|"invokes"| node_agentreport
node_flow -->|"generates report"| node_pdf
node_validation -->|"uses schemas"| node_schemas
node_prevention -->|"uses schemas"| node_schemas
node_emergency -->|"uses schemas"| node_schemas
node_agentreport -->|"uses schemas"| node_schemas
node_validation -->|"uses model"| node_llm
node_prevention -->|"uses model"| node_llm
node_emergency -->|"uses model"| node_llm
node_agentreport -->|"uses model"| node_llm
node_llm -->|"configures"| node_gemini
node_prevention -->|"uses retrieval"| node_ragtools
node_emergency -->|"uses retrieval"| node_ragtools
node_ragtools -->|"queries"| node_rag
node_rag -->|"retrieves evidence"| node_guidelines
node_chatbot -->|"queries"| node_rag
node_api -->|"exposes consultation"| node_chatbot
node_api -->|"mounts routes"| node_clinicalroutes
node_api -->|"mounts routes"| node_auth
node_auth -->|"authenticates"| node_security
node_auth -->|"opens sessions"| node_database
node_auth -->|"queries models"| node_models
node_authdeps -->|"validates tokens"| node_security
node_authdeps -->|"opens sessions"| node_database
node_authdeps -->|"loads users"| node_models
node_clinicalroutes -->|"requires identity"| node_authdeps
node_clinicalroutes -->|"opens sessions"| node_database
node_clinicalroutes -->|"queries records"| node_models
node_clinicalroutes -->|"uses risk engine"| node_risk
node_clinicalroutes -->|"uses report generator"| node_pdf
node_database -->|"connects"| node_store
node_api -->|"configures engine"| node_risk
node_api -->|"configures engine"| node_gate
node_api -->|"configures engine"| node_ct

click node_api "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/app.py"
click node_risk "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/ml_engine.py"
click node_worker "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/ml_worker.py"
click node_gate "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/gate_engine.py"
click node_ct "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/stroke_cls_engine.py"
click node_flow "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/flow.py"
click node_pipeline "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/orchestration/pipeline_manager.py"
click node_state "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/state.py"
click node_validation "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/validation_agent.py"
click node_prevention "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/prevention_agent.py"
click node_emergency "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/emergency_agent.py"
click node_agentreport "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/report_agent.py"
click node_schemas "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/schemas.py"
click node_llm "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/llm.py"
click node_ragtools "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/rag/tools.py"
click node_rag "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/rag/rag_client.py"
click node_pdf "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/reports/pdf_generator.py"
click node_auth "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/auth/router.py"
click node_security "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/auth/security.py"
click node_authdeps "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/auth/dependencies.py"
click node_clinicalroutes "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/clinical/router.py"
click node_models "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/database/models.py"
click node_database "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/database/database.py"
click node_chatbot "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/chatbot/service.py"
click node_frontend "https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/frontend/app.js"

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_risk,node_worker,node_gate,node_ct,node_flow,node_state,node_pdf toneBlue
class node_validation,node_prevention,node_emergency,node_agentreport,node_schemas,node_llm,node_ragtools,node_rag,node_chatbot,node_guidelines,node_store toneAmber
class node_api,node_pipeline,node_models,node_database,node_frontend toneMint
class node_auth,node_security,node_authdeps,node_clinicalroutes toneRose
class node_clinician,node_gemini toneIndigo
```

## Components

### Clinical assessment

- [Stroke risk scoring](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/ml_engine.py): `backend/ml_engine.py`
- [Risk model worker](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/ml_worker.py): `backend/ml_worker.py`
- [CT safety gate](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/gate_engine.py): `backend/gate_engine.py`
- [Stroke CT classifier](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/stroke_cls_engine.py): `backend/stroke_cls_engine.py`
- [Clinical flow](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/flow.py): `backend/crew/flow.py`
- [Flow state](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/state.py): `backend/crew/state.py`
- [PDF report generator](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/reports/pdf_generator.py): `backend/reports/pdf_generator.py`

### Agent guidance

- [Safety validation](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/validation_agent.py): `backend/agents/validation_agent.py`
- [Prevention guidance](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/prevention_agent.py): `backend/agents/prevention_agent.py`
- [Emergency support](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/emergency_agent.py): `backend/agents/emergency_agent.py`
- [Agent report synthesis](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/report_agent.py): `backend/agents/report_agent.py`
- [Clinical schemas](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/agents/schemas.py): `backend/agents/schemas.py`
- [Gemini LLM setup](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/crew/llm.py): `backend/crew/llm.py`
- [Guideline retrieval tools](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/rag/tools.py): `backend/rag/tools.py`
- [Medical RAG adapter](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/rag/rag_client.py): `backend/rag/rag_client.py`
- [Clinical chatbot](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/chatbot/service.py): `backend/chatbot/service.py`

### Application platform

- [Application API](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/app.py): `backend/app.py`
- [Pipeline manager](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/orchestration/pipeline_manager.py): `backend/orchestration/pipeline_manager.py`
- [Clinical data models](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/database/models.py): `backend/database/models.py`
- [Database sessions](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/database/database.py): `backend/database/database.py`
- [Web interface](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/frontend/app.js): `frontend/app.js`

### Care coordination

- [Authentication routes](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/auth/router.py): `backend/auth/router.py`
- [Password and JWT security](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/auth/security.py): `backend/auth/security.py`
- [Authenticated-user dependencies](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/auth/dependencies.py): `backend/auth/dependencies.py`
- [Clinical and care routes](https://github.com/mahmoodbamatraf/strokeaegis-ai-platform/blob/main/backend/clinical/router.py): `backend/clinical/router.py`

### Other components

- **Clinician / patient**
- **Guideline retrieval service**
- **Google Gemini**
- **PostgreSQL database**

## Connections

- Clinician / patient → Web interface: uses
- Web interface → Application API: requests
- Application API → Pipeline manager: starts pipeline (evidence: `backend/app.py`)
- Pipeline manager → Clinical flow: constructs (evidence: `backend/orchestration/pipeline_manager.py`)
- Clinical flow → Stroke risk scoring: scores risk (evidence: `backend/crew/flow.py`)
- Stroke risk scoring → Risk model worker: runs model (evidence: `backend/ml_engine.py`)
- Clinical flow → CT safety gate: checks scan (evidence: `backend/crew/flow.py`)
- Clinical flow → Stroke CT classifier: classifies scan (evidence: `backend/crew/flow.py`)
- Clinical flow → Flow state: updates (evidence: `backend/crew/flow.py`)
- Clinical flow → Safety validation: invokes (evidence: `backend/crew/flow.py`)
- Clinical flow → Prevention guidance: invokes (evidence: `backend/crew/flow.py`)
- Clinical flow → Emergency support: invokes (evidence: `backend/crew/flow.py`)
- Clinical flow → Agent report synthesis: invokes (evidence: `backend/crew/flow.py`)
- Clinical flow → PDF report generator: generates report (evidence: `backend/crew/flow.py`)
- Safety validation → Clinical schemas: uses schemas (evidence: `backend/agents/validation_agent.py`)
- Prevention guidance → Clinical schemas: uses schemas (evidence: `backend/agents/prevention_agent.py`)
- Emergency support → Clinical schemas: uses schemas (evidence: `backend/agents/emergency_agent.py`)
- Agent report synthesis → Clinical schemas: uses schemas (evidence: `backend/agents/report_agent.py`)
- Safety validation → Gemini LLM setup: uses model (evidence: `backend/agents/validation_agent.py`)
- Prevention guidance → Gemini LLM setup: uses model (evidence: `backend/agents/prevention_agent.py`)
- Emergency support → Gemini LLM setup: uses model (evidence: `backend/agents/emergency_agent.py`)
- Agent report synthesis → Gemini LLM setup: uses model (evidence: `backend/agents/report_agent.py`)
- Gemini LLM setup → Google Gemini: configures (evidence: `backend/crew/llm.py`)
- Prevention guidance → Guideline retrieval tools: uses retrieval (evidence: `backend/agents/prevention_agent.py`)
- Emergency support → Guideline retrieval tools: uses retrieval (evidence: `backend/agents/emergency_agent.py`)
- Guideline retrieval tools → Medical RAG adapter: queries (evidence: `backend/rag/tools.py`)
- Medical RAG adapter → Guideline retrieval service: retrieves evidence (evidence: `backend/rag/rag_client.py`)
- Clinical chatbot → Medical RAG adapter: queries (evidence: `backend/chatbot/service.py`)
- Application API → Clinical chatbot: exposes consultation (evidence: `backend/app.py`)
- Application API → Clinical and care routes: mounts routes (evidence: `backend/app.py`)
- Application API → Authentication routes: mounts routes (evidence: `backend/app.py`)
- Authentication routes → Password and JWT security: authenticates (evidence: `backend/auth/router.py`)
- Authentication routes → Database sessions: opens sessions (evidence: `backend/auth/router.py`)
- Authentication routes → Clinical data models: queries models (evidence: `backend/auth/router.py`)
- Authenticated-user dependencies → Password and JWT security: validates tokens (evidence: `backend/auth/dependencies.py`)
- Authenticated-user dependencies → Database sessions: opens sessions (evidence: `backend/auth/dependencies.py`)
- Authenticated-user dependencies → Clinical data models: loads users (evidence: `backend/auth/dependencies.py`)
- Clinical and care routes → Authenticated-user dependencies: requires identity (evidence: `backend/clinical/router.py`)
- Clinical and care routes → Database sessions: opens sessions (evidence: `backend/clinical/router.py`)
- Clinical and care routes → Clinical data models: queries records (evidence: `backend/clinical/router.py`)
- Clinical and care routes → Stroke risk scoring: uses risk engine (evidence: `backend/clinical/router.py`)
- Clinical and care routes → PDF report generator: uses report generator (evidence: `backend/clinical/router.py`)
- Database sessions → PostgreSQL database: connects (evidence: `backend/database/database.py`)
- Application API → Stroke risk scoring: configures engine (evidence: `backend/app.py`)
- Application API → CT safety gate: configures engine (evidence: `backend/app.py`)
- Application API → Stroke CT classifier: configures engine (evidence: `backend/app.py`)
