# google-developer-training/basic-android-kotlin-compose-training-mars-photos architecture

> Architecture diagram of the GitHub repository google-developer-training/basic-android-kotlin-compose-training-mars-photos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos
- Repository: https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos

## Overview

##### Main Components Identification
- UI Layer:
- Composable Screens: Represented by files in the “ui” and “ui/screens” directories (e.g., HomeScreen.kt, MarsPhotosApp.kt).
- ViewModel Layer:
- Business logic managed by the ViewModel (MarsViewModel.kt) to handle state and coroutine-based task execution.
- Data Layer:
- Repository: MarsPhotosRepository.kt is responsible for separating network calls from the UI logic.
- Dependency Injection: AppContainer.kt within the “data” directory sets up object dependencies across the app.
- Network Layer:
- REST API Service: MarsApiService.kt handles API calls via Retrofit to the NASA Mars Photo REST endpoint.
- Model:
- Domain models represented in MarsPhoto.kt under the “model” package.
- Application Setup:
- MarsPhotosApplication.kt initializes the application and its dependency injection, which plays a central role in bootstrapping the app’s architecture.
- Testing Components:
- A dedicated test suite under “app/src/test” includes tests for the ViewModel, network repository, fake implementations, and testing rules.

##### Relationships and Interactions
- The UI components (Composable functions) interact with the ViewModel layer to request data and update the user interface.
- The ViewModel calls the Repository (from the Data layer), which abstracts away the network details.
- The Repository communicates with the MarsApiService (in the Network layer) for fetching Mars photos via REST calls.
- The MarsPhotosApplication and AppContainer handle dependency injection, ensuring that the same instances are available across layers.
- Tests simulate the above interactions using fakes and rules, ensuring components work as expected in isolation.

##### Architectural Patterns & Design Principles
- MVVM (Model-View-ViewModel) Pattern: Clear separation of UI (Composable screens) and business logic (ViewModel) ensures easier maintenance and testing.
- Repository Pattern: Abstracts data sources (i.e., network calls) from the rest of the app.
- Dependency Injection: Managed by AppContainer to provide loosely-coupled module interactions.
- Use of third-party libraries: Retrofit for network requests, kotlinx.serialization for JSON, and Coil for efficient image loading.

##### Relevant Technologies
- Kotlin as the programming language.
- Jetpack Compose for UI development.
- Retrofit, kotlinx.serialization, and Coil as third-party libraries to support key functionalities.
- Gradle as the build system (notice build.gradle.kts, settings.gradle.kts, and gradle wrapper files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Setup Layer
    A["MarsPhotosApplication.kt (App Setup)"]:::app
    B["AppContainer.kt (Dependency Injection)"]:::data

    %% UI Layer
    subgraph "UI Layer"
        U1["MarsPhotosApp.kt (Composable UI)"]:::ui
        U2["HomeScreen.kt (Screen UI)"]:::ui
        subgraph "Theme"
            T1["Color.kt"]:::ui
            T2["Shape.kt"]:::ui
            T3["Theme.kt"]:::ui
            T4["Type.kt"]:::ui
        end
    end

    %% ViewModel Layer
    V["MarsViewModel.kt (ViewModel)"]:::viewmodel

    %% Data Layer
    R["MarsPhotosRepository.kt (Repository)"]:::data

    %% Network Layer
    N["MarsApiService.kt (API Service)"]:::network

    %% Model
    M["MarsPhoto.kt (Model)"]:::model

    %% Testing Layer
    subgraph "Testing Components"
        TS1["MarsViewModelTest.kt"]:::test
        TS2["NetworkMarsRepositoryTest.kt"]:::test
        TS3["FakeDataSource.kt"]:::test
        TS4["FakeMarsApiService.kt"]:::test
        TS5["FakeNetworkMarsPhotosRepository.kt"]:::test
        TS6["TestDispatcherRule.kt"]:::test
    end

    %% Relationships
    A --> B
    B --> V
    B --> R

    U1 --> V
    U2 --> V

    V --> R
    R --> N
    R --> M

    %% Testing relationships (dashed lines represent testing associations)
    TS1 -.-> V
    TS2 -.-> R
    TS3 -.-> R
    TS4 -.-> N
    TS5 -.-> R
    TS6 -.-> TS1

    %% Third-party libraries note (as an annotation)
    Note1["Retrofit, kotlinx.serialization, Coil"]:::note
    N --- Note1

    %% Click Events
    click A "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/MarsPhotosApplication.kt"
    click B "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/data/AppContainer.kt"
    click U1 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/MarsPhotosApp.kt"
    click U2 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/screens/HomeScreen.kt"
    click T1 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/theme/Color.kt"
    click T2 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/theme/Shape.kt"
    click T3 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/theme/Theme.kt"
    click T4 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/theme/Type.kt"
    click V "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/ui/screens/MarsViewModel.kt"
    click R "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/data/MarsPhotosRepository.kt"
    click N "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/network/MarsApiService.kt"
    click M "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/main/java/com/example/marsphotos/model/MarsPhoto.kt"
    click TS1 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/test/java/com/example/marsphotos/MarsViewModelTest.kt"
    click TS2 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/test/java/com/example/marsphotos/NetworkMarsRepositoryTest.kt"
    click TS3 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/test/java/com/example/marsphotos/fake/FakeDataSource.kt"
    click TS4 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/test/java/com/example/marsphotos/fake/FakeMarsApiService.kt"
    click TS5 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/test/java/com/example/marsphotos/fake/FakeNetworkMarsPhotosRepository.kt"
    click TS6 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-mars-photos/blob/main/app/src/test/java/com/example/marsphotos/rules/TestDispatcherRule.kt"

    %% Styles
    classDef ui fill:#ffefd5,stroke:#ff8c00,stroke-width:2px;
    classDef viewmodel fill:#e6e6fa,stroke:#8a2be2,stroke-width:2px;
    classDef data fill:#f0fff0,stroke:#228b22,stroke-width:2px;
    classDef network fill:#ffe4e1,stroke:#dc143c,stroke-width:2px;
    classDef app fill:#ffffe0,stroke:#ffd700,stroke-width:2px;
    classDef test fill:#e0ffff,stroke:#20b2aa,stroke-width:2px;
    classDef model fill:#fffacd,stroke:#b8860b,stroke-width:2px;
    classDef note fill:#f5f5f5,stroke:#696969,stroke-width:1px,stroke-dasharray: 5 5;
```
