# satoshiportal/bullbitcoin-mobile architecture

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

## Overview

This project is a mobile wallet application (“Bull Bitcoin Mobile”) built using Flutter that supports self-custodial Bitcoin and Liquid Network functionality. In other words, it is a full-stack mobile wallet that integrates multiple Bitcoin protocols, swap features, fee estimations, payjoin, hardware wallet support, and even integration with exchange services. The codebase employs a well-organized separation of concerns with distinct layers (e.g., UI, domain, data, and external integrations) and utilizes patterns like BLoC for state management.

##### Main Components
- Mobile Client UI: Represented by the “lib/ui”, “lib/features” (onboarding, home, send, receive, settings, pin_code, etc.) directories. This layer includes all the widget definitions, screens, and presentation logic.
- Application/State Management Layer: With extensive use of BLoC in “lib/features/*/presentation/bloc”, this layer manages state and user interactions.
- Domain Layer: Found in “lib/core/*/domain” and “lib/features/*/domain”. This encompasses entities, use cases, and business logic (for wallet operations, fee estimation, coin selection, swap management, and more).
- External Services and Libraries: Dependencies such as bdk, bdk-flutter, lwk, boltz-dart, and integration with external APIs (mempool.space, electrum servers, etc.) are referenced both in documentation (README) and through dedicated directories (like “op”, “doc”, etc).
- Platform-Specific Integrations: The Android, iOS, linux, macos directories indicate platform-specific implementations and integration points provided by Flutter. This points to native code wrappers or integration layers used for device functionalities (like secure storage and network access).
- DevOps and CI/CD: Presence of the “.github/workflows”, build scripts, and configuration files that manage analysis, building, and release processes.

##### Relationships and Data Flow
- The UI (presentation layer) dispatches events (via BLoC) that invoke use cases in the domain layer.
- Use cases call repository interfaces implemented in the data layer, which in turn fetch data either from local storage (secure storage via Hive or similar under “lib/core/storage”) or remote external services (e.g., fee estimators, electrum servers).
- External libraries and dependencies (e.g., bdk-flutter for wallet operations) act as building blocks within the domain and data layers.
- The mobile client also interacts with external APIs for exchange rate data, blockchain data, and swap services. Represent these with external connectors.
- Platform-specific modules (android, ios, etc.) provide the necessary bridge or wrapper services to ensure the mobile app interacts securely with device resources.

##### Architectural Patterns and Principles
- Layered Architecture: Clear separation between UI, state management, domain logic, and data sources.
- Repository Pattern: Interfacing between domain and data layers, ensuring testability and abstraction over data sources.
- Use Case (Interactor) Pattern: Each operation (wallet creation, fee estimation, coin selection, payjoin processing, etc.) is encapsulated as a use case.
- Modularization: Features and core services are split into different directories (e.g., “lib/features” for UI and specific flows, “lib/core” for business logic and external integrations).
- State Management: The extensive use of the BLoC pattern to manage app state and facilitate UI updates.

##### Relevant Technologies and Integrations
- Flutter (UI framework) with platform-specific adaptations for Android, iOS, macOS, and Linux.
- BDK, BDK-Flutter, and LWK for wallet backend functionality.
- Boltz and boltz-dart for atomic swaps.
- External APIs for mempool fee estimation, electrum servers for blockchain data, and Bull Bitcoin exchange for fiat-to-BTC interactions.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "DevOps and CI/CD"
        devops1["Workflows"]
        devops2["Build Scripts"]
    end

    subgraph "Mobile Client UI"
        ui1["Base UI"]
        ui2["Features UI"]
    end

    subgraph "Application/State Management (BLoC)"
        bloc1["BLoC (App Startup)"]
        bloc2["BLoC (Bitcoin Price)"]
    end

    subgraph "Domain Layer"
        domain1["Core Domain"]
        domain2["Feature Domain"]
    end

    subgraph "Data Layer"
        data1["Core Data"]
        data2["Swaps Data"]
    end

    subgraph "External Services & Libraries"
        external1["Op Integrations"]
        external2["Documentation"]
    end

    subgraph "Platform-Specific Integrations"
        plat1["Android"]
        plat2["iOS"]
        plat3["Linux"]
        plat4["macOS"]
    end

    %% Data Flow Connections
    ui2 -->|"dispatchesEvent"| bloc1
    bloc1 -->|"invokesUseCase"| domain2
    domain1 -->|"callsRepository"| data1
    domain2 -->|"callsRepository"| data2
    data1 -->|"fetchesData"| external1
    data2 -->|"fetchesData"| external1
    ui1 -->|"deviceIntegration"| plat1
    ui1 -->|"deviceIntegration"| plat2
    ui1 -->|"deviceIntegration"| plat3
    ui1 -->|"deviceIntegration"| plat4

    %% Click Events
    click ui1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/ui"
    click ui2 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/features"
    click bloc1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/features/app_startup/presentation/bloc"
    click bloc2 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/features/bitcoin_price/presentation/bloc"
    click domain1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/core/bitcoin/domain"
    click domain2 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/features/onboarding/domain"
    click data1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/core/bitcoin/data"
    click data2 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/lib/core/swaps/data"
    click external1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/op"
    click external2 "https://github.com/satoshiportal/bullbitcoin-mobile/blob/develop/doc/jks.md"
    click plat1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/android"
    click plat2 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/ios"
    click plat3 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/linux"
    click plat4 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/macos"
    click devops1 "https://github.com/satoshiportal/bullbitcoin-mobile/tree/develop/.github/workflows"
    click devops2 "https://github.com/satoshiportal/bullbitcoin-mobile/blob/develop/build.yaml"

    %% Styles
    classDef devops fill:#ddd,stroke:#333,stroke-width:2px;
    classDef ui fill:#f9f,stroke:#333,stroke-width:2px;
    classDef bloc fill:#ccf,stroke:#333,stroke-width:2px;
    classDef domain fill:#cfc,stroke:#333,stroke-width:2px;
    classDef data fill:#fc9,stroke:#333,stroke-width:2px;
    classDef external fill:#cff,stroke:#333,stroke-width:2px;
    classDef platform fill:#fdd,stroke:#333,stroke-width:2px;

    class devops1,devops2 devops;
    class ui1,ui2 ui;
    class bloc1,bloc2 bloc;
    class domain1,domain2 domain;
    class data1,data2 data;
    class external1,external2 external;
    class plat1,plat2,plat3,plat4 platform;
```
