# spacecowboy/feeder architecture

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

- Interactive diagram: https://gitdiagram.com/spacecowboy/feeder
- Repository: https://github.com/spacecowboy/feeder

## Overview

- User Interface Layer:
- Activities (e.g., MainActivity, AddFeedFromShareActivity, OpenLinkInDefaultActivity)
- Compose UI screens and components (found under app/src/main/java/com/nononsenseapps/feeder/ui/compose, including specific feature screens such as feed, article, navigation, settings, etc.)
- Traditional UI parts (legacy XML layouts and AndroidManifest definitions)
- Presentation / ViewModel / Business Logic Layer:
- ViewModels (e.g., MainActivityViewModel, EditFeedScreenViewModel, etc.)
- Architecture model classes in “archmodel” (Repository.kt, FeedStore, etc.) that mediate between UI and data
- Data Access and Persistence Layer:
- Room database (definitions in app/schemas and app/src/main/java/com/nononsenseapps/feeder/db/room such as AppDatabase.kt, FeedDao.kt, etc.)
- Content Provider (RSSContentProvider and its contract)
- Migrations and schema JSON files (used to evolve the database)
- Networking / Sync and External API Layer:
- Retrofit and Moshi setup for REST API calls (under app/src/main/java/com/nononsenseapps/feeder/sync, Retrofit.kt, SyncRestClient.kt)
- External service integration such as OpenAI APIs and Nostr feeds (under app/src/main/java/com/nononsenseapps/feeder/openai)
- Domain-related HTTP interceptors and rate limiters (files in the “model” folder)
- Background Processing and Job Services:
- Background tasks such as sync jobs, notification jobs, and full text synchronization (files in app/src/main/java/com/nononsenseapps/feeder/background, e.g., FeederJobService, RssSyncJob, etc.)
- Dependency Injection (DI) and Configuration Layer:
- DI configuration modules (in app/src/main/java/com/nononsenseapps/feeder/di) using Kodein DI (also visible in the org/kodein directory)
- Application initialization (FeederApplication.kt and ApplicationCoroutineScope.kt)
- Utility, Crypto, and Libraries:
- Cryptographic utilities (e.g., AesCbcWithIntegrity in crypto)
- Extensions and helper functions (Utilities, logging, error handling)
- External libraries like the bundled nostr-sdk (in app/libs) and support libraries provided via Gradle configuration

##### Relationships and Data Flow
- The UI layer (Activities/Compose screens) communicates with ViewModels, which in turn interact with the Repository and business logic (archmodel).
- The Repository abstracts access to the data layer where Room is used to store and retrieve feed content, and content providers expose some of that data.
- Network modules work with the Repository to fetch updates (feeds, articles) via REST APIs as well as processing background sync tasks.
- Dependency injection (DI) is used to inject ViewModels, repositories, network clients, and other dependencies across the layers.
- Background services (JobService, notifications, sync jobs) are triggered periodically or by user actions and coordinate with both the network and the database.

##### Architectural Patterns and Design Principles
- MVVM (Model–View–ViewModel) for a clean separation between UI and business logic.
- Repository Pattern for abstracting and unifying data operations from local (Room) and remote (network) sources.
- Dependency Injection (using Kodein) for flexible component wiring and testability.
- Layered architecture ensuring that UI, business logic, and data layers remain independent.
- Robust testing strategy (notice the extensive androidTest and test folders), which should be represented by including test harness components or noting that each layer is independently tested.

##### Relevant Technologies, Frameworks and Libraries
- Android SDK and Android Jetpack components (Room, Compose, LiveData/ViewModel)
- Retrofit, Moshi for networking and JSON parsing
- Kodein for DI (with compose integration)
- Gradle (Kotlin DSL) for builds
- CI/CD configurations (CircleCI, GitHub Actions, fastlane) which although not directly part of the runtime architecture, support the build and release pipelines

