# rrohit0/brain-tumor-detection-cnn architecture

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

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

## Overview

##### Main Components
- Frontend Client:
– Built in React with TypeScript.
– Uses TailwindCSS and shadcn UI components.
– Contains various pages (Home, About, Dataset, Contact, Privacy, Terms, etc.) and many reusable UI components (e.g., FileUploader, ImagePreviewSection, ResultsSection).
– Implements context (BrainTumorContext) and custom hooks.
- Backend Server:
– Built with Express.js using Node.js.
– Handles routes for file uploads, tumor detection, model training, and dataset management.
– Responsible for image processing (likely using Sharp) and interfacing with the CNN for predictions.
- Neural Network Model:
– Stored in the “model” directory as a JSON configuration and binary weight file.
– Utilizes TensorFlow.js/TensorFlow Node.js for processing uploaded MRI scans.
- Dataset Management:
– Directories (“dataset/no” and “dataset/yes”) and functionality for uploading and training on new MRI images.
- Additional Utilities:
– A PDF generation script (generate_pdf.js) and a poster file (poster.html) that are used to produce presentations or detailed reports.
– Shared schemas and configurations (e.g., shared/schema.ts, drizzle.config.ts) suggest standardized data handling.
- File Storage:
– The “uploads” directory (with subdirectories for original and processed images) manages the lifecycle of input data and derived outputs.

##### Relationships and Interactions
- The Frontend communicates with the Backend via API routes:
– File uploads, dataset management, and triggering model prediction or training are sent as HTTP requests.
- The Backend processes incoming images:
– It routes the request to either the “upload”, “model”, or “train” modules.
– It accesses the CNN (stored in the model directory) to perform inference and returns the results to the frontend.
- The Backend uses image processing libraries for pre/post-processing of MRI scans.
- The system supports exporting detailed reports:
– The generate_pdf.js and Puppeteer are invoked to convert HTML (e.g., poster.html) to PDFs, potentially as part of a reporting service.
- Data storage (uploads and dataset directories) ensures persistence and reusability:
– Uploaded images are stored and optionally processed for future model training or analysis.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
– Frontend vs. Backend responsibilities are clearly defined.
– UI components are modular, and backend routes/modules handle specific tasks (upload, train, inference).
- RESTful API Design:
– The server exposes routes (likely detailed in server/routes.ts) which are designed to handle different aspects of the application (upload, train, model inference).
- Modular Design:
– The project structure separates UI components, server logic, and business logic (model operations and dataset management) into different folders.
- Scalability:
– With distinct modules for dataset management and model training, future enhancements (like multi-class classification or batch processing) can be easily incorporated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React & TailwindCSS)"
        FE1["React App"]
        FE2["Pages & Routing"]
        FE3["Dataset Page"]
        FE4["UI Components"]
        FE5["FileUploader Component"]
        FE6["ImagePreviewSection Component"]
        FE7["ResultsSection Component"]
        FE8["DatasetManagement Component"]
        FE9["BrainTumorContext & Hooks"]
    end

    %% Backend Layer
    subgraph "Backend (Express.js & Node.js)"
        BE1["API Server"]
        BE2["Routes"]
        BE3["Upload Handler"]
        BE4["Model Handler"]
        BE5["Training Handler"]
        BE6["Storage Service"]
    end

    %% Data & Model Layer
    subgraph "Data & Model"
        %% Neural Network Model
        DM1["CNN Model"]
        DM2["Model Config (model.json)"]
        DM3["Weights (weights.bin)"]
        %% Dataset Directories
        DM4["Dataset Directories"]
        DM5["No Tumor Dataset"]
        DM6["Yes Tumor Dataset"]
        %% File Storage
        DM7["File Storage"]
        DM8["Original Uploads"]
        DM9["Processed Uploads"]
        %% Utilities (PDF & Reporting)
        DM10["Utilities"]
        DM11["PDF Generator"]
        DM12["Poster Template"]
        %% Shared Configs & Schemas
        DM13["Shared Configs & Schemas"]
        DM14["Shared Schema"]
        DM15["Drizzle Config"]
    end

    %% Internal Data & Model relationships
    DM1 --> DM2
    DM1 --> DM3
    DM4 --> DM5
    DM4 --> DM6
    DM7 --> DM8
    DM7 --> DM9
    DM10 --> DM11
    DM10 --> DM12
    DM13 --> DM14
    DM13 --> DM15

    %% Frontend internal relationships
    FE1 --> FE2
    FE2 --> FE3
    FE2 --> FE9
    FE1 --> FE4
    FE4 --> FE5
    FE4 --> FE6
    FE4 --> FE7
    FE4 --> FE8

    %% Frontend to Backend interactions
    FE5 -->|"HTTP_POST/upload"| BE2
    FE3 -->|"DatasetRequest"| BE2
    FE7 -->|"DisplayResults"| BE4
    FE8 -->|"DatasetManageAPI"| BE2

    %% Backend internal interactions
    BE1 --> BE2
    BE2 --> BE3
    BE2 --> BE4
    BE2 --> BE5
    BE2 --> BE6
    BE3 -->|"StoreFiles"| DM7
    BE3 -->|"PreprocessImage"| BE4
    BE4 -->|"LoadModel"| DM1
    BE4 -->|"ReturnInference"| FE7
    BE5 -->|"UseDataset"| DM4
    BE5 -->|"UpdateModel"| DM1
    BE6 -->|"ManageStorage"| DM7

    %% Backend to Utilities
    BE2 -->|"GenerateReport"| DM10

    %% Backend usage of Shared Configs
    BE1 -->|"UseConfigs"| DM13

    %% Click Events for Frontend
    click FE1 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/client/"
    click FE3 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/client/src/pages/Dataset.tsx"
    click FE5 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/client/src/components/FileUploader"
    click FE6 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/client/src/components/ImagePreviewSection"
    click FE7 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/client/src/components/ResultsSection"
    click FE8 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/client/src/components/DatasetManagement.tsx"
    click FE9 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/client/"

    %% Click Events for Backend
    click BE1 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/server/index.ts"
    click BE2 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/server/routes.ts"
    click BE3 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/server/upload.ts"
    click BE4 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/server/model.ts"
    click BE5 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/server/train.ts"
    click BE6 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/server/storage.ts"

    %% Click Events for Neural Network Model
    click DM2 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/model/model.json"
    click DM3 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/model/weights.bin"

    %% Click Events for Dataset Directories
    click DM5 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/dataset/no"
    click DM6 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/dataset/yes"

    %% Click Events for Utilities and Shared Configs
    click DM11 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/generate_pdf.js"
    click DM12 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/poster.html"
    click DM14 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/shared/schema.ts"
    click DM15 "https://github.com/rrohit0/brain-tumor-detection-cnn/blob/main/drizzle.config.ts"

    %% Click Events for File Storage Directories
    click DM8 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/uploads/original"
    click DM9 "https://github.com/rrohit0/brain-tumor-detection-cnn/tree/main/uploads/processed"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef datalayer fill:#FFFFE0,stroke:#000,stroke-width:2px;
    classDef utility fill:#FFB6C1,stroke:#000,stroke-width:2px;

    class FE1,FE2,FE3,FE4,FE5,FE6,FE7,FE8,FE9 frontend;
    class BE1,BE2,BE3,BE4,BE5,BE6 backend;
    class DM1,DM2,DM3,DM4,DM5,DM6,DM7,DM8,DM9,DM13 datalayer;
    class DM10,DM11,DM12,DM14,DM15 utility;
```
