# waseemabbas8/libroom-android architecture

> Architecture diagram of the GitHub repository waseemabbas8/libroom-android, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/waseemabbas8/libroom-android
- Repository: https://github.com/waseemabbas8/libroom-android

## Overview

##### Project type and purpose
- This is a single-module Android application (“libroom-android”) built in Kotlin with Jetpack Compose.
- It follows Clean Architecture, combining MVI (Model-View-Intent) and MVVM patterns.
- Its purpose is to let users explore, read, and listen to books, with features like authentication (Firebase), home feed (REST via Ktor), search, favorites, and a reader view.

##### File structure and README
- Top-level gradle files, an Android Studio App module under `/app`, and a clear separation in `app/src/main/java/com/waseem/libroom` into `core` and `feature` packages.
- `core` contains DI modules (Hilt), MVI/MVVM base classes, UI components (Compose widgets & theme), and use-case abstractions.
- Each `feature` (auth, book, author, category, favorites, home, onboarding, profile, reader, root, search) has its own:
- data layer (RepositoryImpl)
- domain layer (models & use cases)
- presentation layer (Screen, ViewModel, UI state, contract)
- External dependencies include Firebase Auth, Ktor for REST, DataStore for key-value, and Compose Navigation.

##### Main components
a. Presentation Layer
- Screens (Compose UIs)
- ViewModels (MVVM or MVI state holders)
- Navigation Graph (Compose Navigation)
b. Domain Layer
- Use Cases (e.g., `SignInWithEmailPassword`, `GetHomeContent`, `GetTopAuthors`)
- Domain Models (e.g., `User`, `Book`, `Author`, `HomeContent`)
c. Data Layer
- Repositories (e.g., `AuthRepositoryImpl`, `BookRepositoryImpl`)
- Data Sources:
- Remote via Ktor HTTP client (REST endpoints)
- FirebaseAuth (for login/logout)
- DataStore (for user preferences)
d. Dependency Injection
- Hilt modules: `AppModule`, `FirebaseModule`, plus feature-specific modules (`AuthModule`, `BookModule`, etc.) supply instances of Ktor client, FirebaseAuth, use cases, and repositories.
e. External Services
- REST API server
- Firebase Auth
- Local DataStore

##### Relationships and data flows
- User taps a button on a Screen → Screen sends an Intent/Action to its ViewModel.
- ViewModel invokes one or more Use Cases from the Domain layer.
- Use Case orchestrates business logic and calls the appropriate Repository.
- Repository either:
- performs a remote call through the Ktor client, or
- interacts with FirebaseAuth, or
- reads/writes DataStore.
- The result flows back: Repository → Use Case → ViewModel → Screen UI State.

