# joinmarket-org/joinmarket-clientserver architecture

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

- Interactive diagram: https://gitdiagram.com/joinmarket-org/joinmarket-clientserver
- Repository: https://github.com/joinmarket-org/joinmarket-clientserver

## Overview

##### Project Type and Purpose
- This project is a specialized Bitcoin transaction application focused on enabling CoinJoin transactions. Its purpose is to mix coins (via market makers and market takers) to improve bitcoin privacy and fungibility.
- The README emphasizes both the market dynamics (makers vs. takers) and crucial wallet features (e.g., coin isolation, multiple mixdepths, PayJoin support, and GUI for join operations).

##### File Structure
- Key directories and modules include:
- The “src” folder with several submodules:
▪ jmbase – Contains common utilities and low-level operations (arguments, crypto functions, work proofs, etc.)
▪ jmbitcoin – Implements bitcoin-specific functionality (amount calculations, signature methods, output descriptors, etc.)
▪ jmclient – Implements wallet operations, coinjoin logic, client protocols, blockchain interfacing, and wallet services for both maker and taker roles.
▪ jmdaemon – Provides the background daemon supporting orderbook maintenance, IRC/messaging, protocol management, and other network-related functions.
▪ jmqtui – Supplies the Qt-based graphical interface for users (specifically the JoinMarket-Qt Taker role).
- The “scripts” directory – Contains command line tools that tie the backend processes to executable scripts (e.g., wallet-tool.py, joinmarketd.py, joinmarket-qt.py). These are the entry-points for different functions.
- “test” – Holds various test suites (unit tests, integration tests, Dockerfiles, and end-to-end testing scripts) that validate components and interactions.
- Additional configuration and packaging files (like Dockerfile, setup.cfg, pyproject.toml) indicate build and deployment concerns.

a. User Interfaces
- Command Line Interface (CLI) via scripts (wallet-tool.py, joinmarketd.py, etc.)
- Graphical User Interface (GUI) provided by the jmqtui module (JoinMarket-Qt)

b. Core Logic Modules (Backend)
- jmbase: The foundation layer with utility functions (arguments parsing, crypto, support utilities).
- jmbitcoin: Handles bitcoin-specific operations (transaction building, signing, output descriptors, dealing with keys/secp256k1 operations).
- jmclient: Implements the wallet’s and coinjoin’s business logic including:
▪ Wallet operations (managing funds, coin control, coinjoin parameters)
▪ Protocol implementations for connecting with makers and takers
▪ Handling of PayJoin and fidelity bonds.
- jmdaemon: Provides asynchronous processing, supports the orderbook, performs IRC messaging, and handles other network communications. It also likely manages the maker’s persistent presence.

c. External Systems and Flows
- Bitcoin Network: The system interacts with external Bitcoin nodes (via blockchaininterface in jmclient) and leverages bitcoin transactions.
- Orderbook/Market Communication: Indicates connections to public orderbooks or local orderbook setups (illustrated in the README with both clearnet and Tor addresses).
- External Dependencies: Use of Twisted (as suggested by twisted_utils in jmbase), cryptography libraries, and possibly dockerized deployments (see Dockerfile, test/Dockerfiles).

##### Interactions and Data Flow
- How the CLI and GUI components trigger operations in the backend modules:
- For example, a market taker might initiate a coinjoin via a script or GUI. That request flows into jmclient which, using functions from jmbase and jmbitcoin, creates a signed transaction.
- Simultaneously, the jmdaemon module manages network communications (orderbook messaging, IRC-based coordination) and exchanges protocol messages with market makers.
- How external blockchain/network services are incorporated:
- Data flow from the blockchain/network into the jmclient (through the blockchaininterface module).
- Communication channels from the jmdaemon to external peers using IRC and possibly Tor.
- Smart-contract like interactions that keep private keys secure (as stated in the README).

##### Architectural Patterns and Design Principles
- Modular Design: Each subdirectory (jmbase, jmbitcoin, jmclient, jmdaemon, jmqtui) encapsulates a specific domain of functionality.
- Separation of Concerns: UI layers, business logic (wallet, coinjoin operations) and network/daemon interactions are clearly isolated.
- Service-oriented / Microservice-like: Although not distributed over network boundaries internally, the design portrays independent running components (CLI, GUI, daemon) that interact with one another.
- Security and Privacy: Use of cryptographic functions, PayJoin, and fidelity bonds underscore that security is built in at each layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces
    subgraph "User Interfaces"
        subgraph "CLI Interfaces"
            CLI1["Wallet-Tool CLI"]:::ui
            CLI2["JoinMarketd CLI"]:::ui
            CLI3["JoinMarket-Qt CLI"]:::ui
        end
        GUI["JoinMarket-Qt (GUI)"]:::ui
    end

    %% Core Modules
    subgraph "Core Modules"
        UTIL["Core Utilities (jmbase)"]:::util
        BITCOIN["Bitcoin-Specific Ops (jmbitcoin)"]:::logic
        CLIENT["Wallet & CoinJoin Logic (jmclient)"]:::logic
        DAEMON["Background Daemon (jmdaemon)"]:::net
    end

    %% External Systems
    EXT_BTC["Bitcoin Network"]:::external
    EXT_ORDERBOOK["Orderbook/IRC Channels"]:::external

    %% Relationships from UI to Core Modules
    CLI1 -->|"triggers"| CLIENT
    CLI2 -->|"triggers"| CLIENT
    CLI3 -->|"triggers"| CLIENT
    GUI  -->|"triggers"| CLIENT

    %% Core Module Interactions
    CLIENT -->|"txCreation"| BITCOIN
    CLIENT -->|"utilize"| UTIL
    CLIENT -->|"broadcastTx"| EXT_BTC

    %% Daemon interactions
    DAEMON -->|"maintainOrderbook"| EXT_ORDERBOOK

    %% Click Events
    click CLI1 "https://github.com/joinmarket-org/joinmarket-clientserver/blob/master/scripts/wallet-tool.py"
    click CLI2 "https://github.com/joinmarket-org/joinmarket-clientserver/blob/master/scripts/joinmarketd.py"
    click CLI3 "https://github.com/joinmarket-org/joinmarket-clientserver/blob/master/scripts/joinmarket-qt.py"
    click GUI "https://github.com/joinmarket-org/joinmarket-clientserver/tree/master/src/jmqtui"
    click UTIL "https://github.com/joinmarket-org/joinmarket-clientserver/tree/master/src/jmbase"
    click BITCOIN "https://github.com/joinmarket-org/joinmarket-clientserver/tree/master/src/jmbitcoin"
    click CLIENT "https://github.com/joinmarket-org/joinmarket-clientserver/tree/master/src/jmclient"
    click DAEMON "https://github.com/joinmarket-org/joinmarket-clientserver/tree/master/src/jmdaemon"

    %% Styles
    classDef ui fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef util fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef logic fill:#a9dfbf,stroke:#229954,stroke-width:2px;
    classDef net fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef external fill:#d7bde2,stroke:#7d3c98,stroke-width:2px;
```
