# subhamroushan2018/brain-tumor-detection architecture

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

- Interactive diagram: https://gitdiagram.com/subhamroushan2018/brain-tumor-detection
- Repository: https://github.com/subhamroushan2018/brain-tumor-detection

## Overview

#### Purpose and Entry Points
This repository trains and deploys a deep-learning classifier for brain-tumor MRI images. The offline training/evaluation entry point is `Model/brain_tumor_model.ipynb`; the runtime inference entry point is the Python web application at `Web App/app.py`.

#### Dataset Boundary
MRI training and testing data are intentionally external to version control. The expected dataset structure is documented in `Dataset/README.md` and must be supplied locally, typically as training/testing image directories. Dataset paths are environment-specific, creating a boundary between reproducible code and large medical-image assets.

#### Training and Model Selection
The notebook implements the ML lifecycle: loading labeled image paths, balancing/splitting data, preprocessing through Keras image generators, training multiple CNN variants, and comparing validation/test metrics. It covers simple and deeper custom CNNs plus VGG16 transfer learning.
- `Model/brain_tumor_model.ipynb`
- `Model/README.md`

The selected model is serialized as `best_model.keras`; it is a generated deployment artifact rather than a tracked repository file.

#### Inference Artifact Handoff
Training and serving are decoupled through the saved Keras model. The notebook produces `best_model.keras`, and deployment expects that artifact to be placed alongside the web application in `Web App/`. This file contract is the primary handoff: changes to preprocessing, class order, or model architecture must remain compatible with inference in `Web App/app.py`.
- `Model/brain_tumor_model.ipynb`
- `Web App/app.py`
- `Web App/README.md`

#### Web Request Flow
The web application accepts an uploaded MRI image, loads/applies the trained model for prediction, and renders an HTML result or failure response. Its server-side routes and inference orchestration reside in `Web App/app.py`; presentation is separated into templates:
- `Web App/Templates/index.html`
- `Web App/Templates/result.html`
- `Web App/Templates/error.html`

Styles are static frontend assets under `Web App/Style/styles.css` and `Web App/Style/styles1.css`.

#### Runtime and Dependencies
The system runs on Python. TensorFlow/Keras provides CNN/VGG16 modeling, training, serialization, and inference; NumPy and Pandas support data processing; Matplotlib supports training/evaluation visualization. Deployment-specific dependencies are declared in `Web App/requirements.txt`, while project/training dependencies are represented by root `requirements.txt`.

#### External Services and Infrastructure
No hosted infrastructure, database, API, or cloud integration is represented in the tree. The main external dependency is the Kaggle Brain Tumor MRI dataset referenced by the root documentation. The application is designed for local or separately hosted Python web serving, with the trained `.keras` artifact and image dataset provisioned outside Git.

