# aitorbauza/weatherforecast architecture

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

- Interactive diagram: https://gitdiagram.com/aitorbauza/weatherforecast
- Repository: https://github.com/aitorbauza/weatherforecast

## Overview

##### Identificación del proyecto y su propósito
- Tipo: Aplicación móvil nativa Android (módulo “app” en Gradle).
- Propósito: Mostrar el clima actual, por horas y días, y recomendar ropa según el clima; planificación de rutas con datos meteorológicos; almacenamiento local para minimizar uso de red.

##### Análisis de la estructura de archivos
- app/src/main/java/com/example/weatherforecast:
- controller – punto de entrada de peticiones (WeatherController).
- service – lógica de negocio: WeatherService, ForecastProcessor, WeatherDataProcessor, WeatherTranslator.
- repository – capa de datos: WeatherRepository (fetch de red o cache).
- model – entidades de dominio: CurrentWeather, HourlyForecast, DailyForecast.
- dto – objetos de transferencia: WeatherResponse, ForecastResponse.
- ui – componentes de interfaz: MainActivity, LocationSuggestionTask.
- util – clases auxiliares: TimeUtils, WeatherIconMapper.
- Recursos Android: layouts, drawables, menús, xml (reglas de backup y extracción de datos).
- Tests: unidad y instrumentados.
- Configuración: Gradle, Proguard, wrappers.

##### Detalles clave del README
- Arquitectura en capas: Controller → Service → Repository → DataSources (API + local).
- Uso de DTOs entre capas y mapeo a Model.
- UI separada de la lógica de negocio y de acceso a datos.

##### Guía para dibujar el diagrama de sistema (completo pero reducido)
a. Componentes principales (cada uno como un “caja”):
1. UI Layer (Android Activities/Fragments)
2. Controller
3. Service Layer
4. Repository Layer
5. Data Sources:
- API externa de Weather (REST)
- Almacenamiento local (Room/SharedPreferences/Datastore)
6. Model & DTO (pueden ir juntos como “Objetos de Dominio y Transferencia”)
7. Utilidades (TimeUtils, IconMapper)
b. Relaciones e Interacciones (flechas direccionales):
- UI → Controller: eventos de usuario (pulsaciones, búsquedas de ubicación).
- Controller → Service: invoca lógica de negocio (obtener clima, procesar recomendaciones).
- Service ↔ Repository: pide datos; recibe JSON/DTO o lee cache.
- Repository → API externa / Local: llamadas HTTP o consulta/almacenamiento local.
- Data (DTO) → Translator → Model: conversión de datos externos al modelo interno.
- Model → Service → UI: envía objetos preparados para renderizar.
c. Patrones y principios:
- Capas independientes (separation of concerns).
- Uso de DTOs para desacoplar red y dominio.
- Unidirectional flow de datos (UI → capa de datos y vuelta al UI).
d. Tecnologías y frameworks:
- Android SDK (Activities, XML layouts).
- Gradle (build scripts).
- Posible uso de Retrofit / OkHttp (en Repository) para llamadas REST.
- JSON mapping (Gson/Moshi).
- Dependencias de Jetpack (Room, DataStore) o SharedPreferences.

##### Recomendaciones para un diagrama reducido pero completo
- Representa cada capa con un solo rectángulo distribuido verticalmente.
- Dentro de “Data Sources” pon dos subcajas (API externa, Local Storage).
- Omite clases individuales; agrúpalas por responsabilidad.
- Usa etiquetas cortas: “UI”, “Controller”, “Service”, “Repository”, “API/Local”.

##### Elementos de estilo a incluir
- Etiquetas claras para cada componente.
- Flechas con sentido único o bidireccional para flujos de datos.
- Colores distintos por capa (por ejemplo: azul UI, verde lógica, naranja datos).
- Formas uniformes (rectángulos) y, de ser posible, íconos sencillos (por ejemplo un smartphone para UI, nube para API).

Con estos pasos obtendrás un diagrama completo (todas las capas y flujos) pero reducido en complejidad visual, ideal para revisión ejecutiva sin perder ningún elemento esencial de la arquitectura.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        MA["MainActivity"]:::ui
        LS["LocationSuggestionTask"]:::ui
    end

    %% Controller Layer
    subgraph "Controller"
        direction TB
        WC["WeatherController"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        WS["WeatherService"]:::service
        FP["ForecastProcessor"]:::service
        WDP["WeatherDataProcessor"]:::service
        WT["WeatherTranslator"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        direction TB
        WR["WeatherRepository"]:::repository
    end

    %% Data Sources
    subgraph "Data Sources"
        direction TB
        API["External API"]:::datasource
        LSRC["Local Storage"]:::datasource
    end

    %% Model & DTO Layer
    subgraph "Model & DTO"
        direction TB
        WRSP["WeatherResponse / ForecastResponse"]:::model
        DM["CurrentWeather / HourlyForecast / DailyForecast"]:::model
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        TU["TimeUtils"]:::util
        WIM["WeatherIconMapper"]:::util
    end

    %% Data Flow
    MA -->|"user events"| WC
    LS -->|"suggest location"| WC
    WC -->|"invoke business logic"| WS
    WS -->|"process forecasts"| FP
    WS -->|"process data"| WDP
    WS -->|"translate DTOs"| WT
    WS -->|"requests data"| WR
    WR -->|"fetch HTTP"| API
    WR -->|"read/write cache"| LSRC
    API -->|"returns DTOs"| WRSP
    LSRC -->|"returns DTOs"| WRSP
    WRSP -->|"map to domain"| DM
    WT -->|"translates DTOs"| DM
    DM -->|"provides models"| WS
    WS -->|"prepared data"| MA

    %% Click Events
    click MA "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/ui/MainActivity.java"
    click LS "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/ui/LocationSuggestionTask.java"
    click WC "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/controller/WeatherController.java"
    click WS "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/service/WeatherService.java"
    click FP "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/service/ForecastProcessor.java"
    click WDP "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/service/WeatherDataProcessor.java"
    click WT "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/service/WeatherTranslator.java"
    click WR "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/repository/WeatherRepository.java"
    click WRSP "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/dto/WeatherResponse.java"
    click WRSP "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/dto/ForecastResponse.java"
    click DM "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/model/CurrentWeather.java"
    click DM "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/model/HourlyForecast.java"
    click DM "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/model/DailyForecast.java"
    click TU "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/util/TimeUtils.java"
    click WIM "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/java/com/example/weatherforecast/util/WeatherIconMapper.java"
    click LSRC "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/res/xml/backup_rules.xml"
    click LSRC "https://github.com/aitorbauza/weatherforecast/blob/master/app/src/main/res/xml/data_extraction_rules.xml"

    %% Styles
    classDef ui fill:#D6EAF8,stroke:#3498DB,color:#154360;
    classDef controller fill:#EBF5FB,stroke:#5DADE2,color:#1B4F72;
    classDef service fill:#E8F8F5,stroke:#48C9B0,color:#0E6251;
    classDef repository fill:#FEF9E7,stroke:#F4D03F,color:#7D6608;
    classDef datasource fill:#FDF2E9,stroke:#EB984E,color:#7E5109;
    classDef model fill:#F5EEF8,stroke:#BB8FCE,color:#4A235A;
    classDef util fill:#F2F3F4,stroke:#ABB2B9,color:#566573;
```
