# freedomchuks/pokedex-compose architecture

> Architecture diagram of the GitHub repository freedomchuks/pokedex-compose, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/freedomchuks/pokedex-compose
- Repository: https://github.com/freedomchuks/pokedex-compose

## Overview

##### Project type and purpose
- This is an Android application built with Kotlin, utilizing Jetpack Compose for the UI and adhering to the MVVM pattern. The app is an offline-first Pokémon catalog (Pokedex) that demonstrates modern Android development concepts such as dependency injection (Hilt), asynchronous processing (Coroutines/Flow), and a repository pattern that bridges remote (Retrofit/OkHttp) and local (Room/SQLite) data sources.

##### File structure
- The file tree indicates several modules and layers:
- The “app” module serves as the main Android application entry point and contains core UI components (Compose UI elements, Navigation, and activity classes).
- “core” modules (like core/data, core/database, core/designsystem, core/model, core/navigation, core/network, core/viewmodel) collectively form the data and supporting layers.
- “feature” modules (feature/home, feature/details) encapsulate domain-specific functions and screens.
- The “build-logic” and “buildSrc” directories contain Gradle build scripts and convention plugins that hint toward standardized build and dependency injection procedures.
- The “baselineprofile” module shows effort to optimize performance with Android baseline profiles.
- The overall structure shows modularization: separation into reusable core components and feature-specific modules along with clear separation of UI and data layers.

##### Insights from the README
- The README explains that the architecture follows MVVM and the Repository pattern, emphasizing unidirectional data flow (UI events flow to the ViewModel/data layer; data streams are observed back by UI).
- It describes two primary layers: the UI layer (screens, navigation, and state management via ViewModels) and the Data layer (handling offline-first business logic, local database access, and remote network calls via Retrofit).
- The README also mentions used technologies: Jetpack Compose, Hilt, Coroutines/Flow, Room, Retrofit, OkHttp, and additional libraries, which should be highlighted.

