# maldonado20/countriesweathermvc architecture

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

- Interactive diagram: https://gitdiagram.com/maldonado20/countriesweathermvc
- Repository: https://github.com/maldonado20/countriesweathermvc

## Overview

##### Project Type and Purpose
- This is a native Android mobile application (Kotlin + XML) implementing an MVC architecture.
- It displays a list of world regions, then lists countries in a selected region (name, flag, capital), and finally shows details for one country including weather data for its capital.
- It consumes two external REST services: RestCountries and WeatherAPI.

##### File Structure Analysis
- Top-level “app/src/main/java/sv/edu/udb/countriesweather/…” is divided into three MVC folders:
- models/ — data classes reflecting JSON responses (CountryModels.kt, WeatherModels.kt)
- controllers/ — orchestrators (CountriesController, RegionsController, CountryDetailController)
- ui/ — Android UI components (MainActivity, Fragments, Adapters)
- network/ holds ApiClient, Retrofit service interfaces (RestCountriesService, WeatherApiService).
- utils/ contains Formatters.
- res/ holds XML layouts, drawables, navigation graph, resources.

##### README Insights
- Uses Retrofit2 + Gson, OkHttp interceptor, Coil for image loading, Android Navigation (without SafeArgs).
- Follows MVC: separation of data (models), coordination (controllers), presentation (ui).

##### Main Components
a. View Layer (UI)
- MainActivity
- RegionsFragment (list regions)
- CountriesFragment (list countries)
- CountryDetailFragment (show details + weather)
- Adapters: RegionsAdapter, CountriesAdapter
- Layout XMLs
b. Controller Layer
- RegionsController
- CountriesController
- CountryDetailController
c. Model Layer
- CountryModels
- WeatherModels
- Utility Formatters
d. Network Layer
- ApiClient (Retrofit builder)
- RestCountriesService (GET regions, countries)
- WeatherApiService (GET weather by capital)
e. External Services
- RestCountries API Endpoint
- WeatherAPI Endpoint
f. Image Loader
- Coil (loads flag URLs into ImageViews)

##### Relationships & Data Flow
- User taps in UI → Fragment calls its Controller
- Controller requests data via ApiClient → Retrofit service
- Service calls external API → Response mapped to Models
- Controller handles errors/loaders, transforms Models (via Formatters)
- Controller returns data to View (Fragment/Adapter) → UI updates

##### Architectural Patterns & Principles
- MVC: strict three-layer separation
- Single Responsibility: Controllers only coordinate, data classes only hold data, UI only renders
- Dependency Injection: ApiClient is singleton, controllers obtain services from it
- Asynchronous calls: Retrofit + OkHttp manage threads, callbacks or coroutines

##### Essential Elements
- Clear component names (e.g., CountriesController)
- Smartphone screen frames for UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        MA["MainActivity"]:::ui
        NH["NavHostFragment"]:::ui
        RF["RegionsFragment"]:::ui
        CF["CountriesFragment"]:::ui
        CDF["CountryDetailFragment"]:::ui
        RA["RegionsAdapter"]:::ui
        CA["CountriesAdapter"]:::ui
        Coil["Coil Image Loader"]:::ui
    end

    %% Controller Layer
    subgraph "Controller Layer"
        direction TB
        RC["RegionsController"]:::controller
        CoC["CountriesController"]:::controller
        CDC["CountryDetailController"]:::controller
    end

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        AC["ApiClient"]:::network
        RCS["RestCountriesService"]:::network
        WAS["WeatherApiService"]:::network
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        CM["CountryModels"]:::model
        WM["WeatherModels"]:::model
        UF["Formatters"]:::model
    end

    %% External Services
    subgraph "External Services"
        direction TB
        RCAPI["RestCountries API"]:::external
        WAPI["WeatherAPI"]:::external
    end

    %% UI to Controllers
    RF -->|"getRegions()"| RC
    CF -->|"getCountries(region)"| CoC
    CDF -->|"getWeather(capital)"| CDC

    %% Controllers to Network
    RC -->|"use ApiClient"| AC
    CoC -->|"use ApiClient"| AC
    CDC -->|"use ApiClient"| AC

    AC -->|"create RestCountriesService"| RCS
    AC -->|"create WeatherApiService"| WAS

    %% Services to External
    RCS -->|"HTTP GET Regions/Countries"| RCAPI
    WAS -->|"HTTP GET Weather"| WAPI

    %% External to Services
    RCAPI -->|"JSON Response"| RCS
    WAPI -->|"JSON Response"| WAS

    %% Services to Controllers
    RCS -->|"parsed CountryModels"| RC
    RCS -->|"parsed CountryModels"| CoC
    WAS -->|"parsed WeatherModels"| CDC

    %% Controllers to UI
    RC -->|"callback with data"| RF
    CoC -->|"callback with data"| CF
    CDC -->|"callback with data"| CDF

    %% Adapters and Coil
    RF -->|"bind regions"| RA
    CF -->|"bind countries"| CA
    CA -->|"load flag URL"| Coil

    %% Controllers use Formatters
    RC -->|"format data"| UF
    CoC -->|"format data"| UF
    CDC -->|"format data"| UF

    %% Click Events
    click MA "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/ui/MainActivity.kt"
    click RF "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/ui/fragments/RegionsFragment.kt"
    click CF "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/ui/fragments/CountriesFragment.kt"
    click CDF "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/ui/fragments/CountryDetailFragment.kt"
    click RA "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/ui/adapters/RegionsAdapter.kt"
    click CA "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/ui/adapters/CountriesAdapter.kt"
    click RC "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/controllers/RegionsController.kt"
    click CoC "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/controllers/CountriesController.kt"
    click CDC "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/controllers/CountryDetailController.kt"
    click CM "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/models/CountryModels.kt"
    click WM "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/models/WeatherModels.kt"
    click UF "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/utils/Formatters.kt"
    click AC "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/network/ApiClient.kt"
    click RCS "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/network/RestCountriesService.kt"
    click WAS "https://github.com/maldonado20/countriesweathermvc/blob/master/app/src/main/java/sv/edu/udb/countriesweather/network/WeatherApiService.kt"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef controller fill:#90EE90,stroke:#000,stroke-width:1px
    classDef network fill:#FFA500,stroke:#000,stroke-width:1px
    classDef model fill:#FFFFE0,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
