# amirha-jafari/brain-tumor-detection-segmentation architecture

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

- Interactive diagram: https://gitdiagram.com/amirha-jafari/brain-tumor-detection-segmentation
- Repository: https://github.com/amirha-jafari/brain-tumor-detection-segmentation

## Overview

This repository is a brain-MRI tumor screening and segmentation application. Its user-facing workflow accepts a scan through either the web dashboard/API or the command-line tool, classifies tumor presence, conditionally segments a positive scan, and returns a diagnosis and mask overlay. The documented model-development lifecycle covers preprocessing, separate classification and segmentation training/evaluation, and saved weights. Source excerpts establish inference and serving calls; training/evaluation implementations were not sampled, so those stages are represented only at their documented subsystem paths.

Main entry points: [`src/inference/predict.py`](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/inference/predict.py) (Inference pipeline), [`src/data/preprocessing.py`](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/preprocessing.py) (Dataset preprocessing), [`src/models/classifier.py`](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/models/classifier.py) (SimpleCNN classifier), [`src/models/unet.py`](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/models/unet.py) (U-Net model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_rawdata[("MRI dataset")]
  node_prep["Dataset preprocessing<br/>[preprocessing.py]"]
  node_classdata["Classification samples<br/>[dataset.py]"]
  node_segdata["Segmentation samples"]
end

subgraph group_models["Model lifecycle"]
  node_classtrain["Classifier training"]
  node_classeval["Classifier evaluation"]
  node_segtrain["Segmentation training"]
  node_segeval["Segmentation evaluation"]
  node_classifier["SimpleCNN classifier<br/>[classifier.py]"]
  node_unet["U-Net model<br/>[unet.py]"]
  node_weights[("Saved model weights")]
end

subgraph group_runtime["Prediction runtime"]
  node_inference["Inference pipeline<br/>[predict.py]"]
end

subgraph group_interfaces["User interfaces"]
  node_api["FastAPI service<br/>[server.py]"]
  node_dashboard["Web dashboard<br/>[index.html]"]
  node_cli["Command-line tool<br/>[main.py]"]
end

node_user(("Scan user"))

node_user -->|"uploads scan"| node_dashboard
node_dashboard -->|"requests prediction"| node_api
node_user -->|"provides scan"| node_cli
node_rawdata -->|"prepares records"| node_prep
node_prep -.->|"labels samples"| node_classdata
node_prep -.->|"indexes masks"| node_segdata
node_classdata -.->|"trains on"| node_classtrain
node_classtrain -->|"evaluates model"| node_classeval
node_classeval -->|"selects model"| node_classifier
node_segdata -.->|"trains on"| node_segtrain
node_segtrain -->|"evaluates model"| node_segeval
node_segeval -->|"selects model"| node_unet
node_classifier -->|"persists weights"| node_weights
node_unet -->|"persists weights"| node_weights
node_api -->|"calls"| node_inference
node_cli -->|"calls"| node_inference
node_inference -->|"constructs and runs"| node_classifier
node_inference -->|"constructs and runs"| node_unet
node_weights -->|"loads parameters"| node_inference
node_inference -->|"returns prediction"| node_api

click node_rawdata "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/data/raw"
click node_prep "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/preprocessing.py"
click node_classdata "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/dataset.py"
click node_segdata "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/segmentation_dataset.py"
click node_classtrain "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/training"
click node_classeval "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/evaluation"
click node_segtrain "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/training"
click node_segeval "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/evaluation"
click node_classifier "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/models/classifier.py"
click node_unet "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/models/unet.py"
click node_weights "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/models"
click node_inference "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/inference/predict.py"
click node_api "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/server.py"
click node_dashboard "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/web/index.html"
click node_cli "https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/main.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_rawdata,node_prep,node_classdata,node_segdata,node_user toneBlue
class node_classtrain,node_classeval,node_segtrain,node_segeval,node_classifier,node_unet,node_weights toneAmber
class node_inference toneMint
class node_api,node_dashboard,node_cli toneRose
```

## Components

### Data preparation

- [MRI dataset](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/data/raw): `data/raw`
- [Dataset preprocessing](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/preprocessing.py): `src/data/preprocessing.py`
- [Classification samples](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/dataset.py): `src/data/dataset.py`
- [Segmentation samples](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/data/segmentation_dataset.py): `src/data/segmentation_dataset.py`

### Model lifecycle

- [Classifier training](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/training): `src/training`
- [Classifier evaluation](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/evaluation): `src/evaluation`
- [Segmentation training](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/training): `src/training`
- [Segmentation evaluation](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/src/evaluation): `src/evaluation`
- [SimpleCNN classifier](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/models/classifier.py): `src/models/classifier.py`
- [U-Net model](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/models/unet.py): `src/models/unet.py`
- [Saved model weights](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/tree/main/models): `models`

### Prediction runtime

- [Inference pipeline](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/src/inference/predict.py): `src/inference/predict.py`

### User interfaces

- [FastAPI service](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/server.py): `server.py`
- [Web dashboard](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/web/index.html): `web/index.html`
- [Command-line tool](https://github.com/amirha-jafari/brain-tumor-detection-segmentation/blob/main/main.py): `main.py`

### Other components

- **Scan user**

## Connections

- Scan user → Web dashboard: uploads scan (evidence: `README.md`)
- Web dashboard → FastAPI service: requests prediction (evidence: `README.md`)
- Scan user → Command-line tool: provides scan (evidence: `main.py`)
- MRI dataset → Dataset preprocessing: prepares records (evidence: `README.md`)
- Dataset preprocessing → Classification samples: labels samples
- Dataset preprocessing → Segmentation samples: indexes masks
- Classification samples → Classifier training: trains on
- Classifier training → Classifier evaluation: evaluates model (evidence: `README.md`)
- Classifier evaluation → SimpleCNN classifier: selects model (evidence: `README.md`)
- Segmentation samples → Segmentation training: trains on
- Segmentation training → Segmentation evaluation: evaluates model (evidence: `README.md`)
- Segmentation evaluation → U-Net model: selects model (evidence: `README.md`)
- SimpleCNN classifier → Saved model weights: persists weights (evidence: `README.md`)
- U-Net model → Saved model weights: persists weights (evidence: `README.md`)
- FastAPI service → Inference pipeline: calls (evidence: `server.py`)
- Command-line tool → Inference pipeline: calls (evidence: `main.py`)
- Inference pipeline → SimpleCNN classifier: constructs and runs (evidence: `src/inference/predict.py`)
- Inference pipeline → U-Net model: constructs and runs (evidence: `src/inference/predict.py`)
- Saved model weights → Inference pipeline: loads parameters (evidence: `src/inference/predict.py`)
- Inference pipeline → FastAPI service: returns prediction (evidence: `server.py`)
