# arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection architecture

> Architecture diagram of the GitHub repository arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection
- Repository: https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection

## Overview

This is a full-stack brain MRI analysis application. A user uploads a scan and selects a masking threshold; the React upload page sends it to Flask, whose inference pipeline detects a tumour with ViT, localizes it, classifies the region with ResNet-50, and produces explainability images. Results are displayed in the UI and can be submitted for PDF generation. The graph reflects the documented pipeline and shown calls; unsampled frontend and report internals are represented at their documented subsystem level.

Main entry points: [`frontend/src/pages/ResultsPage.jsx`](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/pages/ResultsPage.jsx) (Results view), [`backend/utils.py`](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py) (Image decoding and transforms), [`backend/app.py`](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/app.py) (Flask API), [`frontend/src/pages/UploadPage.jsx`](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/pages/UploadPage.jsx) (MRI upload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Web interface"]
  node_upload["MRI upload<br/>[UploadPage.jsx]"]
  node_app["UI state and routing<br/>[App.jsx]"]
  node_results["Results view<br/>[ResultsPage.jsx]"]
  node_imageviewer["Image viewer<br/>[ImageViewer.jsx]"]
  node_confidence["Confidence display<br/>[ConfidenceBar.jsx]"]
  node_tumorbadge["Tumour type badge<br/>[TumorTypeBadge.jsx]"]
end

subgraph group_api["API and orchestration"]
  node_api["Flask API<br/>[app.py]"]
end

subgraph group_analysis["MRI analysis"]
  node_imageprep["Image decoding and transforms<br/>[utils.py]"]
  node_vit["ViT detection<br/>[model.py]"]
  node_localize["Attention localization<br/>[utils.py]"]
  node_resnet["ResNet classification<br/>[model.py]"]
  node_explain["Grad-CAM and masks<br/>[utils.py]"]
end

subgraph group_reporting["Reporting"]
  node_reportapi["PDF endpoint<br/>[app.py]"]
  node_pdf["PDF report generation<br/>[report.py]"]
end

node_user(("User"))

node_user -->|"selects scan"| node_upload
node_upload -->|"sets upload state"| node_app
node_app -->|"renders"| node_upload
node_app -->|"renders results"| node_results
node_upload -->|"posts image"| node_api
node_api -->|"decodes image"| node_imageprep
node_api -->|"loads model"| node_vit
node_api -->|"runs pipeline"| node_imageprep
node_imageprep -->|"runs detection"| node_vit
node_imageprep -->|"localizes region"| node_localize
node_imageprep -->|"classifies region"| node_resnet
node_imageprep -->|"generates visualizations"| node_explain
node_api -->|"returns result"| node_results
node_results -->|"renders image view"| node_imageviewer
node_results -->|"renders confidence"| node_confidence
node_results -->|"renders tumour type"| node_tumorbadge
node_results -->|"posts result"| node_reportapi
node_reportapi -->|"generates PDF"| node_pdf
node_user -.->|"views findings"| node_results
node_pdf -->|"downloads report"| node_user

click node_upload "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/pages/UploadPage.jsx"
click node_app "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/App.jsx"
click node_results "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/pages/ResultsPage.jsx"
click node_imageviewer "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/components/ImageViewer.jsx"
click node_confidence "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/components/ConfidenceBar.jsx"
click node_tumorbadge "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/components/TumorTypeBadge.jsx"
click node_api "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/app.py"
click node_imageprep "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py"
click node_vit "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/model.py"
click node_localize "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py"
click node_resnet "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/model.py"
click node_explain "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py"
click node_reportapi "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/app.py"
click node_pdf "https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/report.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_upload,node_app,node_results,node_imageviewer,node_confidence,node_tumorbadge,node_user toneBlue
class node_api toneAmber
class node_imageprep,node_vit,node_localize,node_resnet,node_explain toneMint
class node_reportapi,node_pdf toneRose
```

## Components

### Web interface

- [MRI upload](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/pages/UploadPage.jsx): `frontend/src/pages/UploadPage.jsx`
- [UI state and routing](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Results view](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/pages/ResultsPage.jsx): `frontend/src/pages/ResultsPage.jsx`
- [Image viewer](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/components/ImageViewer.jsx): `frontend/src/components/ImageViewer.jsx`
- [Confidence display](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/components/ConfidenceBar.jsx): `frontend/src/components/ConfidenceBar.jsx`
- [Tumour type badge](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/frontend/src/components/TumorTypeBadge.jsx): `frontend/src/components/TumorTypeBadge.jsx`

### API and orchestration

- [Flask API](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/app.py): `backend/app.py`

### MRI analysis

- [Image decoding and transforms](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py): `backend/utils.py`
- [ViT detection](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/model.py): `backend/model.py`
- [Attention localization](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py): `backend/utils.py`
- [ResNet classification](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/model.py): `backend/model.py`
- [Grad-CAM and masks](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/utils.py): `backend/utils.py`

### Reporting

- [PDF endpoint](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/app.py): `backend/app.py`
- [PDF report generation](https://github.com/arunima072004/explainable-cnn-vit-model-for-brain-tumour-detection/blob/main/backend/report.py): `backend/report.py`

### Other components

- **User**

## Connections

- User → MRI upload: selects scan (evidence: `README.md`)
- MRI upload → UI state and routing: sets upload state (evidence: `frontend/src/App.jsx`)
- UI state and routing → MRI upload: renders (evidence: `frontend/src/App.jsx`)
- UI state and routing → Results view: renders results (evidence: `frontend/src/App.jsx`)
- MRI upload → Flask API: posts image (evidence: `frontend/src/pages/UploadPage.jsx`)
- Flask API → Image decoding and transforms: decodes image (evidence: `backend/app.py`)
- Flask API → ViT detection: loads model (evidence: `backend/app.py`)
- Flask API → Image decoding and transforms: runs pipeline (evidence: `backend/app.py`)
- Image decoding and transforms → ViT detection: runs detection (evidence: `README.md`)
- Image decoding and transforms → Attention localization: localizes region (evidence: `README.md`)
- Image decoding and transforms → ResNet classification: classifies region (evidence: `README.md`)
- Image decoding and transforms → Grad-CAM and masks: generates visualizations (evidence: `README.md`)
- Flask API → Results view: returns result (evidence: `README.md`)
- Results view → Image viewer: renders image view (evidence: `frontend/src/pages/ResultsPage.jsx`)
- Results view → Confidence display: renders confidence (evidence: `frontend/src/pages/ResultsPage.jsx`)
- Results view → Tumour type badge: renders tumour type (evidence: `frontend/src/pages/ResultsPage.jsx`)
- Results view → PDF endpoint: posts result (evidence: `frontend/src/pages/ResultsPage.jsx`)
- PDF endpoint → PDF report generation: generates PDF (evidence: `backend/app.py`)
- User → Results view: views findings (evidence: `README.md`)
- PDF report generation → User: downloads report
