# valentin5944/weatherapp architecture

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

- Interactive diagram: https://gitdiagram.com/valentin5944/weatherapp
- Repository: https://github.com/valentin5944/weatherapp

## Overview

##### Project Type and Purpose
- This is a monolithic, desktop GUI application (built in Python) for fetching, processing, and displaying weather data from the OpenWeatherMap API.
- It demonstrates API consumption, JSON data handling, and a GUI built with the CustomTkinter library.

##### High-Level Architecture Overview
A. External Service
- OpenWeatherMap REST API
B. Application (monolith)
1. Presentation Layer (GUI)
– main.py / modules.gui.main_screen
– GUI components: side_bar, main_info, forecast_frame, forecast_component, city_weather, image
2. Business Logic Layer
– modules.weather_data (API client using requests)
3. Persistence Layer
– modules.read_json & modules.write_json (read/write to JSON files)
4. Static Resources
– static/config.json (API key and settings)
– static/weather_data.json & static/forecast.json (cached data)
C. Local File System

##### Components and Their Interactions
1. User interacts with the GUI (clicks “Search City” or refresh forecast)
2. GUI invokes Business Logic:
– calls modules.weather_data.fetch_current() / .fetch_forecast()
– weather_data reads API credentials from static/config.json
3. Business Logic sends HTTP request → OpenWeatherMap API
4. API returns JSON payload → business logic processes & transforms it
5. Processed data is passed to Persistence Layer:
– modules.write_json stores raw or formatted data in static/weather_data.json / forecast.json
6. GUI reads from modules.read_json (or receives data directly)
– modules.gui components render the latest data on screen

##### Architectural Patterns & Design Principles
- Layered Architecture: clear separation of GUI, business logic, and persistence.
- Modular Design: each feature (API client, JSON I/O, GUI widget) is a self-contained module.
- Single Responsibility: read_json/write_json only handle file I/O; weather_data only handles API calls; gui modules only handle rendering.

##### Technologies & Frameworks
- Python 3.x
- CustomTkinter for GUI
- requests for HTTP
- json (stdlib) for data serialization
- venv for isolation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Service
    ExternalAPI["OpenWeatherMap API"]:::external

    %% Application Monolith
    subgraph "WeatherApp Application"
        direction TB

        subgraph "Presentation Layer (GUI)"
            direction TB
            Main["main.py"]:::ui
            MainScreen["modules/gui/main_screen.py"]:::ui
            SideBar["modules/gui/side_bar.py"]:::ui
            MainInfo["modules/gui/main_info.py"]:::ui
            ForecastFrame["modules/gui/forecast_frame.py"]:::ui
            ForecastItem["modules/gui/forecast_component.py"]:::ui
            CityWeather["modules/gui/city_weather.py"]:::ui
            ImageLoader["modules/gui/image.py"]:::ui
        end

        subgraph "Business Logic Layer"
            direction TB
            WeatherData["modules/weather_data.py"]:::logic
        end

        subgraph "Persistence Layer"
            direction TB
            JSONRead["modules/read_json.py"]:::storage
            JSONWrite["modules/write_json.py"]:::storage
        end

        subgraph "Static Resources"
            direction TB
            Config["static/config.json"]:::storage
            CachedCurrent["static/weather_data.json"]:::storage
            CachedForecast["static/forecast.json"]:::storage
            Icons["static/icon/"]:::storage
        end
    end

    %% User interaction
    User["User"]:::external -->|"click Search/Refresh"| Main

    %% GUI to Business Logic
    Main -->|"fetch_current() / fetch_forecast()"| WeatherData
    MainScreen --> Main
    SideBar --> MainScreen
    MainInfo --> MainScreen
    ForecastFrame --> MainScreen
    ForecastItem --> ForecastFrame
    CityWeather --> MainScreen
    ImageLoader --> MainScreen

    %% Business Logic to External API
    WeatherData -->|"HTTP GET /weather or /forecast"| ExternalAPI
    ExternalAPI -->|"JSON payload"| WeatherData

    %% Business Logic to Persistence
    WeatherData -->|"write JSON"| JSONWrite
    JSONWrite --> CachedCurrent
    JSONWrite --> CachedForecast
    WeatherData -->|"read config"| Config

    %% GUI Data Rendering
    Main -->|"read data"| JSONRead
    JSONRead --> CachedCurrent
    JSONRead --> CachedForecast
    ImageLoader --> Icons

    %% Relationships for GUI Modules
    MainScreen --> SideBar
    MainScreen --> MainInfo
    MainScreen --> ForecastFrame
    MainScreen --> CityWeather

    %% Click Events
    click Main "https://github.com/valentin5944/weatherapp/blob/main/main.py"
    click MainScreen "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/main_screen.py"
    click SideBar "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/side_bar.py"
    click MainInfo "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/main_info.py"
    click ForecastFrame "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/forecast_frame.py"
    click ForecastItem "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/forecast_component.py"
    click CityWeather "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/city_weather.py"
    click ImageLoader "https://github.com/valentin5944/weatherapp/blob/main/modules/gui/image.py"
    click WeatherData "https://github.com/valentin5944/weatherapp/blob/main/modules/weather_data.py"
    click JSONRead "https://github.com/valentin5944/weatherapp/blob/main/modules/read_json.py"
    click JSONWrite "https://github.com/valentin5944/weatherapp/blob/main/modules/write_json.py"
    click Config "https://github.com/valentin5944/weatherapp/blob/main/static/config.json"
    click CachedCurrent "https://github.com/valentin5944/weatherapp/blob/main/static/weather_data.json"
    click CachedForecast "https://github.com/valentin5944/weatherapp/blob/main/static/forecast.json"
    click Icons "https://github.com/valentin5944/weatherapp/tree/main/static/icon/"

    %% Styles
    classDef ui fill:#add8e6,stroke:#000,stroke-width:1px
    classDef logic fill:#90ee90,stroke:#000,stroke-width:1px
    classDef storage fill:#ffa500,stroke:#000,stroke-width:1px
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px
```
