# adityam49/updoot architecture

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

## Overview

##### Main Components Identification
- ViewModels and Presentation Layer: Files like ActivityVM.kt, CommentsVM.kt, SearchVM, SettingsVM, and other “VM” components signal the ViewModel layer, generally handling UI state and interfacing with domain logic.
- Business Logic / Use Cases: There are many “UseCase” classes spread across modules (e.g., GetSubredditPostsUseCase, GetUserOverviewUseCasel, EditPostVoteUseCase, etc.) that encapsulate the application’s core logic.
- Data Layer: This is subdivided into:
- Local Data Sources: Under data/local and dataStore (for example, LinkMetaDataDAO, PostDAO, and UpdootDB) which likely use a local database or local persistence solutions.
- Remote Data Sources: APIs for authentication and Reddit services (e.g., AuthAPI, RedditAPI) along with remote data models and JSON adapters (Moshi adapters).
- Dependency Injection (DI): The DI components (ApiModule.kt, ApplicationModule.kt, NetworkModule.kt, PersistenceModule.kt, UseCaseModule.kt) orchestrate the creation and wiring of components.
- Background Processing: Workers such as CacheCleanUpWorker, ImageDownLoadWorker, and SubscriptionSyncWorker are used for asynchronous tasks (likely using WorkManager or a similar mechanism).
- Navigation Module: A separate module (“navigation”) contains navigation-related code (NavigationCommand, NavigationDirections, Event) to manage screen transitions.
- Account Management: Subsystem under utils/accountManagement (Authenticator, RedditClient, TokenInterceptor, etc.) that manages user authentication, OAuth tokens, and account interactions.

##### Relationships and Data Flow
- The ViewModels then call Use Cases that encapsulate core business logic.
- Use Cases interact with the Repository layer, which abstracts data access. This layer decides whether to use local (data/local) or remote (data/remote) data sources.
- Remote data sources communicate with Reddit’s API (handled by AuthAPI, RedditAPI) and apply transformations via mappers and Moshi adapters.
- DI modules glue together these interactions by providing the proper instances where needed.
- Background workers run tasks asynchronously to manage operations like caching and image downloads. They may also interface with the data layer to update the local database.
- The Navigation module works with the UI layer to manage screen transitions, with clear flow directives (from one screen to another based on user events).

##### Important Architectural Patterns and Design Principles
- MVVM Pattern: Clear separation between View (UI), ViewModel (presentation logic), and Model (data/business logic).
- Repository Pattern: The use of repositories to abstract the data sources (local database and remote API) and provide a clean API to the use cases.
- Dependency Injection: DI is used extensively for component configuration and testing ease.
- Asynchronous Processing: Background work is handled by dedicated worker components.
- Modularization: The app is divided into focused packages (accounts, comments, home, login, subreddit, etc.) which shows a separation of concerns.

##### Relevant Technologies, Frameworks, and Libraries
- Android Framework: With Activities, Views, and resources.
- Kotlin: The primary programming language.
- Gradle: For building the project (evident from build.gradle.kts, settings.gradle.kts, gradlew).
- Retrofit/Moshi (implied by Moshi adapters): For network calls and JSON parsing.
- Room or another local persistence library: For local database management (UpdootDB, DAOs).
- WorkManager (or similar): For scheduling background work (workers in backgroundWork folder).
- Navigation components: Although custom, the “navigation” module shows navigation logic.
- OAuth: Integration with Reddit using client credentials (as mentioned in README).

