# vietphu01/medical_expert_system architecture

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

- Interactive diagram: https://gitdiagram.com/vietphu01/medical_expert_system
- Repository: https://github.com/vietphu01/medical_expert_system

## Overview

This is a Flask medical risk-assessment application. A user opens the web interface, submits disease-specific measurements, and receives an ensemble probability plus fuzzy and expert-rule conclusions; the application records diagnoses for later history queries. At startup it generates synthetic disease data and trains models, which are also used to expose model metrics and decision-tree rules. The excerpts show the backend routes and template rendering, but not the template’s client-side behavior or the contents of the knowledge base and SQLite database.

Main entry points: [`app.py`](https://github.com/vietphu01/medical_expert_system/blob/main/app.py) (Flask routes), [`inference_engine.py`](https://github.com/vietphu01/medical_expert_system/blob/main/inference_engine.py) (Expert inference), [`medical_history.db`](https://github.com/vietphu01/medical_expert_system/blob/main/medical_history.db) (Medical history), [`templates/index.html`](https://github.com/vietphu01/medical_expert_system/blob/main/templates/index.html) (Diagnosis page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_flask["Flask routes<br/>[app.py]"]
  node_page["Diagnosis page<br/>[index.html]"]
end

subgraph group_diagnosis["Diagnosis pipeline"]
  node_disease_config["Disease configuration<br/>[diseases_config.py]"]
  node_fuzzy["Fuzzy facts<br/>[fuzzy_engine.py]"]
  node_expert["Expert inference"]
end

subgraph group_models["Modeling"]
  node_training["Synthetic training data<br/>[diseases_config.py]"]
  node_ml["ML algorithms"]
end

subgraph group_state["Rules and history"]
  node_knowledge["Rule knowledge base"]
  node_history[("Medical history<br/>[medical_history.db]")]
end

node_user(("User"))

node_user -->|"submits requests"| node_flask
node_flask -->|"renders"| node_page
node_flask -->|"returns JSON"| node_user
node_flask -->|"reads configuration"| node_disease_config
node_flask -->|"generates datasets"| node_training
node_flask -->|"trains and predicts"| node_ml
node_flask -->|"computes fuzzy facts"| node_fuzzy
node_flask -->|"runs inference"| node_expert
node_expert -->|"loads rules"| node_knowledge
node_flask -->|"writes diagnoses"| node_history
node_flask -->|"reads recent history"| node_history

click node_flask "https://github.com/vietphu01/medical_expert_system/blob/main/app.py"
click node_page "https://github.com/vietphu01/medical_expert_system/blob/main/templates/index.html"
click node_disease_config "https://github.com/vietphu01/medical_expert_system/blob/main/diseases_config.py"
click node_fuzzy "https://github.com/vietphu01/medical_expert_system/blob/main/fuzzy_engine.py"
click node_expert "https://github.com/vietphu01/medical_expert_system/blob/main/inference_engine.py"
click node_training "https://github.com/vietphu01/medical_expert_system/blob/main/diseases_config.py"
click node_ml "https://github.com/vietphu01/medical_expert_system/blob/main/math_ml_from_scratch.py"
click node_knowledge "https://github.com/vietphu01/medical_expert_system/blob/main/knowledge_base.json"
click node_history "https://github.com/vietphu01/medical_expert_system/blob/main/medical_history.db"

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_flask,node_page,node_user toneBlue
class node_disease_config,node_fuzzy,node_expert toneAmber
class node_training,node_ml toneMint
class node_knowledge,node_history toneRose
```

## Components

### Web interface

- [Flask routes](https://github.com/vietphu01/medical_expert_system/blob/main/app.py): `app.py`
- [Diagnosis page](https://github.com/vietphu01/medical_expert_system/blob/main/templates/index.html): `templates/index.html`

### Diagnosis pipeline

- [Disease configuration](https://github.com/vietphu01/medical_expert_system/blob/main/diseases_config.py): `diseases_config.py`
- [Fuzzy facts](https://github.com/vietphu01/medical_expert_system/blob/main/fuzzy_engine.py): `fuzzy_engine.py`
- [Expert inference](https://github.com/vietphu01/medical_expert_system/blob/main/inference_engine.py): `inference_engine.py`

### Modeling

- [Synthetic training data](https://github.com/vietphu01/medical_expert_system/blob/main/diseases_config.py): `diseases_config.py`
- [ML algorithms](https://github.com/vietphu01/medical_expert_system/blob/main/math_ml_from_scratch.py): `math_ml_from_scratch.py`

### Rules and history

- [Rule knowledge base](https://github.com/vietphu01/medical_expert_system/blob/main/knowledge_base.json): `knowledge_base.json`
- [Medical history](https://github.com/vietphu01/medical_expert_system/blob/main/medical_history.db): `medical_history.db`

### Other components

- **User**

## Connections

- User → Flask routes: submits requests (evidence: `app.py`)
- Flask routes → Diagnosis page: renders (evidence: `app.py`)
- Flask routes → User: returns JSON (evidence: `app.py`)
- Flask routes → Disease configuration: reads configuration (evidence: `app.py`)
- Flask routes → Synthetic training data: generates datasets (evidence: `app.py`)
- Flask routes → ML algorithms: trains and predicts (evidence: `app.py`)
- Flask routes → Fuzzy facts: computes fuzzy facts (evidence: `app.py`)
- Flask routes → Expert inference: runs inference (evidence: `app.py`)
- Expert inference → Rule knowledge base: loads rules (evidence: `inference_engine.py`)
- Flask routes → Medical history: writes diagnoses (evidence: `app.py`)
- Flask routes → Medical history: reads recent history (evidence: `app.py`)
