# vivek02sharma/neuroscan architecture

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

- Interactive diagram: https://gitdiagram.com/vivek02sharma/neuroscan
- Repository: https://github.com/vivek02sharma/neuroscan

## Overview

##### Project type and purpose
- This is a machine-learning powered web application built with Streamlit.
- Its purpose is to let users upload an MRI image, preprocess it, run inference through a pre-trained CNN (brain-tumor-model.h5), and display the predicted tumor class and associated probabilities.
- It also includes a training pipeline (train.py) that can retrain the CNN on the brain-tumor-dataset and produce an updated model file.

##### File structure
- Top-level files:
- main.py – the Streamlit app entry point (UI + inference logic)
- train.py – the training pipeline script
- brain-tumor-model.h5 – the serialized Keras/TensorFlow model
- brain-tumor-dataset/ – raw MRI images organized by class for training
- brain-tumor-classification.ipynb – exploratory notebook
- requirements.txt – Python dependencies
- .streamlit/config.toml – Streamlit runtime configuration
- .devcontainer/ – VS Code devcontainer settings
- Pattern: single-page web app (frontend + backend combined in main.py) + separate training workflow.

##### Key insights from the README
- Tech stack: Python 3.7+, Streamlit for UI, TensorFlow/Keras for model, Pillow for image I/O.
- Workflow:
1. User uploads image
2. Preprocessing (grayscale + resize to 300×300)
3. Model prediction
4. Class & probabilities
- Optional: retrain model via train.py using the organized dataset.

##### Main components
a. Presentation layer (Streamlit UI in main.py)
b. Preprocessing module (image loader, convert-to-grayscale, resize)
c. Inference engine (TensorFlow/Keras model loader + predictor)
d. Data storage
– Model storage (brain-tumor-model.h5)
– Training data (brain-tumor-dataset/)
e. Training pipeline (train.py)
f. External libraries/frameworks (Streamlit, TensorFlow, Pillow)
g. Optional: Dev environment config (.devcontainer)

##### Relationships and interactions
- User → Streamlit UI: upload MRI image file
- UI → Preprocessing: pass raw image
- Preprocessing → Inference engine: standardized image array
- Inference engine → Model file: loads brain-tumor-model.h5 once at start
- Inference engine → Output: class labels + probability scores
- UI ← Inference results: display to user
- Training pipeline (train.py) → Reads brain-tumor-dataset → Applies data augmentation/preprocessing → Trains CNN → Writes updated brain-tumor-model.h5
- Devcontainer config provides a reproducible dev/workspace environment.

##### Architectural patterns and design principles
- Layered architecture:
- Presentation (Streamlit)
- Application logic (preprocessing + prediction)
- Model artifact layer (stored H5)
- Data persistence (dataset folder)
- Single-process, event-driven web server
- Separation of concerns: main.py focuses on inference/UI, train.py on model training.

##### Diagramming recommendations
- “Streamlit App (main.py)”
- “Image Preprocessor”
- “CNN Inference Engine (TensorFlow)”
- “Model Storage (.h5)”
- “Training Pipeline (train.py)”
- “Dataset Storage (brain-tumor-dataset/)”
- Blue for user-facing/UI
- Green for data processing modules
- Orange for ML model artifacts
- Gray for storage/configuration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Inference Flow
    subgraph "Inference Flow"
        direction TB
        User["User"]:::external
        StreamlitApp["Streamlit App\n(main.py)\n[Streamlit, Pillow]"]:::ui
        Preprocessor["Image Preprocessor\n(grayscale & resize)"]:::dataProcessing
        InferenceEngine["CNN Inference Engine\n(TensorFlow/Keras)"]:::ml
        ModelStorage["Model Storage\n(brain-tumor-model.h5)"]:::storage
        Results["Prediction Results\n(class + probabilities)"]:::ui

        User -->|"uploads MRI image"| StreamlitApp
        StreamlitApp -->|"raw image file"| Preprocessor
        Preprocessor -->|"standardized array"| InferenceEngine
        InferenceEngine -->|"loads model"| ModelStorage
        InferenceEngine -->|"tensor -> model.predict()"| Results
        Results -->|"display output"| StreamlitApp
    end

    %% Training Flow
    subgraph "Training Flow"
        direction TB
        TrainingPipeline["Training Pipeline\n(train.py)\n[data loading, augmentation, training]"]:::dataProcessing
        DatasetStorage["Dataset Storage\n(brain-tumor-dataset/)"]:::storage
        NewModel["Updated Model\n(brain-tumor-model.h5)"]:::storage

        TrainingPipeline -->|"reads images"| DatasetStorage
        TrainingPipeline -->|"applies augmentation\n& preprocessing"| Preprocessor
        Preprocessor -->|"training tensors"| TrainingPipeline
        TrainingPipeline -->|"exports model"| NewModel
    end

    %% Support & Configurations
    subgraph "Support Components"
        direction TB
        ConfigStreamlit["Streamlit Runtime Config\n(.streamlit/config.toml)"]:::storage
        DevContainer["Dev Container Config\n(.devcontainer/devcontainer.json)"]:::storage
        Requirements["Project Dependencies\n(requirements.txt)"]:::ext
        Notebook["Exploratory Notebook\n(brain-tumor-classification.ipynb)"]:::ext

        ConfigStreamlit
        DevContainer
        Requirements
        Notebook
    end

    %% Click Events
    click StreamlitApp "https://github.com/vivek02sharma/neuroscan/blob/main/main.py"
    click Preprocessor "https://github.com/vivek02sharma/neuroscan/blob/main/main.py"
    click InferenceEngine "https://github.com/vivek02sharma/neuroscan/blob/main/main.py"
    click ModelStorage "https://github.com/vivek02sharma/neuroscan/blob/main/brain-tumor-model.h5"
    click DatasetStorage "https://github.com/vivek02sharma/neuroscan/tree/main/brain-tumor-dataset/"
    click TrainingPipeline "https://github.com/vivek02sharma/neuroscan/blob/main/train.py"
    click ConfigStreamlit "https://github.com/vivek02sharma/neuroscan/blob/main/.streamlit/config.toml"
    click DevContainer "https://github.com/vivek02sharma/neuroscan/blob/main/.devcontainer/devcontainer.json"
    click Requirements "https://github.com/vivek02sharma/neuroscan/blob/main/requirements.txt"
    click Notebook "https://github.com/vivek02sharma/neuroscan/blob/main/brain-tumor-classification.ipynb"

    %% Styles
    classDef ui fill:#89CFF0,stroke:#333,stroke-width:1px
    classDef dataProcessing fill:#98FB98,stroke:#333,stroke-width:1px
    classDef ml fill:#FFA500,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef ext fill:#E6E6FA,stroke:#333,stroke-width:1px
```