##### Specific Elements
- Background processes (workers) as separate components that interact with the Data Layer.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% User Interface Layer
    subgraph "User Interface"
        UI1("Login Activity"):::ui
        UI2("Home Screen"):::ui
        UI3("Comments Screen"):::ui
        UI4("Subreddit Screen"):::ui
        UI5("Settings Screen"):::ui
        UI6("User Screen"):::ui
    end

    %% Presentation Layer (ViewModels)
    subgraph "Presentation Layer"
        VM1("Activity ViewModel"):::vm
        VM2("Comments ViewModel"):::vm
        VM3("Login ViewModel"):::vm
        VM4("Explore ViewModel"):::vm
        VM5("Settings ViewModel"):::vm
        VM6("Subreddit ViewModel"):::vm
        VM7("Subreddit Options ViewModel"):::vm
        VM8("Subscriptions ViewModel"):::vm
        VM9("User ViewModel"):::vm
    end

    %% Business Logic / Use Cases
    subgraph "Business Logic / Use Cases"
        UC1("EditPostVote UseCase"):::usecase
        UC2("GetSubredditPosts UseCase"):::usecase
        UC3("SearchSubreddit UseCase"):::usecase
        UC4("GetUserOverview UseCase"):::usecase
        UC5("Other UseCases"):::usecase
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Local Data Sources"
            DLocal1("Local DAOs & Database"):::local
            DLocal2("Updoot DataStore"):::local
        end
        subgraph "Remote Data Sources"
            DRemote1("Auth API"):::remote
            DRemote2("Reddit API"):::remote
        end
        subgraph "Mappers/Adapters"
            DM1("Data Mappers"):::mapper
            DM2("Moshi Adapters"):::mapper
        end
    end

    %% Dependency Injection Modules
    subgraph "DI Modules"
        DI1("API Module"):::di
        DI2("Application Module"):::di
        DI3("Network Module"):::di
        DI4("Persistence Module"):::di
        DI5("UseCase Module"):::di
    end

    %% Background Processing
    subgraph "Background Processing"
        WP1("Cache CleanUp Worker"):::worker
        WP2("Image DownLoad Worker"):::worker
        WP3("Subscription Sync Worker"):::worker
    end

    %% Other Modules
    NAV("Navigation Module"):::nav
    AM("Account Management"):::account
    EXT("Reddit API/OAuth Service"):::external

    %%-----------------------------------------------
    %% Relationships

    %% UI interactions with ViewModels
    UI1 -->|"triggers"| VM3
    UI2 -->|"triggers"| VM1
    UI3 -->|"triggers"| VM2
    UI4 -->|"triggers"| VM6
    UI5 -->|"triggers"| VM5
    UI6 -->|"triggers"| VM9

    %% Navigation directs UI transitions
    NAV -->|"directs"| UI1
    NAV -->|"directs"| UI2
    NAV -->|"directs"| UI3
    NAV -->|"directs"| UI4
    NAV -->|"directs"| UI5
    NAV -->|"directs"| UI6

    %% ViewModels invoke Use Cases
    VM1 -->|"calls"| UC1
    VM2 -->|"calls"| UC2
    VM3 -->|"calls"| UC3
    VM9 -->|"calls"| UC4
    VM4 & VM5 & VM6 & VM7 & VM8 --- UC5

    %% Use Cases interact with Data Layer
    UC1 -->|"reads/writes"| DLocal1
    UC2 -->|"reads"| DLocal1
    UC3 -->|"fetches"| DRemote1
    UC4 -->|"reads"| DRemote2
    UC5 -->|"utilizes"| DM1

    %% Remote Data Sources use mappers/adapters
    DRemote1 -->|"maps"| DM2
    DRemote2 -->|"maps"| DM2

    %% Remote API calls external Reddit service
    DRemote2 -->|"calls"| EXT

    %% DI Modules inject dependencies
    DI1 -->|"provides"| VM1
    DI2 -->|"provides"| VM3
    DI3 -->|"injects"| DRemote2
    DI4 -->|"injects"| DLocal1
    DI4 -->|"injects"| DLocal2
    DI5 -->|"provides"| UC1

    %% Background Processing interactions
    WP1 -->|"cleans"| DLocal1
    WP3 -->|"syncs"| DLocal2
    WP2 -->|"fetches"| DRemote1

    %% Account Management relationships
    AM -->|"manages tokens for"| DRemote1
    AM -->|"integrates OAuth with"| EXT

    %%-----------------------------------------------
    %% Click Events

    %% UI Components
    click UI1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/login/LoginActivity.kt"
    click UI2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/home/HomeScreen.kt"
    click UI3 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/comments/CommentsScreen.kt"
    click UI4 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/subreddit/SubredditScreen.kt"
    click UI5 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/settings/SettingsScreen.kt"
    click UI6 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/user/UserScreen.kt"

    %% ViewModels
    click VM1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/ActivityVM.kt"
    click VM2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/comments/CommentsVM.kt"
    click VM3 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/login/LoginViewModel.kt"
    click VM4 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/search/ExploreVM.kt"
    click VM5 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/settings/SettingsVM.kt"
    click VM6 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/subreddit/SubredditVM.kt"
    click VM7 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/subreddit/options/SubredditOptionsVM.kt"
    click VM8 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/subscriptions/SubscriptionsVM.kt"
    click VM9 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/user/UserViewModel.kt"

    %% Use Cases
    click UC1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/subreddit/EditPostVoteUseCase.kt"
    click UC2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/subreddit/GetSubredditPostsUseCase.kt"
    click UC3 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/search/SearchSubredditUseCase.kt"
    click UC4 "https://github.com/adityam49/updoot/tree/master/app/src/main/java/com/ducktapedapps/updoot/user/"

    %% DI Modules
    click DI1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/di/ApiModule.kt"
    click DI2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/di/ApplicationModule.kt"
    click DI3 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/di/NetworkModule.kt"
    click DI4 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/di/PersistenceModule.kt"
    click DI5 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/di/UseCaseModule.kt"

    %% Data Layer - Local
    click DLocal1 "https://github.com/adityam49/updoot/tree/master/app/src/main/java/com/ducktapedapps/updoot/data/local/"
    click DLocal2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/data/local/dataStore/UpdootDataStore.kt"

    %% Data Layer - Remote
    click DRemote1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/data/remote/AuthAPI.kt"
    click DRemote2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/data/remote/RedditAPI.kt"

    %% Mappers/Adapters
    click DM1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/data/mappers/Mappers.kt"
    click DM2 "https://github.com/adityam49/updoot/tree/master/app/src/main/java/com/ducktapedapps/updoot/data/remote/moshiAdapters/"

    %% Background Workers
    click WP1 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/backgroundWork/CacheCleanUpWorker.kt"
    click WP2 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/backgroundWork/ImageDownLoadWorker.kt"
    click WP3 "https://github.com/adityam49/updoot/blob/master/app/src/main/java/com/ducktapedapps/updoot/backgroundWork/SubscriptionSyncWorker.kt"

    %% Navigation Module
    click NAV "https://github.com/adityam49/updoot/tree/master/navigation/src/main/java/com/ducktapedapps/navigation/"

    %% Account Management
    click AM "https://github.com/adityam49/updoot/tree/master/app/src/main/java/com/ducktapedapps/updoot/utils/accountManagement/"

    %%-----------------------------------------------
    %% Styles
    classDef ui fill:#f9e79f,stroke:#000,stroke-width:1px;
    classDef vm fill:#aed6f1,stroke:#000,stroke-width:1px;
    classDef usecase fill:#a9dfbf,stroke:#000,stroke-width:1px;
    classDef local fill:#f5cba7,stroke:#000,stroke-width:1px;
    classDef remote fill:#fad7a0,stroke:#000,stroke-width:1px;
    classDef mapper fill:#d7bde2,stroke:#000,stroke-width:1px;
    classDef di fill:#f5b7b1,stroke:#000,stroke-width:1px;
    classDef worker fill:#d5f5e3,stroke:#000,stroke-width:1px;
    classDef nav fill:#fcf3cf,stroke:#000,stroke-width:1px;
    classDef account fill:#d6eaf8,stroke:#000,stroke-width:1px;
    classDef external fill:#e8daef,stroke:#000,stroke-width:1px;
```
