# prashik-54/mediguardai architecture

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

- Interactive diagram: https://gitdiagram.com/prashik-54/mediguardai
- Repository: https://github.com/prashik-54/mediguardai

## Overview

MediGuard AI is a hospital DDI and clinical-workflow platform. Its main journey runs from administrator-led patient intake and doctor/appointment allocation through consultation, prescription, DGAT-based interaction screening, clinician decision, patient report, pharmacist dispensing, and patient access. React pages call a FastAPI application whose domain modules use MongoDB or its in-memory fallback. The graph preserves the documented workflow and major capabilities; some backend modules are represented by their exact paths but were not sampled, so only documented or indexed relationships are connected.

Main entry points: [`app/main.py`](https://github.com/prashik-54/mediguardai/blob/main/app/main.py) (FastAPI routes), [`frontend/src/App.jsx`](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/App.jsx) (Role-based SPA), [`frontend/src/lib/api.js`](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/lib/api.js) (API client), [`app/modules/module13_reports.py`](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module13_reports.py) (Report generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_people["Clinical workflow"]
end

subgraph group_web["React application"]
  node_spa["Role-based SPA<br/>[App.jsx]"]
  node_authui["Sign-in session<br/>[AuthContext.jsx]"]
  node_intakeui["Patient intake<br/>[PatientIntake.jsx]"]
  node_consultui["Consultation<br/>[Consultation.jsx]"]
  node_prescriptionui["Prescription workspace<br/>[Prescription.jsx]"]
  node_ddiui["DDI workspace<br/>[DDIWorkspace.jsx]"]
  node_reviewui["Pharmacist review"]
  node_reportsui["Patient reports<br/>[Reports.jsx]"]
  node_api["API client<br/>[api.js]"]
end

subgraph group_backend["FastAPI services"]
  node_entry["FastAPI routes<br/>[main.py]"]
  node_auth["Authentication<br/>[module_auth.py]"]
  node_org["Organizations<br/>[module_org.py]"]
  node_patients["Patient records<br/>[module1_patient.py]"]
  node_appointments["Appointments"]
  node_encounters["Encounters"]
  node_prescriptions["Prescription lifecycle"]
  node_analysis["DDI analyses"]
  node_decisions["Doctor decisions"]
  node_reporting["Report generation"]
  node_pharmacy["Dispensing"]
  node_audit["Audit trail<br/>[module15_audit.py]"]
  node_notifications["Notifications"]
end

subgraph group_intelligence["DDI intelligence"]
  node_explain["Score explanations"]
  node_pipeline["Clinical preprocessing"]
  node_drug["Drug lookup<br/>[module2_drug.py]"]
  node_predictor["DGAT predictor<br/>[dgat_predictor.py]"]
  node_model["DGAT model<br/>[dgat_model.py]"]
end

subgraph group_data["Persistence"]
  node_store[("MongoDB / memory store<br/>[db.py]")]
end

node_staff(("Hospital staff"))
node_patient(("Patient"))

node_staff -->|"uses"| node_spa
node_patient -->|"views records"| node_spa
node_spa -->|"provides session"| node_authui
node_spa -->|"routes to"| node_intakeui
node_spa -->|"routes to"| node_consultui
node_spa -->|"routes to"| node_prescriptionui
node_spa -->|"routes to"| node_ddiui
node_spa -->|"routes to"| node_reviewui
node_spa -->|"routes to"| node_reportsui
node_authui -->|"calls"| node_api
node_intakeui -->|"submits records"| node_api
node_prescriptionui -->|"requests DDI"| node_api
node_ddiui -->|"requests analysis"| node_api
node_reviewui -->|"submits review"| node_api
node_reportsui -->|"fetches reports"| node_api
node_api -->|"HTTPS JSON"| node_entry
node_entry -->|"routes to"| node_auth
node_entry -->|"routes to"| node_org
node_entry -->|"routes to"| node_patients
node_entry -->|"routes to"| node_appointments
node_entry -->|"routes to"| node_encounters
node_entry -->|"routes to"| node_prescriptions
node_entry -->|"routes to"| node_analysis
node_entry -->|"routes to"| node_decisions
node_entry -->|"routes to"| node_reporting
node_entry -->|"routes to"| node_pharmacy
node_entry -->|"routes to"| node_audit
node_entry -->|"routes to"| node_notifications
node_patients -->|"reads / writes"| node_store
node_auth -->|"reads / writes"| node_store
node_reporting -->|"reads / writes"| node_store
node_entry -->|"uses lookup"| node_drug
node_drug -->|"uses preprocessing"| node_pipeline
node_entry -->|"scores pairs"| node_predictor
node_predictor -->|"uses model"| node_model
node_analysis -->|"scores interactions"| node_predictor
node_entry -->|"generates explanations"| node_explain
node_staff -->|"registers patient"| node_intakeui
node_staff -->|"assigns visit"| node_appointments
node_appointments -->|"creates encounter"| node_encounters
node_staff -->|"finalizes plan"| node_prescriptions
node_analysis -->|"informs decision"| node_decisions
node_decisions -->|"supports report"| node_reporting
node_reporting -->|"sends prescription"| node_pharmacy
node_pharmacy -->|"records dispensing"| node_patient
node_reporting -->|"makes report visible"| node_patient

click node_spa "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/context/AuthContext.jsx"
click node_intakeui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/intake/PatientIntake.jsx"
click node_consultui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/consult/Consultation.jsx"
click node_prescriptionui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/consult/Prescription.jsx"
click node_ddiui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/ddi/DDIWorkspace.jsx"
click node_reviewui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/review/PharmacistReview.jsx"
click node_reportsui "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/reports/Reports.jsx"
click node_api "https://github.com/prashik-54/mediguardai/blob/main/frontend/src/lib/api.js"
click node_entry "https://github.com/prashik-54/mediguardai/blob/main/app/main.py"
click node_auth "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module_auth.py"
click node_org "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module_org.py"
click node_patients "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module1_patient.py"
click node_appointments "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module8_appointments.py"
click node_encounters "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module9_encounters.py"
click node_prescriptions "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module10_prescriptions.py"
click node_analysis "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module11_ddi_analysis.py"
click node_decisions "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module12_doctor_decision.py"
click node_reporting "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module13_reports.py"
click node_pharmacy "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module14_pharmacy.py"
click node_audit "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module15_audit.py"
click node_notifications "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module6_notifications.py"
click node_explain "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module16_explainability.py"
click node_pipeline "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module3_pipeline.py"
click node_drug "https://github.com/prashik-54/mediguardai/blob/main/app/modules/module2_drug.py"
click node_predictor "https://github.com/prashik-54/mediguardai/blob/main/app/ml/dgat_predictor.py"
click node_model "https://github.com/prashik-54/mediguardai/blob/main/app/ml/dgat_model.py"
click node_store "https://github.com/prashik-54/mediguardai/blob/main/app/db.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_spa,node_authui,node_intakeui,node_consultui,node_prescriptionui,node_ddiui,node_reviewui,node_reportsui,node_api toneAmber
class node_entry,node_auth,node_org,node_patients,node_appointments,node_encounters,node_prescriptions,node_analysis,node_decisions,node_reporting,node_pharmacy,node_audit,node_notifications toneMint
class node_explain,node_pipeline,node_drug,node_predictor,node_model toneRose
class node_store,node_staff,node_patient toneIndigo
```

## Components

### React application

- [Role-based SPA](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Sign-in session](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Patient intake](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/intake/PatientIntake.jsx): `frontend/src/pages/intake/PatientIntake.jsx`
- [Consultation](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/consult/Consultation.jsx): `frontend/src/pages/consult/Consultation.jsx`
- [Prescription workspace](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/consult/Prescription.jsx): `frontend/src/pages/consult/Prescription.jsx`
- [DDI workspace](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/ddi/DDIWorkspace.jsx): `frontend/src/pages/ddi/DDIWorkspace.jsx`
- [Pharmacist review](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/review/PharmacistReview.jsx): `frontend/src/pages/review/PharmacistReview.jsx`
- [Patient reports](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/pages/reports/Reports.jsx): `frontend/src/pages/reports/Reports.jsx`
- [API client](https://github.com/prashik-54/mediguardai/blob/main/frontend/src/lib/api.js): `frontend/src/lib/api.js`

### FastAPI services

- [FastAPI routes](https://github.com/prashik-54/mediguardai/blob/main/app/main.py): `app/main.py`
- [Authentication](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module_auth.py): `app/modules/module_auth.py`
- [Organizations](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module_org.py): `app/modules/module_org.py`
- [Patient records](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module1_patient.py): `app/modules/module1_patient.py`
- [Appointments](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module8_appointments.py): `app/modules/module8_appointments.py`
- [Encounters](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module9_encounters.py): `app/modules/module9_encounters.py`
- [Prescription lifecycle](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module10_prescriptions.py): `app/modules/module10_prescriptions.py`
- [DDI analyses](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module11_ddi_analysis.py): `app/modules/module11_ddi_analysis.py`
- [Doctor decisions](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module12_doctor_decision.py): `app/modules/module12_doctor_decision.py`
- [Report generation](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module13_reports.py): `app/modules/module13_reports.py`
- [Dispensing](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module14_pharmacy.py): `app/modules/module14_pharmacy.py`
- [Audit trail](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module15_audit.py): `app/modules/module15_audit.py`
- [Notifications](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module6_notifications.py): `app/modules/module6_notifications.py`

### DDI intelligence

- [Score explanations](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module16_explainability.py): `app/modules/module16_explainability.py`
- [Clinical preprocessing](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module3_pipeline.py): `app/modules/module3_pipeline.py`
- [Drug lookup](https://github.com/prashik-54/mediguardai/blob/main/app/modules/module2_drug.py): `app/modules/module2_drug.py`
- [DGAT predictor](https://github.com/prashik-54/mediguardai/blob/main/app/ml/dgat_predictor.py): `app/ml/dgat_predictor.py`
- [DGAT model](https://github.com/prashik-54/mediguardai/blob/main/app/ml/dgat_model.py): `app/ml/dgat_model.py`

### Persistence

- [MongoDB / memory store](https://github.com/prashik-54/mediguardai/blob/main/app/db.py): `app/db.py`

### Other components

- **Hospital staff**
- **Patient**

## Connections

- Hospital staff → Role-based SPA: uses
- Patient → Role-based SPA: views records
- Role-based SPA → Sign-in session: provides session (evidence: `frontend/src/App.jsx`)
- Role-based SPA → Patient intake: routes to (evidence: `frontend/src/App.jsx`)
- Role-based SPA → Consultation: routes to (evidence: `frontend/src/App.jsx`)
- Role-based SPA → Prescription workspace: routes to (evidence: `frontend/src/App.jsx`)
- Role-based SPA → DDI workspace: routes to (evidence: `frontend/src/App.jsx`)
- Role-based SPA → Pharmacist review: routes to (evidence: `frontend/src/App.jsx`)
- Role-based SPA → Patient reports: routes to (evidence: `frontend/src/App.jsx`)
- Sign-in session → API client: calls (evidence: `frontend/src/context/AuthContext.jsx`)
- Patient intake → API client: submits records (evidence: `frontend/src/pages/intake/PatientIntake.jsx`)
- Prescription workspace → API client: requests DDI (evidence: `frontend/src/pages/consult/Prescription.jsx`)
- DDI workspace → API client: requests analysis (evidence: `frontend/src/pages/ddi/DDIWorkspace.jsx`)
- Pharmacist review → API client: submits review
- Patient reports → API client: fetches reports (evidence: `frontend/src/pages/reports/Reports.jsx`)
- API client → FastAPI routes: HTTPS JSON
- FastAPI routes → Authentication: routes to (evidence: `app/main.py`)
- FastAPI routes → Organizations: routes to (evidence: `app/main.py`)
- FastAPI routes → Patient records: routes to (evidence: `app/main.py`)
- FastAPI routes → Appointments: routes to (evidence: `app/main.py`)
- FastAPI routes → Encounters: routes to (evidence: `app/main.py`)
- FastAPI routes → Prescription lifecycle: routes to (evidence: `app/main.py`)
- FastAPI routes → DDI analyses: routes to (evidence: `app/main.py`)
- FastAPI routes → Doctor decisions: routes to (evidence: `app/main.py`)
- FastAPI routes → Report generation: routes to (evidence: `app/main.py`)
- FastAPI routes → Dispensing: routes to (evidence: `app/main.py`)
- FastAPI routes → Audit trail: routes to (evidence: `app/main.py`)
- FastAPI routes → Notifications: routes to (evidence: `app/main.py`)
- Patient records → MongoDB / memory store: reads / writes (evidence: `app/modules/module1_patient.py`)
- Authentication → MongoDB / memory store: reads / writes (evidence: `app/modules/module_auth.py`)
- Report generation → MongoDB / memory store: reads / writes (evidence: `app/modules/module13_reports.py`)
- FastAPI routes → Drug lookup: uses lookup (evidence: `app/main.py`)
- Drug lookup → Clinical preprocessing: uses preprocessing (evidence: `app/modules/module2_drug.py`)
- FastAPI routes → DGAT predictor: scores pairs (evidence: `app/main.py`)
- DGAT predictor → DGAT model: uses model (evidence: `app/ml/dgat_predictor.py`)
- DDI analyses → DGAT predictor: scores interactions
- FastAPI routes → Score explanations: generates explanations (evidence: `app/main.py`)
- Hospital staff → Patient intake: registers patient
- Hospital staff → Appointments: assigns visit
- Appointments → Encounters: creates encounter
- Hospital staff → Prescription lifecycle: finalizes plan
- DDI analyses → Doctor decisions: informs decision
- Doctor decisions → Report generation: supports report
- Report generation → Dispensing: sends prescription
- Dispensing → Patient: records dispensing
- Report generation → Patient: makes report visible