a. And lay out the main components:
- UI Layer:
- App module with UI screens (found in app/src/main/kotlin and feature/* modules), including Compose components, MainActivity, and Navigation components.
- ViewModel layer (in core/viewmodel and within feature modules) that holds and manages UI state.
- Navigation components (in core/navigation) coordinating screen transitions.
- Data Layer:
- Repository components from core/data (with implementations for home and detail repositories).
- Network communication represented by the API client/service in core/network.
- Local storage using Room (see core/database) for caching data.
- Model mappings (in core/model) and possibly conversion utilities.
- Design Systems & Shared Components:
- UI design resources and themes under core/designsystem.
- Build and dependency configurations from build-logic/buildSrc.
- External Dependencies:
- Third-party libraries like Hilt, Retrofit, OkHttp, and others should be noted as external services that integrate within these layers.

b. Relationships and interactions:
- UI components dispatch user events to the ViewModel.
- The ViewModel interacts with repository interfaces to retrieve or store data.
- The repository coordinates data sources by checking the network (core/network) or local database (core/database).
- Data updates trigger flows back to the ViewModel and eventually update the UI.
- Dependency injection with Hilt as it wires up these components.
- Integration points such as API calls (Retrofit/OkHttp) and Room database interactions.

c. Architectural patterns/design principles:
- MVVM and Repository pattern.
- Unidirectional flow of events/data.
- Modularization by showing how the “core” and “feature” modules communicate.
- Offline-first strategy that centralizes data retrieval and caches results locally.

d. Relevant technologies:
- Build/staging tools from build-logic and buildSrc which support modularization and parallel builds.

##### Elements
- Clear labels on each module/component (e.g., “Compose UI”, “ViewModel”, “Repository”, “Network Service”, “Local Database”).

- At the very top, indicate the Android device/user interacting with the UI.
- Next, illustrate the “UI Layer” blocks:
- Compose Screens (from app and feature modules),
- Navigation (from core/navigation),
- ViewModels (from core/viewmodel).
- Below, represent the “Data Layer” blocks:
- Repositories (in core/data and repository submodules),
- Local Database (core/database),
- Network/Remote API (core/network, PokeAPI mentioned in README).
- User interaction flows → UI Layer → ViewModel.
- ViewModel requests → Repository.
- Repository queries → Local Database/Remote API.
- Data flows back upward to update the UI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User (Android Device)"):::user

    subgraph "UI Layer"
        UI1("Compose UI (MainActivity & PokedexApp)"):::ui
        UI2("Navigation (PokedexNavHost & PokedexNavigation)"):::ui
        UI3("Feature Home (PokedexHome, HomeViewModel, HomeBackground)"):::ui
        UI4("Feature Details (PokedexDetails, DetailsViewModel, DetailsBackground)"):::ui
        UI5("Design System (Themes, AppBar, Progress)"):::ui
        NM("Navigation Manager (Compose Navigator, Commands)"):::ui
    end

    subgraph "ViewModel Layer"
        VM("Core ViewModels (BaseViewModel, ViewModelStateFlow)"):::vmlayer
    end

    subgraph "Data Layer"
        DR1("Home Repository"):::datalayer
        DR2("Details Repository"):::datalayer
        DB("Local Database (Room/SQLite)"):::datalayer
        NW("Network Service (Retrofit/OkHttp)"):::datalayer
    end

    subgraph "Build & DI"
        BL("Build Logic (Hilt Plugin)"):::build
        BS("BuildSrc (Configuration)"):::build
    end

    %% Relationships
    U --> UI1
    UI1 -->|"sends UI events"| VM
    UI1 --> UI2
    UI2 --> NM
    UI2 --> UI3
    UI2 --> UI4
    UI3 -->|"triggers"| DR1
    UI4 -->|"triggers"| DR2
    VM -->|"fetches data"| DR1
    VM -->|"fetches data"| DR2
    DR1 -->|"reads/writes"| DB
    DR1 -->|"calls"| NW
    DR2 -->|"reads/writes"| DB
    DR2 -->|"calls"| NW
    UI5 -->|"styles"| UI1
    BL --> VM
    BL --> DR1
    BL --> DR2
    BS --> VM
    BS --> DR1
    BS --> DR2

    %% Styles
    classDef user fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef ui fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef vmlayer fill:#A9DFBF,stroke:#229954,stroke-width:2px;
    classDef datalayer fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef build fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/freedomchuks/pokedex-compose/tree/main/app/src/main/kotlin/com/skydoves/pokedex/compose"
    click UI2 "https://github.com/freedomchuks/pokedex-compose/tree/main/app/src/main/kotlin/com/skydoves/pokedex/compose/navigation"
    click UI3 "https://github.com/freedomchuks/pokedex-compose/tree/main/feature/home/src/main/kotlin/com/skydoves/pokedex/compose/feature/home"
    click UI4 "https://github.com/freedomchuks/pokedex-compose/tree/main/feature/details/src/main/kotlin/com/skydoves/pokedex/compose/feature/details"
    click VM "https://github.com/freedomchuks/pokedex-compose/tree/main/core/viewmodel/src/main/kotlin/com/skydoves/pokedex/compose/core/viewmodel"
    click DR1 "https://github.com/freedomchuks/pokedex-compose/tree/main/core/data/src/main/kotlin/com/skydoves/pokedex/compose/core/data/repository/home"
    click DR2 "https://github.com/freedomchuks/pokedex-compose/tree/main/core/data/src/main/kotlin/com/skydoves/pokedex/compose/core/data/repository/details"
    click DB "https://github.com/freedomchuks/pokedex-compose/tree/main/core/database/src/main/kotlin/com/skydoves/pokedex/compose/core/database"
    click NW "https://github.com/freedomchuks/pokedex-compose/tree/main/core/network/src/main/kotlin/com/skydoves/pokedex/compose/core/network/service"
    click UI5 "https://github.com/freedomchuks/pokedex-compose/tree/main/core/designsystem/src/main/kotlin/com/skydoves/pokedex/compose/core/designsystem"
    click NM "https://github.com/freedomchuks/pokedex-compose/tree/main/core/navigation/src/main/kotlin/com/skydoves/pokedex/compose/core/navigation"
    click BL "https://github.com/freedomchuks/pokedex-compose/tree/main/build-logic/convention/src/main/kotlin"
    click BS "https://github.com/freedomchuks/pokedex-compose/tree/main/buildSrc/src/main/kotlin/com/skydoves/pokedex/compose"
```
