# tejash09/brain-tumor architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack web application for brain tumor detection and visualization.
- It uses a Flask backend that serves HTML/CSS/JS views, runs a U-Net model for 3D semantic segmentation on MRI scans, and returns interactive visualizations to the user’s browser.

##### File structure
- Top-level directories/files:
- app1.py / app.py / main.py – Flask application entrypoints
- requirements.txt – dependency list (Flask, TensorFlow/PyTorch, Nibabel, Plotly, Nilearn, etc.)
- model_per_class.h5 – pre-trained U-Net segmentation weights
- sampledata/… – packaged NIfTI sample MRI scans for demo
- templates/… – Jinja2 HTML templates & client-side assets (app.js, CSS, upload.html, patients.html, etc.)
- gif.py, img.py, vol.py, python_script.py – backend modules handling GIF generation, image slicing, volume calculations, plotting, etc.
- style.css, about.css – top-level static styles
- Architectural pattern: a monolithic Flask “controller” with separate “service” modules for ML inference, data processing, and visualization. The “view” layer is implemented in Jinja2 templates + client JS.

##### Pull extra insights from the README
- Core ML is a U-Net 3D semantic segmentation (TensorFlow/PyTorch).
- Visualization uses Plotly (3D surface, multi-slice), Nilearn (statistical plots), custom GIFs.
- Web UI: Patients page, Upload page, About page, Interactive 3D viewer.

##### Elements
- Blue for user‐facing components (Browser, templates)
- Green for backend compute (ML, segmentation, plotting)
- Orange for data artifacts (model file, sampledata)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend (Browser)"
        Templates["templates/"]:::frontend
        About["about.html"]:::frontend
        Upload["upload.html"]:::frontend
        Patients["patients.html"]:::frontend
        AppJS["app.js"]:::frontend
        CSS1["style.css"]:::frontend
        CSS2["about.css"]:::frontend
    end

    subgraph "Backend (Flask + Services)"
        subgraph "Controllers"
            AppPy["app.py"]:::backend
            App1["app1.py"]:::backend
            MainPy["main.py"]:::backend
        end
        subgraph "ML & Processing"
            Model["model_per_class.h5"]:::data
            PyScript["python_script.py"]:::backend
            TScript["t.py"]:::backend
        end
        subgraph "Visualization Service"
            Img["img.py"]:::backend
            Vol["vol.py"]:::backend
            Gif["gif.py"]:::backend
        end
    end

    subgraph "Data Storage"
        Sample["sampledata/"]:::data
    end

    subgraph "External Libraries"
        Req["requirements.txt"]:::external
    end

    Templates -->|"HTTP GET/POST"| AppPy
    AppPy -->|"invoke inference"| PyScript
    PyScript -->|"segmentation mask"| Img
    Img -->|"2D slices & volume prep"| Vol
    Vol -->|"3D data prep"| Gif
    Gif -->|"return animation"| AppPy
    AppPy -->|"render Jinja2"| Templates

    Sample -->|".nii MRI files"| PyScript

    Req -.-> AppPy
    Req -.-> PyScript
    Req -.-> Img
    Req -.-> Vol
    Req -.-> Gif

    click Templates "https://github.com/tejash09/brain-tumor/tree/main/templates/"
    click About "https://github.com/tejash09/brain-tumor/blob/main/templates/about.html"
    click Upload "https://github.com/tejash09/brain-tumor/blob/main/templates/upload.html"
    click Patients "https://github.com/tejash09/brain-tumor/blob/main/templates/patients.html"
    click AppJS "https://github.com/tejash09/brain-tumor/blob/main/templates/app.js"
    click CSS1 "https://github.com/tejash09/brain-tumor/blob/main/style.css"
    click CSS2 "https://github.com/tejash09/brain-tumor/blob/main/about.css"
    click AppPy "https://github.com/tejash09/brain-tumor/blob/main/app.py"
    click App1 "https://github.com/tejash09/brain-tumor/blob/main/app1.py"
    click MainPy "https://github.com/tejash09/brain-tumor/blob/main/main.py"
    click Model "https://github.com/tejash09/brain-tumor/blob/main/model_per_class.h5"
    click PyScript "https://github.com/tejash09/brain-tumor/blob/main/python_script.py"
    click TScript "https://github.com/tejash09/brain-tumor/blob/main/t.py"
    click Img "https://github.com/tejash09/brain-tumor/blob/main/img.py"
    click Vol "https://github.com/tejash09/brain-tumor/blob/main/vol.py"
    click Gif "https://github.com/tejash09/brain-tumor/blob/main/gif.py"
    click Sample "https://github.com/tejash09/brain-tumor/tree/main/sampledata/"
    click Req "https://github.com/tejash09/brain-tumor/blob/main/requirements.txt"

    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0FFD8,stroke:#333,stroke-width:1px
    classDef data fill:#FFE4B2,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
