# chanubc/photos-lrucache architecture

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

- Interactive diagram: https://gitdiagram.com/chanubc/photos-lrucache
- Repository: https://github.com/chanubc/photos-lrucache

## Overview

##### Project type and purpose
- This is a single-module Android application (Kotlin, Jetpack Compose) whose primary purpose is to load, display, and cache images using an LRU-based two-level cache (memory + disk) before falling back to network download. It follows Google’s recommended Android App Architecture (MVI + MVVM, Repository pattern, Observer pattern).

##### File structure
- Top-level “app” module with standard Android Gradle layout.
- Under app/src/main/java/com/chanu/photocache: two main packages:
- core – contains common base classes (MVI constructs), data layer (cache, network, repository abstractions & DI), models, design system UI, navigation types
- feature – three feature packages (main/NavHost, home list screen, detail screen) holding Composables, ViewModels, intents/states, navigation
- DI modules under core/data/di and core/network/di using Hilt
- Cache layer under core/data/cache (MemoryCache, DiskCache, BitmapFetcher)
- Paging source under core/data/paging
- Network layer under core/network (Retrofit services, DTOs, modules)
- Compose UI under core/designsystem + feature/* screens
- Build scripts (Gradle Kotlin DSL), ProGuard rules, test folders

##### README for additional insights
- Confirms architectural decisions: MVI + MVVM, Repository + Observer patterns, layering (UI vs Data), Hilt DI, Paging3, Retrofit2+OkHttp, kotlinx-serialization, Timber logging
- Describes key flows (image load order: memory → disk → network) and custom behaviors (thumbnail, blur/grayscale, zoom, retry, error handling)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        MS["MainScreen"]:::ui
        HS["HomeScreen"]:::ui
        DS["DetailScreen"]:::ui
    end

    %% Navigation Layer
    subgraph "Navigation Host"
        direction TB
        MA["MainActivity"]:::nav
        MN["MainNavigator"]:::nav
        HN["HomeNavigation"]:::nav
        DN["DetailNavigation"]:::nav
        CR["Route & NavTypes"]:::nav
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        HVM["HomeViewModel"]:::presentation
        DVM["DetailViewModel"]:::presentation
        BI["BaseIntent"]:::presentation
        BS["BaseState"]:::presentation
        BV["BaseViewModel"]:::presentation
        SE["SideEffect"]:::presentation
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RI["HomeRepository (interface)"]:::data
        II["ImageLoaderRepository (interface)"]:::data
        RImpl1["DefaultHomeRepository"]:::data
        RImpl2["DefaultImageLoaderRepository"]:::data
        PS["HomePagingSource"]:::data
        HM["HomeMapper"]:::data
    end

    %% Cache Layer
    subgraph "Cache Layer"
        direction TB
        MC["MemoryCache"]:::cache
        DC["DiskCache"]:::cache
        BF["BitmapFetcher"]:::cache
        CM["CacheModule"]:::cache
    end

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        HSvc["HomeService"]:::network
        DTO["ResponsePhotoDto"]:::network
        NX["StringExt"]:::network
        NM["NetworkModule"]:::network
        SM["ServiceModule"]:::network
    end

    %% DI Layer
    subgraph "DI Layer"
        direction TB
        RepoM["RepositoryModule"]:::di
        CacheM["CacheModule"]:::di
        NetM["NetworkModules"]:::di
    end

    %% Design System
    subgraph "Design System"
        direction TB
        DSC["Components"]:::design
        DSE["Extensions"]:::design
        DST["Theme"]:::design
    end

    %% Domain Models
    subgraph "Domain Models"
        direction TB
        PM["PhotoModel"]:::model
        CE["CustomError"]:::model
    end

    %% External Service
    API["Image API Endpoint"]:::external

    %% Connections
    MS -->|Intent| HVM
    HS -->|Intent| HVM
    DS -->|Intent| DVM

    HVM -->|suspend call| RI
    DVM -->|suspend call| II

    RI -->|uses| RImpl1
    II -->|uses| RImpl2

    RImpl1 -->|checks| MC
    RImpl1 -->|checks| DC
    RImpl1 -->|fetch| HSvc
    RImpl1 -->|save| MC
    RImpl1 -->|save| DC
    RImpl2 -->|delegate| BF

    BF -->|memory→disk→network| MC
    BF --> DC
    BF --> HSvc

    RImpl1 -->|uses| PS
    PS -->|emit pages| HVM

    HSvc -->|Retrofit call| API
    HSvc -->|returns DTO| DTO
    DTO -->|mapped| HM

    HVM -->|StateFlow| MS
    DVM -->|StateFlow| DS

    %% DI injections
    RepoM -->|provides| RImpl1
    RepoM --> RImpl2
    CacheM --> MC
    CacheM --> DC
    NetM --> HSvc
    NetM --> NM
    NetM --> SM

    %% DesignSystem usage
    MS --> DSC
    HS --> DSC
    DS --> DSC

    %% Click Events
    click MS "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/main/MainScreen.kt"
    click HS "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/home/HomeScreen.kt"
    click DS "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/detail/DetailScreen.kt"
    click MA "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/main/MainActivity.kt"
    click MN "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/main/MainNavigator.kt"
    click HN "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/home/naviagation/HomeNavigation.kt"
    click DN "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/detail/navigation/DetailNavigation.kt"
    click CR "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/navigation/Route.kt"
    click CR "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/navigation/ParcelableNavType.kt"
    click HVM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/home/HomeViewModel.kt"
    click DVM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/feature/detail/DetailViewModel.kt"
    click BI "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/common/base/BaseIntent.kt"
    click BS "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/common/base/BaseState.kt"
    click BV "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/common/base/BaseViewModel.kt"
    click SE "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/common/base/SideEffect.kt"
    click RI "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/repository/HomeRepository.kt"
    click II "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/repository/ImageLoaderRepository.kt"
    click RImpl1 "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/repositoryimpl/DefaultHomeRepository.kt"
    click RImpl2 "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/repositoryimpl/DefaultImageLoaderRepository.kt"
    click PS "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/paging/HomePagingSource.kt"
    click HM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/mapper/HomeMapper.kt"
    click MC "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/cache/datasource/MemoryCache.kt"
    click DC "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/cache/datasource/DiskCache.kt"
    click BF "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/cache/datasource/BitmapFetcher.kt"
    click CM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/cache/di/CacheModule.kt"
    click HSvc "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/network/datasource/HomeService.kt"
    click DTO "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/network/dto/ResponsePhotoDto.kt"
    click NX "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/network/util/StringExt.kt"
    click NM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/network/di/NetworkModule.kt"
    click SM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/network/di/ServiceModule.kt"
    click RepoM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/di/RepositoryModule.kt"
    click CacheM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/data/cache/di/CacheModule.kt"
    click PM "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/model/PhotoModel.kt"
    click CE "https://github.com/chanubc/photos-lrucache/blob/main/app/src/main/java/com/chanu/photocache/core/model/CustomError.kt"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064;
    classDef nav fill:#E8F5E9,stroke:#2E7D32;
    classDef presentation fill:#BBDEFB,stroke:#0D47A1;
    classDef data fill:#C8E6C9,stroke:#1B5E20;
    classDef cache fill:#FFE0B2,stroke:#E65100;
    classDef network fill:#F5F5F5,stroke:#616161;
    classDef di fill:#E1BEE7,stroke:#4A148C;
    classDef design fill:#FFF9C4,stroke:#F57F17;
    classDef model fill:#FFCDD2,stroke:#B71C1C;
    classDef external fill:#FCE4EC,stroke:#880E4F;
```