Main entry points: [`Web App/app.py`](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/app.py) (Inference application), [`Model/brain_tumor_model.ipynb`](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Model/brain_tumor_model.ipynb) (Training notebook), [`Web App/Templates/index.html`](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Templates/index.html) (Result templates), [`Dataset/README.md`](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Dataset/README.md) (Dataset contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Offline training"]
  node_dataset_docs["Dataset contract<br/>documentation<br/>[README.md]"]
  node_external_dataset[("External MRI dataset<br/>external dataset")]
  node_training_notebook["Training notebook"]
  node_model_docs["Model workflow docs<br/>documentation<br/>[README.md]"]
  node_data_split["Balanced data splits<br/>ML data stage"]
  node_image_pipeline["Keras image pipeline<br/>preprocessing"]
  node_model_candidates["CNN candidates<br/>model training"]
  node_model_evaluation["Model evaluation<br/>ML evaluation"]
  node_training_deps["Training dependencies<br/>Python dependencies<br/>[requirements.txt]"]
end

subgraph group_serving["Web serving"]
  node_web_app["Inference application<br/>Python web app<br/>[app.py]"]
  node_upload_image["Uploaded MRI image<br/>request input"]
  node_templates["Result templates<br/>HTML templates<br/>[index.html]"]
  node_error_template["Error template<br/>HTML template<br/>[error.html]"]
  node_styles["Frontend styles<br/>static assets<br/>[styles.css]"]
  node_web_docs["Web app contract<br/>documentation<br/>[README.md]"]
  node_serving_deps["Serving dependencies<br/>Python dependencies<br/>[requirements.txt]"]
end

node_keras_artifact["best_model.keras<br/>model artifact"]

node_dataset_docs -.->|"defines layout"| node_external_dataset
node_external_dataset -->|"labeled images"| node_training_notebook
node_training_deps -.->|"supports"| node_training_notebook
node_model_docs -.->|"documents"| node_training_notebook
node_training_notebook -->|"loads and balances"| node_data_split
node_data_split -->|"partitions"| node_image_pipeline
node_image_pipeline -->|"preprocessed batches"| node_model_candidates
node_model_candidates -->|"metrics"| node_model_evaluation
node_model_evaluation -->|"serializes selected model"| node_keras_artifact
node_keras_artifact -->|"deployment handoff"| node_web_app
node_serving_deps -.->|"supports"| node_web_app
node_upload_image -->|"HTTP upload"| node_web_app
node_web_app -->|"renders index or prediction"| node_templates
node_web_app -->|"renders failures"| node_error_template
node_styles -->|"styles views"| node_templates
node_web_docs -.->|"documents"| node_web_app

click node_dataset_docs "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Dataset/README.md"
click node_training_notebook "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Model/brain_tumor_model.ipynb"
click node_model_docs "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Model/README.md"
click node_web_app "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/app.py"
click node_templates "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Templates/index.html"
click node_error_template "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Templates/error.html"
click node_styles "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Style/styles.css"
click node_web_docs "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/README.md"
click node_training_deps "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/requirements.txt"
click node_serving_deps "https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/requirements.txt"

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_dataset_docs,node_external_dataset,node_training_notebook,node_model_docs,node_data_split,node_image_pipeline,node_model_candidates,node_model_evaluation,node_training_deps toneBlue
class node_web_app,node_upload_image,node_templates,node_error_template,node_styles,node_web_docs,node_serving_deps toneAmber
class node_keras_artifact toneNeutral
```

## Components

### Offline training

Model development and selection workflow.

- [Dataset contract](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Dataset/README.md): documentation · Documents the required local training and testing image layout. · `Dataset/README.md`
- **External MRI dataset**: external dataset · Locally supplied labeled brain-tumor MRI images.
- [Training notebook](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Model/brain_tumor_model.ipynb): notebook · Loads data, trains CNN variants, and selects a model. · `Model/brain_tumor_model.ipynb`
- [Model workflow docs](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Model/README.md): documentation · `Model/README.md`
- **Balanced data splits**: ML data stage · Balances labeled paths and creates training, validation, and test partitions.
- **Keras image pipeline**: preprocessing · Applies image loading and generator-based preprocessing.
- **CNN candidates**: model training · Trains custom CNNs and VGG16 transfer learning variants.
- **Model evaluation**: ML evaluation · Compares validation and test metrics to select the deployable model.
- [Training dependencies](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/requirements.txt): Python dependencies · TensorFlow/Keras, NumPy, Pandas, and Matplotlib environment. · `requirements.txt`

### Web serving

Runtime image prediction application.

- [Inference application](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/app.py): Python web app · Receives uploads, runs model prediction, and handles failures. · `Web App/app.py`
- **Uploaded MRI image**: request input
- [Result templates](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Templates/index.html): HTML templates · Separate index, prediction-result, and error views. · `Web App/Templates/index.html`
- [Error template](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Templates/error.html): HTML template · `Web App/Templates/error.html`
- [Frontend styles](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/Style/styles.css): static assets · `Web App/Style/styles.css`
- [Web app contract](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/README.md): documentation · Documents runtime model placement and application use. · `Web App/README.md`
- [Serving dependencies](https://github.com/subhamroushan2018/brain-tumor-detection/blob/main/Web%20App/requirements.txt): Python dependencies · `Web App/requirements.txt`

### Other components

- **best_model.keras**: model artifact · Generated Keras model handoff; provisioned beside the web app.

## Connections

- Dataset contract → External MRI dataset: defines layout
- External MRI dataset → Training notebook: labeled images
- Training dependencies → Training notebook: supports
- Model workflow docs → Training notebook: documents
- Training notebook → Balanced data splits: loads and balances
- Balanced data splits → Keras image pipeline: partitions
- Keras image pipeline → CNN candidates: preprocessed batches
- CNN candidates → Model evaluation: metrics
- Model evaluation → best_model.keras: serializes selected model
- best_model.keras → Inference application: deployment handoff · Preprocessing and class order must remain compatible.
- Serving dependencies → Inference application: supports
- Uploaded MRI image → Inference application: HTTP upload
- Inference application → Result templates: renders index or prediction
- Inference application → Error template: renders failures
- Frontend styles → Result templates: styles views
- Web app contract → Inference application: documents
