# tusharsinha007/climatepredictor architecture

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

- Interactive diagram: https://gitdiagram.com/tusharsinha007/climatepredictor
- Repository: https://github.com/tusharsinha007/climatepredictor

## Overview

##### Project Type and Purpose
- This is a full-stack climate tracking application that gathers weather data from OpenWeatherMap and integrates with several AWS services (Lambda, S3, API Gateway, CloudWatch) to store, process, and display weather data.
- It includes a frontend for data visualization and backend components (implemented in Python) that are deployed as AWS Lambda functions.

##### Analyzing the File Structure
- The top-level files (README.md, api.py, live_weather_api.py, weather_prediction.py) hint at backend logic, possibly used as AWS Lambda functions.
- The “frontend” directory contains the web assets (HTML, CSS, JS) that provide the interactive user interface – note files like index.html and aws-config.js.
- The “mock” directory holds sample CSV and JSON files used for testing or simulating various weather scenarios.
- Other CSV files (weather_forecast.csv, processed_chennai_weather.csv) indicate processed data which is likely stored and referenced in S3.
- The requirements.txt shows third-party dependencies.

##### Key Components Identified
a. Frontend
– Located in the “frontend” folder (index.html, CSS, JS).
– Interacts with AWS API Gateway (configured via aws-config.js) to retrieve weather data.

b. AWS Lambda Functions
– Two primary Lambda functions are described: one for current weather data collection (e.g., implemented in lambda_function.py or live_weather_api.py) and one for retrieving historical data (referenced in the README).
– They are responsible for invoking the OpenWeatherMap API, processing weather data, and storing/retrieving data from S3.

c. Amazon API Gateway
– Serves as the RESTful API endpoint for the frontend to interact with.
– The README details endpoints like /weather and /historical which map to corresponding Lambda functions.

d. Amazon S3
– Used for storage of the weather data, largely in CSV format (as evidenced by the CSV files in the file tree and README instructions to create an S3 bucket).

e. Amazon CloudWatch
– Used for monitoring and logging the activity of Lambda functions and overall system performance.

f. External Weather API (OpenWeatherMap)
– The data source from which real-time weather information is retrieved.

g. AWS EventBridge (CloudWatch Events)
– Used to schedule the regular invocation of the weather collection Lambda function.

- The Frontend (user’s web browser) sends HTTP requests to the API Gateway (configured with endpoints such as /weather and /historical).
- API Gateway routes these requests to the respective AWS Lambda functions.
- The “Data Collection Lambda” function connects to the external OpenWeatherMap API to fetch current weather data.
- Once retrieved, this Lambda function stores weather data (in CSV format) into the Amazon S3 bucket.
- The “Data Retrieval Lambda” function fetches historical weather data from S3 when requested.
- Both Lambda functions log events to CloudWatch for monitoring purposes.
- AWS EventBridge is configured to trigger the Data Collection Lambda function periodically.

[User / Browser]
│
▼
[Frontend (index.html, JS)]
│  (configured via aws-config.js)
▼
[Amazon API Gateway] ──► Routes REST requests ──► [AWS Lambda Functions]
│                                         ├── (Data Collection Lambda: calls OpenWeatherMap API ──► [OpenWeatherMap API])
│                                         │                          └─► Stores CSV data into [Amazon S3]
│                                         └── (Data Retrieval Lambda: reads from Amazon S3)
│
▼
[Amazon CloudWatch] (Monitoring & Logging of Lambda functions)

- Additional supporting interactions:
- AWS EventBridge periodically triggers the Data Collection Lambda.

##### Architectural Patterns
- The application follows a decoupled architecture where the frontend and backend are clearly separated.
- It relies on serverless components (AWS Lambda functions) to reduce management overhead.
- There is a clear request-response pattern between the frontend and backend through the API Gateway.
- The storage layer is segregated from the compute logic (data stored in S3 and processed in Lambda).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User/Browser"]:::support

    subgraph "Frontend Layer"
        FE["index.html"]:::frontend
        AC["aws-config.js"]:::frontend
    end

    U --> FE
    FE --> AC
    AC --> AG["API Gateway (api.py)"]:::aws

    subgraph "AWS Lambda Functions"
        DCL["Data Collection Lambda (live_weather_api.py)"]:::lambda
        DRL["Data Retrieval Lambda (api.py)"]:::lambda
    end

    AG --> DCL
    AG --> DRL

    EB["EventBridge"]:::aws
    EB --> DCL

    DCL -->|"FetchWeather"| OWM["OpenWeatherMap API"]:::external

    DCL -->|"StoreCSV"| CSV1["processed_chennai_weather.csv"]:::aws
    DCL -->|"StoreCSV"| CSV2["weather_forecast.csv"]:::aws
    DRL -->|"RetrieveCSV"| CSV1

    DCL --> CW["CloudWatch"]:::aws
    DRL --> CW

    MD["Mock Data (mock/)"]:::support
    DEP["Dependencies (requirements.txt)"]:::support

    %% Click Events
    click FE "https://github.com/tusharsinha007/climatepredictor/blob/master/frontend/index.html"
    click AC "https://github.com/tusharsinha007/climatepredictor/blob/master/frontend/js/aws-config.js"
    click AG "https://github.com/tusharsinha007/climatepredictor/blob/master/api.py"
    click DCL "https://github.com/tusharsinha007/climatepredictor/blob/master/live_weather_api.py"
    click DRL "https://github.com/tusharsinha007/climatepredictor/blob/master/api.py"
    click CSV1 "https://github.com/tusharsinha007/climatepredictor/blob/master/processed_chennai_weather.csv"
    click CSV2 "https://github.com/tusharsinha007/climatepredictor/blob/master/weather_forecast.csv"
    click MD "https://github.com/tusharsinha007/climatepredictor/tree/master/mock/"
    click DEP "https://github.com/tusharsinha007/climatepredictor/blob/master/requirements.txt"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef lambda fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef aws fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef support fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
