# unsplash/unsplash-photopicker-android architecture

> Architecture diagram of the GitHub repository unsplash/unsplash-photopicker-android, 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/unsplash/unsplash-photopicker-android
- Repository: https://github.com/unsplash/unsplash-photopicker-android

## Overview

##### Project type and purpose
- This is an Android multi-module project consisting of:
- A library module (`photopicker`) that implements an Unsplash photo picker UI component.
- An example application module (`example`) that demonstrates how to integrate and use the picker.
- Purpose: provide a reusable, drop-in Android component to search Unsplash, display a gallery, let users pick photos, and return the results to the host app.

##### File structure
- Top-level:
- `settings.gradle`: includes `:photopicker` and `:example` modules.
- Root `build.gradle`, Gradle wrapper, CI/GitHub config and license.
- `photopicker` module:
- `src/main/java/com/unsplash/pickerandroid/photopicker` subdivided into:
– `data` (network models & endpoints)
– `domain` (data sources, repository, network state)
– `presentation` (activities, view models, adapters, views)
- `Injector.kt`: central dependency provider.
- `UnsplashPhotoPicker.kt`: Kotlin object used to initialize the library with API keys.
- Resources: drawables, layouts, styles for the picker UI.
- `example` module:
- Standard Android app structure demonstrating how to call `UnsplashPhotoPicker.init(...)` and start `UnsplashPickerActivity`.

##### README for additional insights
- Confirms library init flow: `init()` → `UnsplashPickerActivity` → return `UnsplashPhoto` list.
- Highlights external dependency on Unsplash HTTP API (access key, secret key).
- Shows minimal integration code in the host app.

a. Main components to represent:
1. Host Application (the `example` or any consumer app)
2. UnsplashPhotoPicker Library Module
- Initialization object (`UnsplashPhotoPicker`)
- Presentation layer (`UnsplashPickerActivity`, `PhotoShowActivity`, adapters, custom views)
- Domain layer (ViewModels, State objects, Listener interfaces)
- Data layer (Repositories, DataSources, NetworkEndpoints, DTOs)
3. External Service: Unsplash REST API
4. Android framework (Activities, Intents, ViewModels, RecyclerView)
b. Relationships and interactions:
- Host App calls `UnsplashPhotoPicker.init(app, key, secret)` → config stored in `Injector`.
- Host App launches `UnsplashPickerActivity` via Intent.
- `UnsplashPickerActivity` uses `UnsplashPickerViewModel` (via factory) to coordinate:
– Calls `Repository.searchPhotos(...)` or `loadMorePhotos()`
– Repository delegates to `SearchPhotoDataSource` / `LoadPhotoDataSource` (domain)
– DataSource uses `NetworkEndpoints` to make HTTP requests to Unsplash API
– JSON → `SearchResponse` → list of `UnsplashPhoto` DTOs
– ViewModel exposes LiveData of paging data + network state → UI updates via adapter
- User selects photo(s). Activity returns result Intent containing `ArrayList<UnsplashPhoto>`.
- Host App receives result in `onActivityResult`.
c. Architectural patterns and design principles:
- MVVM: Activities + Adapters observe ViewModel state.
- Clean layering: Data → Domain → Presentation
- Dependency Injection via simple `Injector` object
- Repository & DataSource pattern for paging and API abstractions
d. Technologies, frameworks, libraries:
- Kotlin, AndroidX, ViewModel, LiveData/Observer
- RecyclerView, custom Views
- Retrofit/OKHttp (implied by NetworkEndpoints) or similar HTTP client
- Gradle multi-module build

