# isatyamks/uhi-detector architecture

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

- Interactive diagram: https://gitdiagram.com/isatyamks/uhi-detector
- Repository: https://github.com/isatyamks/uhi-detector

## Overview

##### Project Type and Purpose

**Project Type:**
GeoSmartPredict is a **full-stack, AI-powered platform** designed for detecting and forecasting Urban Heat Islands (UHIs). It integrates data collection, machine learning modeling, visualization, and user interaction through a web-based dashboard.

**Purpose:**
- **Detection:** Identify existing UHIs using satellite imagery and environmental data.
- **Prediction:** Forecast future temperature trends and UHI expansion.
- **Actionable Insights:** Provide recommendations to urban planners and policymakers for UHI mitigation.

##### File Structure

**Top-Level Directories and Files:**
- **data/**: Contains geospatial data (geojson), machine learning models (.hdf5), and raster files in JSON format.
- **notebooks/**: Houses Jupyter notebooks for data analysis, model building/testing, and related checkpoints.
- **src/**: Includes source code, specifically `weather_data.py` for handling weather-related data.
- **testing/**: Contains scripts for testing maps, regions of interest (ROI), and various versions.
- **readme.md**: Project documentation.
- **requirements.txt**: Lists project dependencies.

**Architectural Indicators:**
- Presence of **data**, **src**, and **notebooks** suggests a strong emphasis on data processing and machine learning.
- **Testing/** indicates a focus on validating different components.
- Use of **.hdf5** files points to trained machine learning models.
- **Raster_files** and **geojson** data suggest geospatial data handling.

##### README for Additional Insights

**Technologies and Tools:**
- **Data Sources:** Google Earth Engine (GEE), OpenWeatherMap API, OpenStreetMap.
- **Programming Languages & Frameworks:** Python with libraries like Numpy, Pandas, Scikit-learn, TensorFlow/PyTorch, GeoPandas.
- **Visualization:** Streamlit/Dash, Leaflet.js.
- **Database:** MongoDB.
- **Deployment:** Heroku, AWS, GCP.

**Workflow Highlights:**
1. **Data Collection & Preprocessing:** Handling large geospatial datasets, feature engineering.
2. **UHI Detection & Predictive Modeling:** Utilizing ML models for classification and time-series forecasting.
3. **Visualization & Dashboard Development:** Interactive maps and user-facing web applications.
##### Deployment: Hosting the dashboard and managing data storage.

**a. Identify the Main Components:**

##### Data Ingestion Layer
- **Sources:** Google Earth Engine, OpenWeatherMap API, OpenStreetMap.
- **Components:** Data collectors/scripts (`weather_data.py`), data storage (MongoDB).

##### Data Processing & Preprocessing
- **Tools:** Python scripts, Jupyter Notebooks (e.g., `model_building.ipynb`).
- **Processes:** Geospatial alignment, data cleaning, feature engineering.

##### Machine Learning Layer
- **Models:**
- **UHI Detection:** Classification models.
- **Predictive Modeling:** LSTM networks for time-series forecasting.
- **Storage:** Trained models (`.hdf5` files in `data/models/`).

##### Backend Services
- **API Layer:** Interfaces between frontend and backend, handling requests.
- **Business Logic:** Processes data, runs models, manages workflows.

##### Database
- **MongoDB:** Stores user data, analysis results, UHI metrics.

##### Frontend/User Interface
- **Dashboard:** Built with Streamlit or Dash.
- **Interactive Maps:** Utilizes Leaflet.js for geospatial visualization.

##### Testing & Validation
- **Testing Scripts:** Located in `testing/` directory.
- **Continuous Integration:** Ensures reliability of components.

##### Deployment Infrastructure
- **Hosting Platforms:** Heroku, AWS, GCP.
- **CI/CD Pipelines:** Automated deployment processes.

**b. Determine Relationships and Interactions:**

- **Data Flow:** Data is collected from external sources → stored in MongoDB → processed and preprocessed via backend services → fed into machine learning models → results stored back in MongoDB → accessed by frontend dashboard for visualization.
- **User Interaction:** Users interact with the frontend dashboard → frontend communicates with backend APIs → backend retrieves/manipulates data and models → responses sent back to frontend for display.
- **Testing Feedback Loop:** Testing scripts validate backend and frontend components → feedback used to refine models and services.

**c. Highlight Architectural Patterns and Design Principles:**

- **Modular Architecture:** Separation of concerns with distinct layers (Data Ingestion, Processing, ML, Backend, Frontend).
- **Microservices (if applicable):** Potential for scaling individual services like data processing or model serving.
- **MVC Pattern:** Likely separation between data models, business logic, and user interface in the dashboard.
- **Scalability and Maintainability:** Use of cloud services and modular codebase supports scalability and ease of maintenance.

**d. Include Relevant Technologies, Frameworks, or Libraries:**

- **Data Handling:** Python, GeoPandas, Numpy, Pandas.
- **Machine Learning:** Scikit-learn, TensorFlow/PyTorch.
- **Visualization:** Matplotlib, Seaborn, Leaflet.js.
- **Web Frameworks:** Streamlit or Dash.
- **Database:** MongoDB.
- **Deployment:** Heroku, AWS, GCP.

##### Emphasizing Detail and Essential Architectural Elements

- **Granular Components:** Break down each main component into sub-components where necessary (e.g., within Data Processing: Geospatial Alignment, Feature Engineering).
- **Interactions and Dependencies:** Clearly show how each component interacts with others, ensuring that all data flows and service calls are represented.
- **Scalability Considerations:** If applicable, indicate how components can scale (e.g., multiple instances of backend services).
- **Security Layers:** Represent any authentication or security measures if present.
- **Deployment Architecture:** Show how the application is deployed across platforms like Heroku or AWS, including any CDN or load balancers if used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    GE["Google Earth Engine"]:::external
    OWM["OpenWeatherMap API"]:::external
    OSM["OpenStreetMap"]:::external

    %% Subgraphs and modules
    subgraph "Data Ingestion Layer"
        WD["Weather Data Collector"]:::data_ingestion
        GE -->|"data source"| WD
        OWM -->|"data source"| WD
        OSM -->|"data source"| WD
        WD -->|"stores data to"| DB["MongoDB"]:::database
    end

    subgraph "Data Processing & Preprocessing"
        MB["Model Building Notebook"]:::processing
        MT["Model Testing Notebook"]:::processing
        LST["LST Info"]:::processing
        WD -->|"provides data to"| MB
        WD -->|"provides data to"| MT
        WD -->|"provides data to"| LST
    end

    subgraph "Machine Learning Layer"
        UHI["UHI Detection Model"]:::ml
        LSTM["LSTM Forecasting Model"]:::ml
        MODEL["Trained Model"]:::ml
        MB -->|"trains"| MODEL
        MODEL -->|"saved to"| DB
    end

    subgraph "Backend Services"
        API["API Layer"]:::backend
        BL["Business Logic"]:::backend
        DB -->|"provides data to"| BL
        BL -->|"exposes via"| API
    end

    subgraph "Frontend/User Interface"
        Dashboard["Dashboard (Streamlit/Dash)"]:::frontend
        Maps["Interactive Maps (Leaflet.js)"]:::frontend
        API -->|"sends data to"| Dashboard
        Dashboard -->|"displays"| Maps
    end

    subgraph "Testing & Validation"
        MapIB["map_ib.py"]:::testing
        MapTesting["map_testing.py"]:::testing
        ROI["roi.py"]:::testing
        TST["tst.py"]:::testing
        V3["v3.py"]:::testing
        BL -->|"validated by"| MapIB
        BL -->|"validated by"| MapTesting
        BL -->|"validated by"| ROI
        BL -->|"validated by"| TST
        BL -->|"validated by"| V3
    end

    subgraph "Deployment Infrastructure"
        Heroku["Heroku"]:::deployment
        AWS["AWS"]:::deployment
        GCP["GCP"]:::deployment
        CI_CD["CI/CD Pipeline"]:::deployment
        API -->|"deployed on"| Heroku
        API -->|"deployed on"| AWS
        API -->|"deployed on"| GCP
        CI_CD -->|"deploys to"| Heroku
        CI_CD -->|"deploys to"| AWS
        CI_CD -->|"deploys to"| GCP
    end

    %% Click Events
    click WD "https://github.com/isatyamks/uhi-detector/blob/main/src/weather_data.py"
    click MB "https://github.com/isatyamks/uhi-detector/blob/main/notebooks/model_building.ipynb"
    click MT "https://github.com/isatyamks/uhi-detector/blob/main/notebooks/model_testing.ipynb"
    click LST "https://github.com/isatyamks/uhi-detector/blob/main/notebooks/lst_info.json"
    click MODEL "https://github.com/isatyamks/uhi-detector/blob/main/data/models/landcover_25_epochs_resnet50_backbone_batch16_freeze_iou_0.86.hdf5"
    click MapIB "https://github.com/isatyamks/uhi-detector/blob/main/testing/map_ib.py"
    click MapTesting "https://github.com/isatyamks/uhi-detector/blob/main/testing/map_testing.py"
    click ROI "https://github.com/isatyamks/uhi-detector/blob/main/testing/roi.py"
    click TST "https://github.com/isatyamks/uhi-detector/blob/main/testing/tst.py"
    click V3 "https://github.com/isatyamks/uhi-detector/blob/main/testing/v3.py"

    %% Styles
    classDef data_ingestion fill:#FFD700,stroke:#333,stroke-width:2px
    classDef external fill:#A9A9A9,stroke:#333,stroke-width:2px
    classDef database fill:#87CEFA,stroke:#333,stroke-width:2px
    classDef processing fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef ml fill:#98FB98,stroke:#333,stroke-width:2px
    classDef backend fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef frontend fill:#FFFACD,stroke:#333,stroke-width:2px
    classDef testing fill:#FF6347,stroke:#333,stroke-width:2px
    classDef deployment fill:#DDA0DD,stroke:#333,stroke-width:2px

    class GE,OWM,OSM external
    class DB database
    class WD data_ingestion
    class MB,MT,LST processing
    class UHI,LSTM,MODEL ml
    class API,BL backend
    class Dashboard,Maps frontend
    class MapIB,MapTesting,ROI,TST,V3 testing
    class Heroku,AWS,GCP,CI_CD deployment
```
