# unstoppableswap/core architecture

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

## Overview

##### Main Components Identification

a) Core Components:
- Swap Protocol Implementation (swap/)
- GUI Application (src-gui/)
- Tauri Backend Bridge (src-tauri/)
- Cryptocurrency Nodes Integration:
- Monero Integration (monero-wallet/, monero-rpc/)
- Bitcoin Integration (visible in swap/src/bitcoin/)

b) Actor Types:
- Maker (ASB - Atomic Swap Backend)
- Taker (CLI/GUI Client)

##### Architectural Layers

**┌─ Presentation Layer ─────────────────────┐**
- GUI (React/Tauri Frontend)            │
- CLI Interface                         │
- Application Bridge ────────────────────┤
- Tauri Bindings                       │
- Core Protocol Layer ──────────────────┤
- Swap Protocol Implementation         │
- Network Communication               │
- Cryptocurrency Integration Layer ────┤
- Bitcoin Wallet/Node Interface      │
- Monero Wallet/Node Interface       │
- ┘

##### Key Interactions to Highlight

a) Network Flow:
- P2P Communication between Maker and Taker
- Tor Network Integration
- Libp2p Implementation

b) Swap Protocol Flow:
- Quote Exchange
- Setup Phase
- Lock Transactions
- Signature Exchange
- Redeem/Refund/Punish Mechanisms

##### Data Flow Representation

- User Interface → Protocol Communications
- Protocol → Blockchain Interactions
- Inter-party Communications (Maker ↔ Taker)
- Database Operations (SQLite)

##### Component Details

Frontend (GUI):
**┌─ GUI Layer ──────────────┐**
- React Components       │
- State Management      │
- API Integration       │
- ┘

Protocol Core:
**┌─ Swap Protocol ────────────┐**
- State Machines           │
- Cryptographic Operations │
- Transaction Management   │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Presentation Layer"
        GUI["GUI (React/Tauri)"]:::frontend
        CLI["CLI Interface"]:::frontend
    end

    subgraph "Application Bridge"
        TauriBridge["Tauri Backend Bridge"]:::bridge
    end

    subgraph "Core Protocol Layer"
        SwapProtocol["Swap Protocol Core"]:::core
        StateMachines["Protocol State Machines"]:::core
        NetworkComm["Network Communication"]:::network
        DB[(Database)]:::database
    end

    subgraph "Cryptocurrency Layer"
        BitcoinInt["Bitcoin Integration"]:::crypto
        MoneroInt["Monero Integration"]:::crypto
        TorProxy["Tor Proxy"]:::security
    end

    subgraph "Actor Components"
        MakerASB["Maker (ASB)"]:::actor
        TakerClient["Taker (Client)"]:::actor
    end

    %% Connections
    GUI --> TauriBridge
    CLI --> SwapProtocol
    TauriBridge --> SwapProtocol
    SwapProtocol --> StateMachines
    StateMachines --> NetworkComm
    NetworkComm --> TorProxy
    SwapProtocol --> DB
    
    StateMachines --> BitcoinInt
    StateMachines --> MoneroInt
    
    MakerASB <--> NetworkComm
    TakerClient <--> NetworkComm

    %% Click Events
    click GUI "https://github.com/UnstoppableSwap/core/tree/master/src-gui"
    click TauriBridge "https://github.com/UnstoppableSwap/core/tree/master/src-tauri"
    click SwapProtocol "https://github.com/UnstoppableSwap/core/tree/master/swap/src/protocol"
    click NetworkComm "https://github.com/UnstoppableSwap/core/tree/master/swap/src/network"
    click CLI "https://github.com/UnstoppableSwap/core/tree/master/swap/src/cli"
    click DB "https://github.com/UnstoppableSwap/core/tree/master/swap/src/database"
    click MakerASB "https://github.com/UnstoppableSwap/core/tree/master/swap/src/asb"
    click BitcoinInt "https://github.com/UnstoppableSwap/core/tree/master/swap/src/bitcoin"
    click MoneroInt "https://github.com/UnstoppableSwap/core/tree/master/monero-wallet"
    click TorProxy "https://github.com/UnstoppableSwap/core/blob/master/swap/src/common/tor.rs"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef bridge fill:#e74c3c,stroke:#c0392b,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef network fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef crypto fill:#e67e22,stroke:#d35400,color:white
    classDef security fill:#9b59b6,stroke:#8e44ad,color:white
    classDef actor fill:#1abc9c,stroke:#16a085,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Bridge["Bridge Component"]:::bridge
        Core["Core Component"]:::core
        Network["Network Component"]:::network
        Database["Database"]:::database
        Crypto["Crypto Integration"]:::crypto
        Security["Security Component"]:::security
        Actor["Actor Component"]:::actor
    end
```