##### Instructing the Design
- Use clear labels for each component. For instance, label “UI – Activities & Compose Screens,” “ViewModel Layer,” “Repository/Business Logic,” “Room Database & Content Provider,” “Networking & API Clients,” “Background Services/Sync,” and “DI & Application Config.”
- Annotations or notes on any design patterns (like MVVM or Repository), and indicate how background processing interacts with the main application (e.g., through Job Services).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "User Interface Layer"
        UI_Activities("UI - Activities & Legacy XML"):::ui
        UI_Compose("Compose UI Screens & Components"):::ui
    end

    subgraph "Presentation / Business Logic Layer"
        VM("ViewModels"):::presentation
        Arch("ArchModel (Repository/FeedStore)"):::presentation
    end

    subgraph "Data Access and Persistence Layer"
        RoomDB("Room Database & Migrations"):::data
        CP("Content Provider"):::data
    end

    subgraph "Networking & External API Layer"
        Network("Networking (Retrofit/Moshi)"):::network
        ExtAPI("External API Integration (OpenAI, Nostr)"):::network
        Interceptor("Domain Interceptors & Rate Limiters"):::network
    end

    subgraph "Background Processing Layer"
        BG("Background Jobs & Sync Services"):::background
    end

    subgraph "Dependency Injection & App Config"
        DI("DI Modules (Kodein)"):::di
        AppInit("Application Initialization"):::di
    end

    subgraph "Utility & Libraries"
        Crypto("Crypto Utilities & Helpers"):::utility
        Lib("External Libraries (nostr-sdk)"):::utility
    end

    %% Connections between layers
    UI_Activities -->|"calls"| VM
    UI_Compose -->|"calls"| VM

    VM -->|"updates/gets data"| Arch
    Arch -->|"CRUD operations"| RoomDB
    Arch -->|"publishes data"| CP

    Arch -->|"requests updates"| Network
    Network -->|"fetches data"| ExtAPI
    Network -->|"applies"| Interceptor

    BG -->|"syncs/updates"| RoomDB
    BG -->|"triggers updates"| Network

    VM -->|"receives dependencies"| DI
    Arch -->|"receives dependencies"| DI
    Network -->|"receives dependencies"| DI

    DI -->|"initializes"| AppInit

    %% Utility interactions
    RoomDB -->|"secure logging"| Crypto
    VM -->|"helper calls"| Crypto
    Network -->|"security utilities"| Crypto
    AppInit -->|"configures"| Lib

    %% Click Events
    click UI_Activities "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/ui"
    click UI_Compose "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/ui/compose"
    click VM "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/ui"
    click Arch "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/archmodel"
    click RoomDB "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/db/room"
    click CP "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/contentprovider"
    click Network "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/sync"
    click ExtAPI "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/openai"
    click Interceptor "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/model"
    click BG "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/background"
    click DI "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/di"
    click AppInit "https://github.com/spacecowboy/feeder/blob/master/app/src/main/java/com/nononsenseapps/feeder/FeederApplication.kt"
    click Crypto "https://github.com/spacecowboy/feeder/tree/master/app/src/main/java/com/nononsenseapps/feeder/crypto"
    click Lib "https://github.com/spacecowboy/feeder/tree/master/app/libs"
    click DI "https://github.com/spacecowboy/feeder/tree/master/org/kodein/di/compose"

    %% Styles
    classDef ui fill:#f9c,stroke:#333,stroke-width:2px;
    classDef presentation fill:#cce,stroke:#333,stroke-width:2px;
    classDef data fill:#cfc,stroke:#333,stroke-width:2px;
    classDef network fill:#fcc,stroke:#333,stroke-width:2px;
    classDef background fill:#ff9,stroke:#333,stroke-width:2px;
    classDef di fill:#cff,stroke:#333,stroke-width:2px;
    classDef utility fill:#efe,stroke:#333,stroke-width:2px;
```
