How google-developer-training/basic-android-kotlin-compose-training-mars-photos works
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).