# breadwallet/breadwallet-ios architecture

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

- Interactive diagram: https://gitdiagram.com/breadwallet/breadwallet-ios
- Repository: https://github.com/breadwallet/breadwallet-ios

## Overview

##### Main System Components

a. Core Components:
- Wallet Core (breadwallet/src/Wallet/)
- CoreSystem
- WalletInitializer
- Currency Management
- RescanCoordinator

b. Platform Services:
- Blockset Integration (External API)
- CloudKit Integration (for backup)
- Authentication Services
- Push Notification Services

c. User Interface Layer:
- View Controllers
- View Models
- Custom Views
- Widget Extension

##### Key Architectural Patterns to Highlight

a. Data Flow:
- How transactions flow from the blockchain through Blockset/SPV to the wallet
- Backup flow to iCloud
- Authentication flow with biometrics

b. Security Layer:
- Secure Enclave integration
- KeyStore management
- Encryption/Decryption flow

**┌─ User Interface Layer ─────────────────────┐**
- Home Screen                              │
- Transaction Views                        │
- Wallet Management                        │
- Settings & Security                      │
- Business Logic Layer ────────────────────┤
- Transaction Processing                   │
- Wallet Management                        │
- Currency Handling                        │
- Core Services Layer ────────────────────┤
- CoreSystem                              │
- KeyStore                                │
- Secure Storage                          │
- External Services Layer ─────────────────┤
- Blockset API                            │
- CloudKit                                │
- Push Notifications                      │
- ┘

##### Important Connections

- Secure Enclave ↔ KeyStore
- CoreSystem ↔ Blockset API
- Wallet ↔ Transaction Processing
- UI Layer ↔ Business Logic
- CloudKit ↔ Backup System

##### Additional Elements

- Version/environment indicators
- Critical security boundaries
- Backup paths
- User interaction points

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef ui fill:#e6e6fa,stroke:#333
    classDef core fill:#add8e6,stroke:#333
    classDef security fill:#90ee90,stroke:#333
    classDef external fill:#ffa500,stroke:#333
    classDef data fill:#f0f8ff,stroke:#333
    classDef critical fill:#ff6b6b,stroke:#333

    %% User Interface Layer
    subgraph UI
        VC["View Controllers"]
        VM["View Models"]
        CV["Custom Views"]
        WE["Widget Extension"]
        SC["Security Center"]
    end

    %% Business Logic Layer
    subgraph BLL
        CS["CoreSystem"]
        WI["WalletInitializer"]
        CM["Currency Management"]
        RC["RescanCoordinator"]
        TP["Transaction Processing"]
    end

    %% Core Services Layer
    subgraph CSL
        KS["KeyStore"]
        SE["Secure Enclave"]
        CD["Core Database"]
        PS["Platform Storage"]
    end

    %% External Services Layer
    subgraph ESL
        BI["Blockset Integration"]
        CK["CloudKit Integration"]
        PN["Push Notifications"]
        AC["API Client"]
        AN["Analytics"]
        AS["Authentication Services"]
    end

    %% Relationships
    VC --> VM
    VM --> CV
    VM --> WE
    VC --> SC

    VM --> CS
    CS --> WI
    CS --> CM
    CS --> RC
    CS --> TP

    TP --> KS
    KS --> SE
    CS --> CD
    CS --> PS

    CS --> BI
    CS --> CK
    CS --> PN
    CS --> AC
    AC --> AN
    CS --> AS

    %% Click events
    click VC "https://github.com/breadwallet/breadwallet-ios/tree/master/breadwallet/src/ViewControllers/"
    click VM "https://github.com/breadwallet/breadwallet-ios/tree/master/breadwallet/src/ViewModels/"
    click CV "https://github.com/breadwallet/breadwallet-ios/tree/master/breadwallet/src/Views/"
    click WE "https://github.com/breadwallet/breadwallet-ios/tree/master/breadwalletWidget/"
    click SC "https://github.com/breadwallet/breadwallet-ios/tree/master/breadwallet/src/ViewControllers/SecurityCenter/"
    
    click CS "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Wallet/CoreSystem.swift"
    click WI "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Wallet/WalletInitializer.swift"
    click CM "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Wallet/Currency.swift"
    click RC "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Wallet/RescanCoordinator.swift"
    
    click KS "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/KeyStore/KeyStore.swift"
    click CD "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Wallet/CoreDatabase.swift"
    click PS "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Platform/BRReplicatedKVStore.swift"
    
    click BI "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Platform/BRAPIClient.swift"
    click CK "https://github.com/breadwallet/breadwallet-ios/tree/master/breadwallet/src/CloudBackup/"
    click PN "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/NotificationHandler.swift"
    click AC "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/ExternalAPIClient/ExternalAPIClient.swift"
    click AN "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Platform/BRAnalyticsEvent.swift"
    click AS "https://github.com/breadwallet/breadwallet-ios/blob/master/breadwallet/src/Platform/AuthenticationClient.swift"

    %% Style applications
    class VC,VM,CV,WE ui
    class CS,WI,CM,RC,TP core
    class KS,SE,SC security
    class BI,CK,PN,AC,AN,AS external
    class CD,PS data
```
