# muvva-adityavardhan/forest-fire-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/muvva-adityavardhan/forest-fire-prediction
- Repository: https://github.com/muvva-adityavardhan/forest-fire-prediction

## Overview

##### Project type and purpose
- This is a full-stack, web-based Machine Learning application for forest-fire prediction.
- Backend: Python + Flask serving a prediction service.
- Frontend: HTML/CSS templates for user input and result display.
- ML pipeline: data preprocessing → model training notebooks → model artifacts (Random Forest, KNN, Decision Tree) → prediction.

##### File structure
- Top-level files:
– data (2003.csv … 2021.csv) – raw time-series dataset
– Jupyter notebooks (ForestFires.ipynb, etc.) – exploratory analysis & model training
– app.py – Flask application entry point (routes + controller logic)
– model scripts (model.py, knn_model.py, decisiontree_model.py) – model-wrapping code
– serialized artifacts (rf_model.pkl, knn_model.pkl, dt_model.pkl, scaler.pkl)
– requirements.txt – dependencies
- Directories:
– templates/ – HTML files (index.html, manual.html, map.html, result.html) → view layer
– static/ – CSS/JS/images → presentation assets
- No microservices; follows an MVC-style pattern within a single Flask service.

##### README for additional insights
- Confirms Random Forest classifier (accuracy 99.84%) built on VPD and environmental variables.
- Web interface for manual VPD & location entry; real-time prediction.
- Future scope indicates potential satellite imagery or API-driven real-time data.

a. Main components:
1. User Browser (UI)
2. Static Assets Server (CSS, JS, images)
3. Flask Web Application
– Route Handlers (Controllers)
– Model Loading Service
– Prediction Engine
4. Model Artifacts Storage (Pickle files + Scaler)
5. Data Store (CSV files or external DB if extended)
6. (Optional) Model Training Pipeline (Jupyter Notebooks, Data Preprocessor, Model Trainer)
7. External Services (future: Satellite Imagery API, Weather API)
b. Relationships & data flow:
– User requests page → Flask serves HTML + static assets
– User submits VPD & location → HTTP POST to Flask route
– Flask controller loads scaler & model from artifact store (once or cached)
– Input data → Preprocessor → Model.predict() → result
– Controller renders result.html (or map.html) with prediction
c. Architectural patterns / design principles:
– MVC:
- Model = serialized ML artifacts + preprocessing logic
- View = Jinja templates in templates/ + static files
- Controller = Flask routes in app.py
– Separation of concerns: data ingestion/training vs. inference service
– Single-process, single-service fashion; can evolve into microservices (e.g., separateInference API)
d. Key technologies & frameworks:
– Python + Flask for web server
– scikit-learn for ML models
– pandas/numpy for data processing
– joblib/pickle for model serialization
– HTML/CSS (templates & static) for frontend

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["User Browser"]:::frontend
        subgraph "HTML Templates"
            direction TB
            Index["index.html"]:::frontend
            Manual["manual.html"]:::frontend
            Map["map.html"]:::frontend
            Result["result.html"]:::frontend
        end
        StaticAssets["Static Assets (CSS/JS/Images)"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FlaskApp["Flask Web Application (app.py)"]:::app
        Controllers["Flask Controllers"]:::app
        subgraph "Inference Engine"
            direction TB
            Preprocessor["Data Preprocessor"]:::app
            RFModel["model.py"]:::app
            KNNModel["knn_model.py"]:::app
            DTModel["decisiontree_model.py"]:::app
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        subgraph "Model Artifacts Storage"
            direction TB
            RFArtifact["rf_model.pkl"]:::data
            KNNArtifact["knn_model.pkl"]:::data
            DTArtifact["dt_model.pkl"]:::data
            Scaler["scaler.pkl"]:::data
        end
        subgraph "Raw Dataset"
            direction TB
            CSV["2003.csv … 2021.csv"]:::data
        end
    end

    %% Training Pipeline
    subgraph "Model Training Pipeline"
        direction TB
        Notebook1["ForestFires.ipynb"]:::external
        Notebook2["Checking1.ipynb"]:::external
        Notebook3["IDEA.ipynb"]:::external
    end

    %% Configuration
    Config["requirements.txt / README.md"]:::external

    %% External Future Services
    subgraph "External Services (Future)"
        direction TB
        WeatherAPI["Weather API"]:::external
        SatelliteAPI["Satellite Imagery API"]:::external
    end

    %% Connections
    Browser -->|requests HTML| Index
    Browser -->|requests HTML| Manual
    Browser -->|requests HTML| Map
    Browser -->|requests HTML| Result
    Browser -->|requests static| StaticAssets

    Browser -->|POST /predict| Controllers
    Controllers -->|invoke preprocessing| Preprocessor
    Preprocessor -->|loads model code| RFModel
    Preprocessor -->|loads model code| KNNModel
    Preprocessor -->|loads model code| DTModel
    RFModel -->|loads artifact| RFArtifact
    KNNModel -->|loads artifact| KNNArtifact
    DTModel -->|loads artifact| DTArtifact
    Preprocessor -->|loads scaler| Scaler
    Controllers -->|reads raw data| CSV
    Controllers -->|sends result| Result

    Controllers -->|future data| WeatherAPI
    Controllers -->|future imagery| SatelliteAPI

    Notebook1 -->|trains model| RFArtifact
    Notebook2 -->|trains model| KNNArtifact
    Notebook3 -->|trains model| DTArtifact
    CSV -->|used by notebooks| Notebook1
    CSV -->|used by notebooks| Notebook2
    CSV -->|used by notebooks| Notebook3
    Config --> FlaskApp

    %% Click Events
    click Index "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/templates/index.html"
    click Manual "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/templates/manual.html"
    click Map "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/templates/map.html"
    click Result "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/templates/result.html"
    click StaticAssets "https://github.com/muvva-adityavardhan/forest-fire-prediction/tree/main/static/"
    click FlaskApp "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/app.py"
    click Controllers "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/app.py"
    click RFModel "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/model.py"
    click KNNModel "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/knn_model.py"
    click DTModel "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/decisiontree_model.py"
    click RFArtifact "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/rf_model.pkl"
    click KNNArtifact "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/knn_model.pkl"
    click DTArtifact "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/dt_model.pkl"
    click Scaler "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/scaler.pkl"
    click CSV "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/2003.csv … 2021.csv"
    click Notebook1 "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/ForestFires.ipynb"
    click Notebook2 "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/Checking1.ipynb"
    click Notebook3 "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/IDEA.ipynb"
    click Config "https://github.com/muvva-adityavardhan/forest-fire-prediction/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#21618C
    classDef app fill:#D5F5E3,stroke:#196F3D
    classDef data fill:#FCF3CF,stroke:#B7950B
    classDef external fill:#EAECEE,stroke:#566573
```
