# muun/apollo architecture

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

- Interactive diagram: https://gitdiagram.com/muun/apollo
- Repository: https://github.com/muun/apollo

## Overview

##### Project type and purpose
- This is a full-stack Android application: a non-custodial 2-of-2 multisig Bitcoin wallet.
- It follows “Clean Architecture”: separate layers for Data, Domain, Presentation, plus shared “common” code and a native Go-based “libwallet” library.

##### File structure
- Top-level Gradle modules:
- android/apollo     – Data + Domain layers
- android/apolloui   – Presentation (UI: Activities, Fragments, ViewModels)
- common             – Pure Java shared models and API mappers
- libwallet          – Native Go library for low-level wallet logic (compiled via gomobile)
- Each Android module follows:
android/apollo/src/main/java/io/muun/apollo/data    → data backends (network, DB, file system, OS)
android/apollo/src/main/java/io/muun/apollo/domain  → business logic, use-cases
android/apolloui/src/main/java/io/muun/apollo/presentation → UI layer
- Config files: Gradle scripts, Dockerfiles for containerized libwallet build, SQLDelight schema & migrations, ProGuard rules, CI workflows.

##### Extract architecture insights from README
- App enforces strict dependency direction:
Presentation → Domain → Data
- Data layer deals with network (Houston API over Retrofit/RxJava), local persistence (SQLDelight), async tasks, secure storage, OS services (Firebase, Google Drive).
- Domain layer orchestrates use-cases (Challenge keys, payments, swaps, session management).
- Presentation layer renders UI and only calls Domain use-cases (no direct Data references).
- The common module is reused by both Data and Domain layers (models, API JSON mappings).

