How google-developer-training/basic-android-kotlin-compose-training-amphibians works
Main Components (Folders)
• App Module (app): This is the heart of the project.
• Source Code Hierarchy:
• /src/main/java/com/example/amphibians contains the core packages:
• Application Class (AmphibiansApplication.kt)
• MainActivity.kt for launching the UI
• /data folder: Contains the repository (AmphibiansRepository.kt) and AppContainer.kt (acts as the dependency injection/lightweight service locator).
• /model folder: Contains data models like Amphibian.kt.
• /network folder: Contains the Retrofit-based API service (AmphibiansApiService.kt) for fetching data from the internet.
• /ui folder: Contains the composable application (AmphibiansApp.kt), screens (including HomeScreen.kt), and ViewModels (AmphibiansViewModel.kt).
• Resource files (res folders): Maintain layouts (drawables, values, and mipmaps) needed for rendering UI components.
• Build System and Configurations:
• Gradle files (build.gradle.kts, settings.gradle.kts) and the wrapper ensure a repeatable build environment.
• GitHub workflows and configuration files (*.github folder) indicate CI/CD practices.
Relationships and Interactions
• UI Layer: The UI is built using Compose with the AmphibiansApp entry point, which launches the HomeScreen.
• ViewModel Layer: HomeScreen communicates with AmphibiansViewModel for business logic and state management.
• Data Layer: The AmphibiansViewModel depends on AmphibiansRepository (via AppContainer for dependency management) to fetch and provide data.
• Network: The AmphibiansRepository uses AmphibiansApiService (a Retrofit-based API client) to perform network calls.
• Model: The Amphibian data model is used across the repository and UI layers to define the data structure.
Architectural Patterns and Design Principles
• MVVM: Clear separation between UI (compose screens), business logic (ViewModel), and data (repository, network services).
• Dependency Injection: The AppContainer in the data package provides a simple DI mechanism.
• Use of Retrofit and Coil: Indicates pattern-driven integration where network calls and resource loading are abstracted via dedicated libraries.
• Layering: Separate folders clearly show segregation between UI, network, and business logic.