# zeeshanunique/weather_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/zeeshanunique/weather_prediction
- Repository: https://github.com/zeeshanunique/weather_prediction

## Overview

##### Project Type and Purpose
- This is a full-stack web application designed to forecast air pollution at various weather stations across Taiwan.
- It integrates traditional machine learning models (LSTM, ANN, Random Forest, Linear Regression, MLR) with predictions provided via Google’s Gemini API.
- The application provides a web interface for users to select a station, pollutant, and modeling approach, then displays forecasts and performance metrics.

##### Analyzing the File Structure
- Top-level Python scripts (app.py, main.py) indicate the Flask-based web server that powers the application.
- The “models” directory encapsulates multiple forecasting algorithms. Files include specialized models (ann_model.py, lstm_model.py, random_forest_model.py, regression_models.py), a base model for shared functionality (base_model.py), a preprocessing module for data handling, and a model manager to orchestrate model selection.
- The “static” (with CSS and JavaScript) and “templates” (HTML) folders form the front-end part, indicating that Flask renders a UI.
- Environment ('.env.example') and configuration files (requirements.txt) show external dependencies and API key management for Google’s Gemini API.
- Additional notebooks and scripts (weather_prediction_models.ipynb, weather_prediction_models.py) suggest exploratory data analysis or testing of prediction functionalities.

##### Key Components
a. Frontend:
- User Interface: Represent the “templates/index.html” rendered via Flask, coupled with the static files (CSS, JS) to provide an interactive webpage.
b. Backend:
- Flask Server: Combine main.py and app.py as the core server handling HTTP requests, routing, and user session management.
- Model Manager: Located in models/model_manager.py, responsible for selecting and coordinating which prediction model to execute.
- Prediction Models: Group together ann_model.py, lstm_model.py, random_forest_model.py, regression_models.py, and possibly MLR parts, managed under the “models” folder.
- Data Preprocessing: Reference models/preprocessing.py which handles incoming data (from CSVs in the data/ directory as mentioned in the README).
c. External Services:
- Google Gemini API: Highlight that predictions may leverage this API, requiring the API key (securely provided via .env).
d. Data Storage/Input:
- Although not listed explicitly in the file tree, reference the “data/” directory mentioned in the README as the source of historical air quality measurements.

##### Relationships and Interactions
- User Interaction Flow:
1. The user accesses the web UI.
2. The Flask server processes user input and triggers the corresponding prediction model.
3. The Model Manager communicates with the appropriate model (ANN, LSTM, etc.) after applying any necessary preprocessing.
4. For predictions driven by Gemini API, the server will authenticate via the stored API key and send/receive data.
5. The prediction results and performance metrics are compiled and sent back to the frontend for visualization.
- Data Flow:

##### Architectural Patterns and Technologies
- MVC/Separation of Concerns: Although it’s a relatively compact Flask app, the structure effectively separates the view (templates/static), controller (Flask routing in main.py/app.py), and model layers (all files in models/).
- Dependency Management: The project leverages environment variables and requirements.txt to manage external libraries and API keys.
- External API Integration: Highlight the integration with Google’s Gemini API as a key external dependency.

- Integration points: data ingestion (CSV files mentioned in README) and external prediction requests (Gemini API).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Layer
    subgraph "Frontend"
        IP["Index Page"]:::frontend
        CSS["CSS Styles"]:::frontend
        JS["JS Scripts"]:::frontend
    end

    %% User
    User["User"]:::userStyle

    %% Backend Layer
    subgraph "Backend"
        FS["Flask Server"]:::backend
        MM["Model Manager"]:::backend
        subgraph "Prediction Models"
            ANN["ANN Model"]:::model
            LSTM["LSTM Model"]:::model
            RF["Random Forest Model"]:::model
            REG["Regression Models"]:::model
            BM["Base Model"]:::model
        end
        DP["Data Preprocessing Module"]:::model
    end

    %% External Services
    subgraph "External Services"
        GAPI["Google Gemini API"]:::external
        CONFIG["Configuration (.env)"]:::config
    end

    %% Data Storage Layer
    subgraph "Data Storage"
        DATA[("Air Quality Data")]
    end

    %% Connections
    User -->|"initiates"| IP
    IP -->|"HTTP_request"| FS
    FS -->|"routes to"| MM
    MM -->|"selects"| ANN
    MM -->|"selects"| LSTM
    MM -->|"selects"| RF
    MM -->|"selects"| REG
    MM -->|"selects"| BM
    MM -->|"preprocesses"| DP
    DP -->|"reads"| DATA
    ANN -->|"result"| MM
    LSTM -->|"result"| MM
    RF -->|"result"| MM
    REG -->|"result"| MM
    BM -->|"result"| MM
    MM -->|"aggregates"| FS
    FS -->|"integrates"| GAPI
    FS -->|"loads"| CONFIG
    FS -->|"responds"| IP
    IP -->|"displays"| User

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef model fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef config fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef userStyle fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef database fill:#ffffff,stroke:#666666,stroke-width:2px;

    %% Click Events
    click IP "https://github.com/zeeshanunique/weather_prediction/blob/main/templates/index.html"
    click CSS "https://github.com/zeeshanunique/weather_prediction/blob/main/static/css/styles.css"
    click JS "https://github.com/zeeshanunique/weather_prediction/blob/main/static/js/app.js"
    click FS "https://github.com/zeeshanunique/weather_prediction/blob/main/app.py"
    click MM "https://github.com/zeeshanunique/weather_prediction/blob/main/models/model_manager.py"
    click ANN "https://github.com/zeeshanunique/weather_prediction/blob/main/models/ann_model.py"
    click LSTM "https://github.com/zeeshanunique/weather_prediction/blob/main/models/lstm_model.py"
    click RF "https://github.com/zeeshanunique/weather_prediction/blob/main/models/random_forest_model.py"
    click REG "https://github.com/zeeshanunique/weather_prediction/blob/main/models/regression_models.py"
    click BM "https://github.com/zeeshanunique/weather_prediction/blob/main/models/base_model.py"
    click DP "https://github.com/zeeshanunique/weather_prediction/blob/main/models/preprocessing.py"
    click CONFIG "https://github.com/zeeshanunique/weather_prediction/blob/main/.env.example"
```
