# ayushsyntax/skycast architecture

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

- Interactive diagram: https://gitdiagram.com/ayushsyntax/skycast
- Repository: https://github.com/ayushsyntax/skycast

## Overview

##### Project Type and Purpose
- This is a monolithic full-stack web application built with Streamlit (Python) for real-time rainfall prediction.
- It bundles a trained XGBoost model (`final_model.pkl`), data preprocessing/EDA utilities (`projectrain.py`), and a Streamlit front-end (`app.py`).

##### File Structure
- Top-level files:
- `app.py` – main Streamlit application (UI, input handling, prediction, post-processing, display).
- `projectrain.py` – standalone scripts for exploratory data analysis and preprocessing.
- `final_model.pkl` – serialized XGBoost classifier.
- `requirements.txt` – Python dependencies (streamlit, xgboost, pandas, numpy, seaborn, matplotlib, etc.).
- `venv/` – Python virtual environment.
- No separate frontend/backend directories: everything runs together under a single Python process.
- No external database: model and preprocessing run in memory, inputs come from user via Streamlit widgets.

##### Extract Architecture Insights from README
- Streamlit framework handles HTTP requests, renders UI, and calls Python functions.
- Input validation is built into `app.py` using Streamlit form controls and Python checks.
- Preprocessing and feature engineering: part built into `app.py`, extended by code in `projectrain.py`.
- Prediction stage: load `final_model.pkl` and run XGBoost inference.
- Post-processing: map probability → risk level → advice.

##### Main Components and Relationships
a. User Interface (Streamlit Frontend)
- Widgets: date picker, sliders, dropdowns.
- Submits input to the application logic.
b. Input Validation & Preprocessing Module
- Performs sanity checks on user data.
- Transforms date to cyclical features.
- Combines humidity, temperature range, cloud cover into engineered features.
c. Model Inference Engine
- Loads `final_model.pkl` once at startup.
- Executes XGBoost classifier to produce probability score.
d. Post-Processing & Output Renderer
- Applies risk thresholds.
- Chooses advice text.
- Renders probability, risk level, and advice back to UI.
e. Exploratory Data Analysis Toolkit (`projectrain.py`)
- Separate component for offline data analysis (not called in production flow).
- Uses pandas, numpy, seaborn, matplotlib to generate plots.
f. Runtime Environment
- Python 3.x in virtual environment.
- Streamlit’s HTTP server exposes `app.py`.

##### Architectural Patterns and Principles
- Monolithic modular design: clear separation between UI, preprocessing, inference, and post-processing, but all within one service.
- Single-process, event-driven I/O via Streamlit.
- Dependency injection at import time: `final_model.pkl` loaded once.
- Reusable EDA scripts kept separate to avoid runtime overhead.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actor
    User["User (Web Browser)"]:::actor

    %% Streamlit Application Service
    subgraph "Streamlit Application Service"
        UI["Streamlit UI Layer"]:::compute
        Pre["Validation & Preprocessing"]:::compute
        Infr["Model Inference Engine"]:::compute
        Post["Post-Processing & Rendering"]:::compute
    end

    %% Resources & Tools
    subgraph "Resources & Tools"
        Model["final_model.pkl"]:::data
        EDA["projectrain.py"]:::data
        Env["venv/"]:::tool
        Req["requirements.txt"]:::tool
    end

    %% Data Flows
    User -->|HTTP request / form data| UI
    UI -->|raw input| Pre
    Pre -->|feature vector| Infr
    Infr -->|probability score| Post
    Post -->|risk & advice| UI

    %% Artifact Links
    Infr -->|loads model| Model
    EDA -.->|offline analysis| UI

    %% Dependency Links
    Env -->|runtime deps| UI
    Req -->|runtime deps| UI

    %% Click Events
    click UI "https://github.com/ayushsyntax/skycast/blob/main/app.py"
    click Pre "https://github.com/ayushsyntax/skycast/blob/main/app.py"
    click Infr "https://github.com/ayushsyntax/skycast/blob/main/app.py"
    click Post "https://github.com/ayushsyntax/skycast/blob/main/app.py"
    click EDA "https://github.com/ayushsyntax/skycast/blob/main/projectrain.py"
    click Model "https://github.com/ayushsyntax/skycast/blob/main/final_model.pkl"
    click Env "https://github.com/ayushsyntax/skycast/tree/main/venv/"
    click Req "https://github.com/ayushsyntax/skycast/blob/main/requirements.txt"

    %% Styles
    classDef compute fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef data fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef actor fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef tool fill:#ECEFF1,stroke:#455A64,color:#263238
```