##### Architectural patterns and design principles
- Clean Architecture layered approach: Presentation → Domain → Data.
- MVI for state management, where state flows are unidirectional.
- MVVM for simpler UI-ViewModel binding in certain screens.
- Hilt for constructor injection and module organization.
- Compose Navigation for screen routing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        NavGraph["AppNavGraph"]:::presentation
        Route["Route Definitions"]:::presentation

        subgraph "Auth Feature"
            direction TB
            LoginScreen["LoginScreen"]:::presentation
            LoginVM["LoginViewModel"]:::presentation
        end

        subgraph "Home Feature"
            direction TB
            HomeScreen["HomeScreen"]:::presentation
            HomeVM["HomeViewModel"]:::presentation
        end

        subgraph "Search Feature"
            direction TB
            SearchScreen["SearchScreen"]:::presentation
            SearchVM["SearchViewModel"]:::presentation
        end

        subgraph "Favorites Feature"
            direction TB
            FavoritesScreen["FavoritesScreen"]:::presentation
            FavoritesVM["FavoritesViewModel"]:::presentation
        end

        subgraph "Book & Reader"
            direction TB
            BookDetailScreen["BookDetailScreen"]:::presentation
            BookDetailVM["BookDetailViewModel"]:::presentation
            BookReaderScreen["BookReaderScreen"]:::presentation
        end

        subgraph "Onboarding Feature"
            direction TB
            OnboardingScreen["OnboardingScreen"]:::presentation
            OnboardingVM["OnboardingViewModel"]:::presentation
        end

        subgraph "Profile Feature"
            direction TB
            ProfileScreen["ProfileScreen"]:::presentation
            ProfileVM["ProfileViewModel"]:::presentation
        end
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        SignInUC["SignInWithEmailPassword UseCase"]:::domain
        SignOutUC["SignOut UseCase"]:::domain
        GetHomeUC["GetHomeContent UseCase"]:::domain
        GetTopAuthorsUC["GetTopAuthors UseCase"]:::domain
        GetTopCategoriesUC["GetTopCategories UseCase"]:::domain
        GetFavoritesUC["GetFavoriteBooks UseCase"]:::domain
        GetAuthStateUC["GetAuthState UseCase"]:::domain
        UpdateAuthStateUC["UpdateAuthState UseCase"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        AuthRepo["AuthRepositoryImpl"]:::data
        BookRepo["BookRepositoryImpl"]:::data
        AuthorRepo["AuthorRepositoryImpl"]:::data
        CategoryRepo["CategoryRepositoryImpl"]:::data
        PrefRepo["UserPreferenceRepositoryImpl"]:::data
    end

    %% DI Modules
    subgraph "DI Modules"
        direction TB
        AppModule["AppModule"]:::di
        FirebaseModule["FirebaseModule"]:::di
        AuthModule["AuthModule"]:::di
        BookModule["BookModule"]:::di
        HomeModule["HomeModule"]:::di
        SearchModule["SearchModule"]:::di
    end

    %% External Services
    REST["REST API"]:::external
    FirebaseAuth["Firebase Auth"]:::external
    DataStore["DataStore"]:::external

    %% Data Flow
    LoginScreen -->|action| LoginVM
    LoginVM -->|calls| SignInUC
    SignInUC -->|uses| AuthRepo
    AuthRepo -->|auth via| FirebaseAuth
    SignOutUC -->|uses| AuthRepo

    HomeScreen -->|action| HomeVM
    HomeVM -->|calls| GetHomeUC
    GetHomeUC -->|uses| BookRepo
    BookRepo -->|http via| REST
    GetTopAuthorsUC -->|uses| AuthorRepo
    AuthorRepo -->|http via| REST

    SearchScreen -->|action| SearchVM
    SearchVM -->|calls| GetTopCategoriesUC
    GetTopCategoriesUC -->|uses| CategoryRepo
    CategoryRepo -->|http via| REST

    FavoritesScreen -->|action| FavoritesVM
    FavoritesVM -->|calls| GetFavoritesUC
    GetFavoritesUC -->|uses| PrefRepo
    PrefRepo -->|data via| DataStore

    OnboardingScreen -->|action| OnboardingVM
    OnboardingVM -->|calls| GetAuthStateUC
    GetAuthStateUC -->|uses| PrefRepo

    ProfileScreen -->|action| ProfileVM
    ProfileVM -->|calls| UpdateAuthStateUC
    UpdateAuthStateUC -->|uses| PrefRepo

    BookDetailScreen -->|action| BookDetailVM
    BookDetailVM -->|calls| GetHomeUC
    BookReaderScreen -->|renders| BookDetailVM

    %% DI Bindings
    AppModule -->|provides| BookRepo
    AppModule -->|provides| REST
    FirebaseModule -->|provides| AuthRepo
    FirebaseModule -->|provides| FirebaseAuth
    AuthModule -->|binds| SignInUC
    AuthModule -->|binds| SignOutUC
    BookModule -->|binds| GetHomeUC
    HomeModule -->|binds| GetTopAuthorsUC
    SearchModule -->|binds| GetTopCategoriesUC

    %% Click Events
    click NavGraph "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/navigation/AppNavGraph.kt"
    click Route "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/navigation/Route.kt"
    click LoginScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/auth/presentation/LoginScreen.kt"
    click LoginVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/auth/presentation/LoginViewModel.kt"
    click HomeScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/home/presentation/HomeScreen.kt"
    click HomeVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/home/presentation/HomeViewModel.kt"
    click SearchScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/search/presentation/SearchScreen.kt"
    click SearchVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/search/presentation/SearchViewModel.kt"
    click FavoritesScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/favorites/presentation/FavoritesScreen.kt"
    click FavoritesVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/favorites/presentation/FavoritesViewModel.kt"
    click BookDetailScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/book/presentation/BookDetailScreen.kt"
    click BookDetailVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/book/presentation/BookDetailViewModel.kt"
    click BookReaderScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/reader/presentation/BookReaderScreen.kt"
    click OnboardingScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/onboarding/presentation/OnboardingScreen.kt"
    click OnboardingVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/onboarding/presentation/OnboardingViewModel.kt"
    click ProfileScreen "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/profile/presentation/ProfileScreen.kt"
    click ProfileVM "https://github.com/waseemabbas8/libroom-android/blob/main/app/src/main/java/com/waseem/libroom/feature/profile/presentation/ProfileViewModel.kt"

    %% Styles
    classDef presentation fill:#daffd6,stroke:#027502,stroke-width:1px
    classDef domain fill:#d6e0ff,stroke:#0433ff,stroke-width:1px,shape:round
    classDef data fill:#fff2cc,stroke:#ffb100,stroke-width:1px,shape:cylinder
    classDef external fill:#ffcccc,stroke:#ff0000,stroke-width:1px,shape:cloud
    classDef di fill:#f3d6ff,stroke:#a000ff,stroke-width:1px,shape:hexagon
```
