# frguerrerogo/weather architecture

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

- Interactive diagram: https://gitdiagram.com/frguerrerogo/weather
- Repository: https://github.com/frguerrerogo/weather

## Overview

##### Project Type and Purpose
- This is a full-stack mobile application (with cross-platform support for Android, iOS, Linux, macOS, Windows, and even Web) built in Flutter.
- Its purpose is to display weather information (with forecasts, current conditions, and weather events) and support additional features such as managing favorites, showing maps, and providing an offline mode using a local database (Realm). The app also supports different environments (“flavors” – dev/prod).

##### Analyzing the File Structure
- Multiple top-level directories for different platforms (android, ios, linux, macos, windows, web) indicate the cross-platform nature.
- The “lib” directory is organized by Clean Architecture – with distinct subdirectories for core configuration and utilities, data sources and repositories, domain models and use cases, and the presentation layer (UI, screens, providers).
- There is a clear separation of modules: core configurations (dependency injection, themes, routing, and flavors); data (remote APIs, local Realm data source, adapters, and models); domain (entities and abstract repositories); and presentation (screens, widgets, and state management using Riverpod).

##### Key Components
a. Presentation Layer:
- Contains the UI components.
- Includes screens such as Home, Weather, Map, Events, and Favorites.
- Uses state management via Riverpod, as seen in “providers” under lib/presentation.
b. Domain Layer:
- Holds business logic and entities (for weather and events) along with abstract repository definitions.
- Acts as the intermediary between the UI logic and the actual data sources.
c. Data Layer:
- Contains concrete implementations:
- Remote Data Source: API integration (e.g., VisualCrossing API) implemented in lib/data/core/datasources/remote.
- Local Data Source: Offline storage via Realm (e.g., realm_datasource.dart).
- Adapters and models for transforming API responses into domain entities.
- Weather-specific repositories and data sources.
d. Core/Configuration Layer:
- Manages configuration, dependency injection (using Kiwi or similar), app themes, utilities, flavors (for Dev and Prod), and routing (using GoRoute).
- Provides essential utilities and configurations that underpin the rest of the application.
e. Platform-Specific Modules:
- The android, ios, linux, macos, windows, and web directories illustrate deployment and platform-specific configurations.

##### Relationships and Interactions
- The Presentation Layer interacts with the Domain Layer via providers (using Riverpod) to fetch or request weather data.
- The Domain Layer defines repository interfaces which are implemented in the Data Layer.
- The Data Layer retrieves data from external APIs (via HTTP) and local offline storage (Realm), and then passes the processed data back to the Domain Layer.
- The Core/Configuration Layer sets up dependency injection and defines routes and global settings, linking all the layers.

##### Architectural Patterns and Design Principles
- Clean Architecture: Separation of layers (presentation, domain, data) ensures modularity, testability, and maintainability.
- Dependency Injection: Managed via a dedicated DI module to decouple dependencies.
- Layered Structure: Clear boundaries between how data is fetched, processed, and presented.
- Adaptability for Multiple Environments: Use of flavors under lib/core/config/flavors allows for easy switching between dev and prod setups.

##### Key Technologies
- Flutter (framework for building UI)
- Riverpod (state management)
- Realm (local/offline persistence)
- HTTP (for remote API calls)
- GoRoute (navigation)
- Kiwi (dependency injection)
- External services/APIs: VisualCrossing for weather and Google APIs for maps and location.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core/Configuration Layer
    subgraph "Core/Configuration Layer"
        C1["Dependency Injection (DI)"]:::core
        C2["Flavors (Dev/Prod)"]:::core
        C3["Routing (GoRoute)"]:::core
        C4["Utilities & Themes"]:::core
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        P1["UI, Screens & Providers (Riverpod)"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        D1["Entities, Use Cases & Abstract Repositories"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        D2["Remote API Integration (VisualCrossing)"]:::data
        D3["Local Storage (Realm)"]:::data
        D4["Adapters & Models"]:::data
    end

    %% Platform Modules
    subgraph "Platform Modules"
        PM1["Android"]:::platform
        PM2["iOS"]:::platform
        PM3["Linux"]:::platform
        PM4["macOS"]:::platform
        PM5["Windows"]:::platform
        PM6["Web"]:::platform
    end

    %% External Dependencies
    E1["External Weather API"]:::external
    E2["Local Realm DB"]:::external

    %% Relationships
    P1 -->|"fetchesData"| D1
    D1 -->|"repositoryCall"| D2
    D1 -->|"repositoryCall"| D3
    D2 -->|"transformsData"| D4
    D3 -->|"transformsData"| D4
    D4 -->|"returnsData"| D1

    C1 ---|"initConfig"| P1
    C1 ---|"initConfig"| D1
    C1 ---|"initConfig"| D2
    C1 ---|"initConfig"| D3
    C1 ---|"initConfig"| D4
    C1 ---|"initConfig"| C2
    C1 ---|"initConfig"| C3
    C1 ---|"initConfig"| C4

    C2 ---|"influences"| P1
    C2 ---|"influences"| D1
    C2 ---|"influences"| D2
    C2 ---|"influences"| D3

    C3 ---|"routes"| P1

    C4 ---|"providesUtilities"| P1
    C4 ---|"providesUtilities"| D1

    C1 ---|"platformSetup"| PM1
    C1 ---|"platformSetup"| PM2
    C1 ---|"platformSetup"| PM3
    C1 ---|"platformSetup"| PM4
    C1 ---|"platformSetup"| PM5
    C1 ---|"platformSetup"| PM6

    D2 ---|"HTTPCalls"| E1
    D3 ---|"OfflineStorage"| E2

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef domain fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef data fill:#FFFFE0,stroke:#DAA520,stroke-width:2px;
    classDef core fill:#D8BFD8,stroke:#800080,stroke-width:2px;
    classDef platform fill:#FFB6C1,stroke:#FF0000,stroke-width:2px;
    classDef external fill:#FFE4B5,stroke:#FF8C00,stroke-width:2px;

    %% Click Events
    click P1 "https://github.com/frguerrerogo/weather/tree/master/lib/presentation"
    click D1 "https://github.com/frguerrerogo/weather/tree/master/lib/domain"
    click D2 "https://github.com/frguerrerogo/weather/tree/master/lib/data/core/datasources/remote/apis"
    click D3 "https://github.com/frguerrerogo/weather/blob/master/lib/data/core/datasources/local/realm_datasource.dart"
    click D4 "https://github.com/frguerrerogo/weather/tree/master/lib/data/weather/adapters"
    click C1 "https://github.com/frguerrerogo/weather/tree/master/lib/core/config/di"
    click C2 "https://github.com/frguerrerogo/weather/blob/master/lib/core/config/flavors/flavors.dart"
    click C3 "https://github.com/frguerrerogo/weather/tree/master/lib/core/config/router"
    click C4 "https://github.com/frguerrerogo/weather/blob/master/lib/core/config/app_theme.dart"
    click PM1 "https://github.com/frguerrerogo/weather/tree/master/android/"
    click PM2 "https://github.com/frguerrerogo/weather/tree/master/ios/"
    click PM3 "https://github.com/frguerrerogo/weather/tree/master/linux/"
    click PM4 "https://github.com/frguerrerogo/weather/tree/master/macos/"
    click PM5 "https://github.com/frguerrerogo/weather/tree/master/windows/"
    click PM6 "https://github.com/frguerrerogo/weather/tree/master/web/"
```
