# simplemobiletools/simple-gallery architecture

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

- Interactive diagram: https://gitdiagram.com/simplemobiletools/simple-gallery
- Repository: https://github.com/simplemobiletools/simple-gallery

## Overview

##### Main Components
- UI Layer: Represent the various activities (e.g., MainActivity, MediaActivity, EditActivity, SearchActivity) and fragments (e.g., PhotoFragment, VideoFragment, ViewPagerFragment) along with custom views (e.g., EditorDrawCanvas, MediaSideScroll).
- Business Logic & Controllers: Capture the classes handling the core functionality, such as asynchronous tasks (GetMediaAsyncTask), helper classes (MediaFetcher, FilterThumbnailsManager, File extension helpers), and configuration/utility classes (Constants, Config).
- Data Access Layer: Illustrate the data models (Directory, Medium, Favorite, DateTaken, etc.), DAO interfaces (DirectoryDao, MediumDao, WidgetsDao, etc.) and the GalleryDatabase classes that manage persistent storage.
- System Services & Receivers: Include Android broadcast receivers such as BootCompletedReceiver and RefreshMediaReceiver, which respond to system events.
- Resources & Assets: Although not “code,” it’s important to note the extensive resources folder (layouts, drawables, values) which support the UI design.
- Build and Deployment Infrastructure: Represent Gradle build configuration (build.gradle.kts, settings.gradle.kts, gradle wrapper) and the fastlane directory that manages metadata and release assets.
- Flavor-specific Code: Note the existence of separate flavors like “foss” and “proprietary” to highlight variations in code meant for different deployments.

##### Relationships and Interactions
- How the UI layer (activities, fragments, adapters) invokes methods in the business logic layer.
- Dependency connections between UI components and external utilities/libraries (e.g., image loading libraries like Glide or Picasso, which are hinted at in classes like MyGlideImageDecoder and PicassoRegionDecoder).
- How the app listens to Android system events via the registered broadcast receivers.
- Optionally, include a deployment pipeline block that moves from the source through Gradle builds to fastlane-managed release channels.

##### Architectural Patterns
- Layered Architecture: Group components in layers such as Presentation (UI), Domain/Business Logic, and Data Access.
- MVC or MVP-like pattern: Although not strictly enforced, the organization of activities/controllers, models, and helper classes suggests a separation of concerns.
- Flavor Variants: Highlight that the app uses different source sets (e.g., main, foss, proprietary) to tailor behavior for open-source versus pro versions.
- Modular Design: Given the large number of packages (dialogs, adapters, fragments, helpers) reflect a modular approach which makes it easier to extend functionality.

##### Detailing Relevant Technologies and Components
- Language & Framework: Kotlin and Android SDK.
- Build System: Gradle Kotlin DSL (build.gradle.kts, settings.gradle.kts) and fastlane for CI/CD.
- UI Technologies: Android layouts, dialogs, and custom views designed in XML.
- Data Persistence: SQLite (via GalleryDatabase) with DAO interfaces.
- External Libraries: Image processing libraries (Glide, Picasso) likely used by corresponding helper classes.
- System Services and Receivers: Android’s broadcast mechanisms are used to handle device boot completion and media updates.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer – Activities & Fragments"
        UI1["Activities"]:::ui
        UI2["Fragments"]:::ui
        UI3["Custom Views"]:::ui
    end

    subgraph "Business Logic & Controllers"
        BL1["Async Tasks"]:::logic
        BL2["Helper Classes"]:::logic
        BL3["Extensions & Utilities"]:::logic
    end

    subgraph "Data Access Layer"
        DAL1["Gallery Database"]:::data
        DAL2["DAO Interfaces"]:::data
        DAL3["Data Models"]:::data
    end

    subgraph "System Services & Receivers"
        SSR1["Receivers"]:::services
    end

    subgraph "Resources & Assets"
        RES1["Resources Folder"]:::resources
    end

    subgraph "Build & Deployment"
        BD1["Gradle Build Config"]:::build
        BD2["Fastlane Deployment"]:::build
    end

    subgraph "Flavor-specific Code"
        FS1["Debug Flavor"]:::flavor
        FS2["FOSS Flavor"]:::flavor
        FS3["Prepaid Flavor"]:::flavor
        FS4["Proprietary Code"]:::flavor
    end

    %% Interactions between layers
    UI1 -- "calls" --> BL2
    UI2 -- "calls" --> BL2
    UI3 -- "interacts" --> BL3

    BL1 -- "fetches_updates" --> DAL1
    BL2 -- "processes" --> DAL3
    BL2 -- "invokes" --> DAL2

    SSR1 -- "triggers" --> BL1
    BL1 -- "updates" --> UI1

    UI1 -- "uses" --> RES1
    UI2 -- "uses" --> RES1
    UI3 -- "uses" --> RES1

    BD1 -- "builds" --> FS1
    BD1 -- "builds" --> FS2
    BD1 -- "builds" --> FS3
    BD1 -- "builds" --> FS4

    BD2 -- "deploys" --> FS1
    BD2 -- "deploys" --> FS2
    BD2 -- "deploys" --> FS3
    BD2 -- "deploys" --> FS4

    %% Click Events for UI Layer
    click UI1 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities"
    click UI2 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments"
    click UI3 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views"

    %% Click Events for Business Logic & Controllers
    click BL1 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks"
    click BL2 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers"
    click BL3 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions"

    %% Click Events for Data Access Layer
    click DAL1 "https://github.com/simplemobiletools/simple-gallery/blob/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/databases/GalleryDatabase.kt"
    click DAL2 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces"
    click DAL3 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models"

    %% Click Events for System Services & Receivers
    click SSR1 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/kotlin/com/simplemobiletools/gallery/pro/receivers"

    %% Click Events for Resources & Assets
    click RES1 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/main/res"

    %% Click Events for Build & Deployment
    click BD1 "https://github.com/simplemobiletools/simple-gallery/blob/master/build.gradle.kts"
    click BD2 "https://github.com/simplemobiletools/simple-gallery/tree/master/fastlane"

    %% Click Events for Flavor-specific Code
    click FS1 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/debug"
    click FS2 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/foss"
    click FS3 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/prepaid"
    click FS4 "https://github.com/simplemobiletools/simple-gallery/tree/master/app/src/proprietary"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef logic fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef services fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef resources fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef build fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef flavor fill:#7FFFD4,stroke:#000,stroke-width:2px;
```
