# gemwalletcom/gem-ios architecture

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

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

## Overview

##### Project Overview and Main Components
- Application Frontend (UI)
– Built using SwiftUI and organized into numerous feature modules (e.g., Onboarding, WalletTab, Swap, Staking, PriceAlerts, NFT, QRScanner, etc.).
– Each module often follows an MVVM pattern: Scenes (views), ViewModels, and supporting types.
- Navigation and App Coordination
– Look at the Gem/Core folder and Gem/Root navigation and view models. These are the central coordinators that manage the app’s navigation and scene switching.
- Service Layer
– The “Services” directory provides backend support for business logic such as asset management, balance updates, notifications, blockchain data retrieval, node status, transaction processing, and WalletConnect.
- Data and Domain Libraries
– Packages such as Blockchain, Keystore, Primitives, and WalletCore supply critical infrastructure (e.g., secure cryptographic operations, multi-chain support, and key management).
– The “Store” package handles persistence (database, migrations, models for balances, transactions, etc.).
- UI Components & Styling
– Packages/Components and Packages/Style present reusable UI elements like list views, buttons, and custom controls, which ensure consistency across the application.
- External Integrations and Third-Party Communication
– GemAPI handles network requests toward external endpoints.
– SwiftHTTPClient abstracts HTTP communication.
– Integration with a Rust-based “Core” library provides secure cryptographic operations.

##### Layered Architecture and Relationships
- Presentation Layer:
- Business Logic / Service Layer:
– Represent services (e.g., AssetsService, BalanceService, PriceService, ChainService, etc.) as a separate block that the view models call into.
- Data & Domain Layer:
- External and Infrastructure Layer:
– External dependencies such as GemAPI and SwiftHTTPClient should be shown, along with the communication with external blockchain networks and dApps (used with WalletConnect).
– Include the “Core” Rust library (found under the core submodule and referenced in Gem’s README) as a secure cryptographic engine.
- Persistence:
– The “Store” package is responsible for local database interactions. It should be depicted as a storage block that feeds data into the Service Layer.

##### Architectural Patterns and Design Principles
- MVVM Pattern is prominently used within each feature module:
- Modularization using Swift Packages:
- Dependency Inversion & Abstraction:
– Service interfaces (protocols) and use of dependency injection (seen under Gem/Core/AppResolver) to allow for testability and replaceable implementations.
- Separation of Concerns:
– Clearly show the boundary between UI (presentation), business logic (services), and low-level domain operations (data/crypto packages).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer (UI)
    subgraph "Presentation Layer (UI)"
        subgraph "UI Feature Modules"
            onboarding["Onboarding Module"]:::ui
            wallettab["WalletTab Module"]:::ui
            swap["Swap Module"]:::ui
            staking["Staking Module"]:::ui
            pricealerts["PriceAlerts Module"]:::ui
            nft["NFT Module"]:::ui
            qrscanner["QRScanner Module"]:::ui
        end
        viewModels["View Models (MVVM)"]:::ui
    end

    %% UI Components & Styling
    subgraph "UI Components & Styling"
        uicomponents["UI Components"]:::ui
        stylepkg["Style Package"]:::ui
    end

    %% Navigation & Coordination
    subgraph "Navigation & Coordination"
        appResolver["App Resolver"]:::navigation
        navigation["Navigation"]:::navigation
        rootScene["Root Scene"]:::navigation
    end

    %% Business Logic / Service Layer
    subgraph "Business Logic / Service Layer"
        services["Services"]:::service
    end

    %% Data & Domain Libraries
    subgraph "Data & Domain Libraries"
        blockchain["Blockchain Package"]:::domain
        keystore["Keystore Package"]:::domain
        primitives["Primitives Package"]:::domain
        walletcore["WalletCore Package"]:::domain
    end

    %% Persistence Layer
    subgraph "Persistence"
        store["Store Package"]:::persistence
    end

    %% External & Infrastructure
    subgraph "External & Infrastructure"
        gemapi["GemAPI"]:::external
        swifthttp["SwiftHTTPClient"]:::external
        rustcore["Rust Core"]:::external
    end

    %% Flow Connections
    %% UI Feature Modules to View Models
    onboarding -->|"trigger"| viewModels
    wallettab  -->|"trigger"| viewModels
    swap       -->|"trigger"| viewModels
    staking    -->|"trigger"| viewModels
    pricealerts-->|"trigger"| viewModels
    nft        -->|"trigger"| viewModels
    qrscanner  -->|"trigger"| viewModels

    %% View Models to Navigation & Coordination
    viewModels -->|"coordinate"| appResolver

    %% Navigation to Service Layer
    appResolver -->|"resolves"| services
    navigation -->|"supports"| services
    rootScene   -->|"orchestrates"| services

    %% Service Layer to Data & Domain Libraries and Persistence
    services -->|"fetches"| blockchain
    services -->|"fetches"| keystore
    services -->|"fetches"| primitives
    services -->|"utilizes"| walletcore
    services -->|"persists"| store

    %% Service Layer to External Integrations
    services -->|"calls"| gemapi
    services -->|"calls"| swifthttp

    %% Domain Integration with Rust Core
    walletcore -->|"integrates"| rustcore

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef navigation fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef domain fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef persistence fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Click Events
    click onboarding "https://github.com/gemwalletcom/gem-ios/tree/main/Features/Onboarding"
    click wallettab "https://github.com/gemwalletcom/gem-ios/tree/main/Features/WalletTab"
    click swap "https://github.com/gemwalletcom/gem-ios/tree/main/Features/Swap"
    click staking "https://github.com/gemwalletcom/gem-ios/tree/main/Features/Staking"
    click pricealerts "https://github.com/gemwalletcom/gem-ios/tree/main/Features/PriceAlerts"
    click nft "https://github.com/gemwalletcom/gem-ios/tree/main/Features/NFT"
    click qrscanner "https://github.com/gemwalletcom/gem-ios/tree/main/Features/QRScanner"
    click appResolver "https://github.com/gemwalletcom/gem-ios/tree/main/Gem/Core/AppResolver"
    click navigation "https://github.com/gemwalletcom/gem-ios/tree/main/Gem/Root/Navigation"
    click rootScene "https://github.com/gemwalletcom/gem-ios/blob/main/Gem/Root/RootScene.swift"
    click services "https://github.com/gemwalletcom/gem-ios/tree/main/Services"
    click blockchain "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/Blockchain"
    click keystore "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/Keystore"
    click primitives "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/Primitives"
    click walletcore "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/WalletCore"
    click store "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/Store"
    click uicomponents "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/Components"
    click stylepkg "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/Style"
    click gemapi "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/GemAPI"
    click swifthttp "https://github.com/gemwalletcom/gem-ios/tree/main/Packages/SwiftHTTPClient"
    click rustcore "https://github.com/gemwalletcom/gem-ios/tree/main/core"
```
