# payjoin/rust-payjoin architecture

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

## Overview

##### Project Type and Purpose
- The project is a multi-crate Rust implementation for Payjoin—a method for collaborative Bitcoin transactions aimed at batching payments, lowering fees, and enhancing privacy.
- The project is intended for use with Bitcoin wallets and integrates with external systems (e.g., BTCPayServer, JoinMarket, WasabiWallet, Blue Wallet, Sparrow) to facilitate improved transactional privacy.

##### File Structure
- At the top level you see configuration files (Cargo.toml, docker-related configs, GitHub actions) indicating CI/CD and container deployment.
- There are several dedicated directories/crates:
- "payjoin": Core library containing modules for handling PSBT processing, sending and receiving payjoin transactions, handling different protocol versions (V1 and V2), along with utility modules (e.g., bech32, uri, error codes).
- "payjoin-cli": A CLI wrapper (with its own Dockerfile, README, tests, etc.) that makes use of the core library to operate as a reference implementation.
- "payjoin-directory": Implements the store-and-forward directory server required for asynchronous Payjoin V2 transactions.
- "payjoin-test-utils": Utility code for testing, indicating robust test support.
- The internal structure of the "payjoin" crate further splits into subdirectories like src/psbt, src/receive, src/send, and others—this separation is key to representing the various responsibilities within the core library.

##### Specific Elements
- Specify submodules within the library (like sending, receiving, PSBT, etc.) if space permits, to give a sense of granularity.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Payjoin Core Library subgraph with modules
    subgraph "Payjoin Core Library"
        CORE["Payjoin Core Library"]:::core
        CORE_PSBT["PSBT Processing"]:::core
        CORE_SEND["Send Module"]:::core
        CORE_RECEIVE["Receive Module"]:::core
        CORE_URI["URI & Utilities"]:::core
        CORE --> CORE_PSBT
        CORE --> CORE_SEND
        CORE --> CORE_RECEIVE
        CORE --> CORE_URI
    end

    %% Other major components
    CLI["Payjoin CLI"]:::cli
    DIR["Payjoin Directory"]:::directory
    EXW["External Wallet (Bitcoin Core etc.)"]:::external
    EXC["External Clients"]:::external
    TEST["Test Utilities"]:::test

    %% CI/CD & Linting subgraph
    subgraph "CI/CD & Linting"
        CI_GH["GitHub Actions"]:::test
        CI_CONTRIB["Contrib Scripts"]:::test
    end

    %% Connections between components
    CLI -->|"calls"| CORE
    DIR -->|"uses"| CORE

    CLI -->|"communicates"| EXW
    DIR <-->|"async calls"| EXC

    TEST -->|"tests"| CLI
    TEST -->|"tests"| DIR
    TEST -->|"tests"| CORE

    CI_GH -->|"supports"| TEST
    CI_CONTRIB -->|"supports"| TEST

    %% Styling classes for color coding
    classDef core fill:#FFF2CC,stroke:#B58900,stroke-width:2px;
    classDef cli fill:#DFF0D8,stroke:#40754C,stroke-width:2px;
    classDef directory fill:#D9E5FF,stroke:#3B7DD8,stroke-width:2px;
    classDef external fill:#F8D7DA,stroke:#C82333,stroke-width:2px;
    classDef test fill:#E2E3E5,stroke:#6C757D,stroke-width:2px;

    %% Click Events for component mapping (paths not visible in nodes)
    click CORE "https://github.com/payjoin/rust-payjoin/tree/master/payjoin/"
    click CLI "https://github.com/payjoin/rust-payjoin/tree/master/payjoin-cli/"
    click DIR "https://github.com/payjoin/rust-payjoin/tree/master/payjoin-directory/"
    click TEST "https://github.com/payjoin/rust-payjoin/tree/master/payjoin-test-utils/"
    click CI_GH "https://github.com/payjoin/rust-payjoin/tree/master/.github/"
    click CI_CONTRIB "https://github.com/payjoin/rust-payjoin/tree/master/contrib/"
```
