# google-developer-training/basic-android-kotlin-compose-training-inventory-app architecture

> Architecture diagram of the GitHub repository google-developer-training/basic-android-kotlin-compose-training-inventory-app, 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-inventory-app
- Repository: https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Entry
    subgraph "Application Entry"
        A1["MainActivity"] 
        A2["InventoryApp"]
        A3["InventoryApplication"]
        B["AppContainer (DI)"]
    end
    A1 --> B
    A2 --> B
    A3 --> B

    %% UI Layer
    subgraph "UI Layer"
        %% Navigation components
        SN["InventoryNavGraph (Navigation)"]
        ND["NavigationDestination"]
        
        %% Composable Screens
        HS["HomeScreen"]
        IES["ItemEntryScreen"]
        IDS["ItemDetailsScreen"]
        IEScr["ItemEditScreen"]
        
        %% ViewModels
        HV["HomeViewModel"]
        IEV["ItemEntryViewModel"]
        IDV["ItemDetailsViewModel"]
        IEV2["ItemEditViewModel"]
        AVP["AppViewModelProvider"]
    end

    %% Data Layer
    subgraph "Data Layer"
        IR["ItemsRepository"]
        OIR["OfflineItemsRepository"]
        Dao["ItemDao (DAO)"]
        DB["InventoryDatabase (Room)"]
        Model["Item (Data Model)"]
    end

    %% Android Build & Config
    subgraph "Android Build & Config"
        AM["AndroidManifest.xml"]
        Gradle["Gradle Build & Configurations"]
        Resources["Resources (Layouts, Themes, Drawables)"]
    end

    %% UI interactions
    HS -->|"triggers"| HV
    IES -->|"triggers"| IEV
    IDS -->|"triggers"| IDV
    IEScr -->|"triggers"| IEV2

    %% Navigation control
    ND -->|"controls"| SN
    SN -->|"navigates"| HS
    SN -->|"navigates"| IES
    SN -->|"navigates"| IDS
    SN -->|"navigates"| IEScr

    %% ViewModel to Repository calls
    HV -->|"calls"| IR
    IEV -->|"calls"| IR
    IDV -->|"calls"| IR
    IEV2 -->|"calls"| IR
    AVP -->|"provides"| IR

    %% Dependency Injection from AppContainer
    B -->|"injects"| IR
    B -->|"injects"| OIR

    %% Data flow in Data Layer
    IR -->|"accesses"| Dao
    OIR -->|"accesses"| Dao
    Dao -->|"queries"| DB
    DB -->|"stores"| Model

    %% Click Events for Application Entry
    click A1 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/MainActivity.kt"
    click A2 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/InventoryApp.kt"
    click A3 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/InventoryApplication.kt"
    click B "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/data/AppContainer.kt"

    %% Click Events for UI Layer Composable Screens
    click HS "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/home/HomeScreen.kt"
    click IES "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/item/ItemEntryScreen.kt"
    click IDS "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/item/ItemDetailsScreen.kt"
    click IEScr "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/item/ItemEditScreen.kt"

    %% Click Events for UI Layer Navigation
    click SN "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/navigation/InventoryNavGraph.kt"
    click ND "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/navigation/NavigationDestination.kt"

    %% Click Events for ViewModels
    click HV "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/home/HomeViewModel.kt"
    click IEV "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/item/ItemEntryViewModel.kt"
    click IDV "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/item/ItemDetailsViewModel.kt"
    click IEV2 "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/item/ItemEditViewModel.kt"
    click AVP "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/ui/AppViewModelProvider.kt"

    %% Click Events for Data Layer
    click IR "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/data/ItemsRepository.kt"
    click OIR "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/data/OfflineItemsRepository.kt"
    click Dao "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/data/ItemDao.kt"
    click DB "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/data/InventoryDatabase.kt"
    click Model "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/java/com/example/inventory/data/Item.kt"

    %% Click Events for Android Build & Config
    click AM "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/src/main/AndroidManifest.xml"
    click Gradle "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/blob/main/app/build.gradle.kts"
    click Resources "https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/tree/main/app/src/main/res"

    %% Styles
    classDef app fill:#D8BFD8,stroke:#000,stroke-width:1px;
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef vm fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef data fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef config fill:#F0E68C,stroke:#000,stroke-width:1px;

    class A1,A2,A3,B app;
    class SN,ND,HS,IES,IDS,IEScr ui;
    class HV,IEV,IDV,IEV2,AVP vm;
    class IR,OIR,Dao,DB,Model data;
    class AM,Gradle,Resources config;
```
