How google-developer-training/basic-android-kotlin-compose-training-inventory-app works
Main Components Identification
• UI Layer: Represented by the “ui” package. This includes composable screens such as HomeScreen, ItemEntryScreen, ItemDetailsScreen, ItemEditScreen, and their respective ViewModels under the “ui/home” and “ui/item” directories. Also include the “navigation” package where the InventoryNavGraph and NavigationDestination govern in-app navigation.
• View Models: Each screen has its dedicated ViewModel that mediates between the UI and the data components.
• Data Layer: Found in the “data” package. This contains:
• The Room Database (InventoryDatabase)
• The DAO interface (ItemDao)
• Data models (Item)
• Repository classes (ItemsRepository and OfflineItemsRepository for managing data operations)
• A container class (AppContainer) that likely handles dependency setup/injection for the data components.
• Application/Entry Point: The MainActivity and the Application classes (InventoryApp.kt and InventoryApplication.kt) that bootstrap the app.
• Android Build & Configuration: Gradle scripts, AndroidManifest.xml, and resource files (layouts, themes, drawables) which inform the environmental setup.
Relationships and Interactions
• UI Components → ViewModels: Each UI screen sends user actions and events to its corresponding ViewModel.
• ViewModels → Repositories: ViewModels interact with ItemsRepository (or OfflineItemsRepository) to retrieve or update the data.
• Repositories → Data Access Layer: The repositories work with the Room database via the ItemDao to execute CRUD operations.
• Navigation: The Navigation component controls transitions between UI composables based on state and user interactions.
• Dependency Injection: The AppContainer component may serve to inject the repository and other dependencies into the ViewModels and UI.
Architectural Patterns and Principles
• MVVM: Emphasize the separation of concerns; Views (Compose screens) notify the ViewModels, which then interact with the repository and data sources.
• Repository Pattern: The repository abstracts the underlying Room database and supports data operations in a clean way.
• Clean Architecture Concepts: Though not laid out in multiple layers, the clear separation between UI, domain (via view models), and data logic (Room, DAO) is evident.
• Use of Kotlin Coroutines & Flow: Data flows (using StateFlows or Kotlin Flow) from the repositories to the UI via the ViewModels.
• Navigation Component: Points to a structured approach for handling multiple screens using a NavGraph.