1. Presentation Module (android/apolloui)
2. Domain Module (android/apollo/domain)
3. Data Module (android/apollo/data)
4. Common Module (common)
5. Native libwallet Module (libwallet via gomobile bridge)
6. External Services:
– Houston backend API
– Firebase Cloud Messaging
– Google Drive for Emergency Kit
7. Local Resources:
– SQLDelight database
– Android Keystore / Secure Storage
– File System (cache, disk)
– Presentation → Domain: invokes use-case actions (AsyncAction classes)
– Domain → Data: orchestrates data requests (network calls, DB reads/writes, OS services)
– Domain ↔ Common: shares models & JSON mappers
– Data → External Services: HTTP calls to Houston API, FCM registration, DriveUploader
– Data → SQLDelight: read/write wallet tables
– Data → Android OS: secure storage via KeyStoreProvider, background tasks via WorkManager/GCM
– Domain → libwallet: JNI bridge for transaction crafting & key operations
– Presentation ←→ OS: UI events, system services
c. Architectural patterns & principles:
– Clean Architecture: strict layer boundaries, Dependence Rule
– Dependency Injection (Dagger 2): wiring modules (DataComponent, DomainComponent, ApplicationComponent)
– Reactive streams (RxJava) for async flows
– SQLDelight for type-safe database
– JSII (gomobile bridge) for native Go library
d. Key technologies & libraries:
– Kotlin + Java, Android SDK
– Dagger 2 (DI)
– Retrofit + OkHttp + RxJava (network)
– SQLDelight (database)
– WorkManager / Firebase Manager (background jobs)
– Google Drive API (Emergency Kit export)
– Firebase Cloud Messaging / GCM
– Go Mobile (libwallet, JNI bridging)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        style PresentationLayer fill:#D0E6FF,stroke:#0288D1
        PresentationModule["Presentation Module\n(Activities, Fragments, ViewModels)"]:::frontend
        AppSetup["ApplicationComponent (DI)"]:::frontend
        UIComponents["UI ViewModels & Adapters"]:::frontend
    end

    %% Domain Layer
    subgraph "Domain Layer"
        style DomainLayer fill:#E0F7E9,stroke:#388E3C
        DomainModule["Domain Module\n(Use-Cases, Business Logic)"]:::domain
        DomainDI["ActionComponent & DI"]:::domain
        LibwalletBridge["Libwallet JNI Bridge"]:::native
    end

    %% Common Module
    CommonModule["Common Module\n(Models & Mappers)"]:::common

    %% Data Layer
    subgraph "Data Layer"
        style DataLayer fill:#FFF3E0,stroke:#F57C00
        DataModule["Data Module\n(Repositories)"]:::data
        DataDI["DataComponent & DI"]:::data
        Network["Network\n(Retrofit + RxJava)"]:::data
        SQLDelight["SQLDelight DB"]:::database
        SecureStorage["Secure Storage\n(Android Keystore)"]:::data
        AsyncTasks["Async Tasks & Background"]:::data
        DriveUploader["DriveUploader (Google Drive)"]:::data
    end

    %% Native libwallet
    subgraph "Native libwallet"
        style NativeLayer fill:#F3E5F5,stroke:#8E24AA
        LibwalletWrapper["Gradle Wrapper & Scripts"]:::native
        GoLibwallet["Go Source & Docker"]:::native
    end

    %% External Services
    subgraph "External & OS Services"
        style ExternalLayer fill:#ECEFF1,stroke:#607D8B
        HoustonAPI["Houston Backend API"]:::external
        Firebase["Firebase Cloud Messaging"]:::external
        GoogleDrive["Google Drive"]:::external
        AndroidOS["Android OS Services"]:::external
    end

    %% Relationships
    PresentationModule -->|invokes| DomainModule
    AppSetup -->|provides DI| PresentationModule
    UIComponents -->|binds to| DomainModule

    DomainModule -->|orchestrates| DataModule
    DomainModule -->|uses| LibwalletBridge
    DomainModule <-->|shares models| CommonModule

    DataModule -->|network calls| Network
    DataModule -->|db read/write| SQLDelight
    DataModule -->|storage| SecureStorage
    DataModule -->|background jobs| AsyncTasks
    DataModule -->|upload| DriveUploader
    DataModule <-->|uses models| CommonModule

    Network -->|HTTP| HoustonAPI
    AsyncTasks -->|register| Firebase
    DriveUploader -->|API| GoogleDrive
    SecureStorage -->|Keystore| AndroidOS
    LibwalletBridge -->|JNI calls| GoLibwallet

    %% Click Events
    click PresentationModule "https://github.com/muun/apollo/tree/master/android/apolloui/src/main/java/io/muun/apollo/presentation"
    click AppSetup "https://github.com/muun/apollo/tree/master/android/apolloui/src/main/java/io/muun/apollo/presentation/app/di"
    click UIComponents "https://github.com/muun/apollo/tree/master/android/apolloui/src/main/java/io/muun/apollo/presentation/ui/adapter"
    click DomainModule "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/domain"
    click DomainDI "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/domain/action/di"
    click LibwalletBridge "https://github.com/muun/apollo/blob/master/android/apollo/src/main/java/io/muun/apollo/domain/libwallet/LibwalletBridge.java"
    click DataModule "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/data"
    click DataDI "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/data/di"
    click Network "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/data/net"
    click SQLDelight "https://github.com/muun/apollo/tree/master/android/apollo/src/main/sqldelight/io/muun/apollo/data/db/migrations"
    click SecureStorage "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/data/os/secure_storage"
    click AsyncTasks "https://github.com/muun/apollo/tree/master/android/apollo/src/main/java/io/muun/apollo/data/async/tasks"
    click DriveUploader "https://github.com/muun/apollo/blob/master/android/apollo/src/main/java/io/muun/apollo/data/apis/DriveUploader.kt"
    click CommonModule "https://github.com/muun/apollo/tree/master/common/src/main/java/io/muun/common"
    click LibwalletWrapper "https://github.com/muun/apollo/tree/master/android/libwallet"
    click GoLibwallet "https://github.com/muun/apollo/tree/master/libwallet"
    click Firebase "https://github.com/muun/apollo/blob/master/android/apollo/src/main/java/io/muun/apollo/data/async/gcm/FirebaseManager.kt"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0288D1,color:#000;
    classDef domain fill:#E0F7E9,stroke:#388E3C,color:#000;
    classDef data fill:#FFF3E0,stroke:#F57C00,color:#000;
    classDef common fill:#ECEFF1,stroke:#607D8B,color:#000;
    classDef native fill:#F3E5F5,stroke:#8E24AA,color:#000;
    classDef external fill:#ECEFF1,stroke:#607D8B,color:#000;
    classDef database fill:#FFF9C4,stroke:#FBC02D,color:#000;
```