##### Final advice
- Be detailed: breakdown each module’s subcomponents.
- Key flows: initialization, API request, UI rendering, selection result.
- Keep the external Unsplash API as its own node to show the network dependency.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Application
    subgraph "Host Application"
        HostApp["Host App"]:::host
    end

    %% Library Module
    subgraph "photopicker Library"
        direction TB

        subgraph "Initialization"
            direction TB
            Init["UnsplashPhotoPicker"]:::init
            Injector["Injector"]:::init
            Init --> Injector
        end

        subgraph "Presentation Layer"
            direction TB
            UPActivity["UnsplashPickerActivity"]:::presentation
            PSActivity["PhotoShowActivity"]:::presentation
            Adapter["UnsplashPhotoAdapter"]:::presentation
            View["AspectRatioImageView"]:::presentation
            ViewModel["UnsplashPickerViewModel"]:::presentation
            Factory["UnsplashPickerViewModelFactory"]:::presentation
            State["UnsplashPickerState"]:::presentation
            Listener["OnPhotoSelectedListener"]:::presentation

            UPActivity --> ViewModel
            UPActivity --> Adapter
            UPActivity --> PSActivity
            ViewModel --> Adapter
        end

        subgraph "Domain Layer"
            direction TB
            Repo["Repository"]:::domain
            SearchFactory["SearchPhotoDataSourceFactory"]:::domain
            SearchDS["SearchPhotoDataSource"]:::domain
            LoadFactory["LoadPhotoDataSourceFactory"]:::domain
            LoadDS["LoadPhotoDataSource"]:::domain
            NetState["NetworkState"]:::domain

            ViewModel --> Repo
            Repo --> SearchFactory
            Repo --> LoadFactory
            SearchFactory --> SearchDS
            LoadFactory --> LoadDS
        end

        subgraph "Data Layer"
            direction TB
            Endpoints["NetworkEndpoints"]:::data
            SearchRes["SearchResponse"]:::data
            Photo["UnsplashPhoto"]:::data
            User["UnsplashUser"]:::data
            Urls["UnsplashUrls"]:::data
            Links["UnsplashLinks"]:::data

            SearchDS --> Endpoints
            LoadDS --> Endpoints
            Endpoints --> SearchRes
            SearchRes --> Photo
            Photo --> User
            Photo --> Urls
            Photo --> Links
        end

        subgraph "Resources"
            direction TB
            Layouts["Layouts"]:::resources
            Drawables["Drawables"]:::resources
            Values["Styles & Strings"]:::resources
        end
    end

    %% External Service
    UnsplashAPI["Unsplash REST API"]:::external

    %% Interactions
    HostApp -->|"init() & launch Intent"| Init
    HostApp -->|"startActivity Intent"| UPActivity
    UPActivity -->|"calls Repository"| Repo
    UPActivity -->|"API Request"| Endpoints
    Endpoints -->|"HTTP Request"| UnsplashAPI
    UnsplashAPI -->|"JSON Response"| Endpoints
    UPActivity -->|"return result Intent"| HostApp

    %% Click Events
    click HostApp "https://github.com/unsplash/unsplash-photopicker-android/tree/master/example/"
    click Init "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/UnsplashPhotoPicker.kt"
    click Injector "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/Injector.kt"
    click UPActivity "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/UnsplashPickerActivity.kt"
    click PSActivity "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/PhotoShowActivity.kt"
    click Adapter "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/UnsplashPhotoAdapter.kt"
    click View "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/AspectRatioImageView.kt"
    click ViewModel "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/UnsplashPickerViewModel.kt"
    click Factory "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/UnsplashPickerViewModelFactory.kt"
    click State "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/UnsplashPickerState.kt"
    click Listener "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/presentation/OnPhotoSelectedListener.kt"
    click Repo "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/domain/Repository.kt"
    click SearchFactory "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/domain/SearchPhotoDataSourceFactory.kt"
    click SearchDS "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/domain/SearchPhotoDataSource.kt"
    click LoadFactory "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/domain/LoadPhotoDataSourceFactory.kt"
    click LoadDS "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/domain/LoadPhotoDataSource.kt"
    click NetState "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/domain/NetworkState.kt"
    click Endpoints "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/data/NetworkEndpoints.kt"
    click SearchRes "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/data/SearchResponse.kt"
    click Photo "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/data/UnsplashPhoto.kt"
    click User "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/data/UnsplashUser.kt"
    click Urls "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/data/UnsplashUrls.kt"
    click Links "https://github.com/unsplash/unsplash-photopicker-android/blob/master/photopicker/src/main/java/com/unsplash/pickerandroid/photopicker/data/UnsplashLinks.kt"

    %% Styles
    classDef host fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef init fill:#ffeb99,stroke:#cc9900,stroke-width:1px;
    classDef presentation fill:#ffd1b3,stroke:#cc6600,stroke-width:1px;
    classDef domain fill:#d5f5e3,stroke:#27ae60,stroke-width:1px;
    classDef data fill:#cce5ff,stroke:#3399ff,stroke-width:1px;
    classDef resources fill:#e6e6e6,stroke:#999999,stroke-width:1px;
    classDef external fill:#e0e0e0,stroke:#666666,stroke-width:2px,stroke-dasharray: 5 5;
```
