# bitcoinj/bitcoinj architecture

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

- Interactive diagram: https://gitdiagram.com/bitcoinj/bitcoinj
- Repository: https://github.com/bitcoinj/bitcoinj

## Overview

##### Project Type and Purpose
- This is a multi-module Java library and toolset (“bitcoinj”) implementing the Bitcoin protocol.
- It provides two core libraries (base + core), plus CLI tools (wallettool, tools), a JavaFX template app (wallettemplate), example applications (Java + Kotlin), and comprehensive tests.

##### High-Level Module Structure
- build system (Gradle + settings.gradle + Docker/Containerfile)
- base module: low-level data types (Address, Base58, Bech32, Monetary, VarInt, Hash, Utils)
- core module: protocol+networking (Message, Serializer, PeerGroup, Peer, NetworkParameters), blockchain (Block, BlockChain, SPV or full-pruned stores), wallet (KeyChain, Wallet, Transaction, CoinSelector), script interpreter, crypto primitives
- tools module: batch/block importers, checkpoint builders
- wallettool module: CLI wallet creation, sync, dump (uses core + base + Protobuf)
- wallettemplate module: JavaFX GUI application skeleton (UI layer + controller + model)
- examples / examples-kotlin: sample apps demonstrating library usage
- integration-test & test-support modules: external-facing integration tests and support code

##### External Dependencies
- Java 8+ (base, core) and Java 17+ (tools, wallettool, wallettemplate, examples)
- Gradle (build orchestration)
- Google Protobuf (core RPC/serialization)
- Bitcoin P2P network (peers, block data)

##### Architectural Layers & Patterns
- Layered architecture:
- Data Model & Utilities (base)
- Protocol & Networking + Blockchain + Wallet + Crypto (core)
- Application/Tooling (tools, wallettool, wallettemplate, examples)
- Test layers (unit, integration)
- Modular design: each Gradle subproject builds independently and depends on lower layers
- Event-driven in core’s networking (listeners for block download, transactions)
- Strategy pattern in wallet (CoinSelector, TransactionSigner)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & CI
    subgraph "Build & CI"
        CI_Settings["settings.gradle"] 
        CI_Build["build.gradle"] 
        CI_Scan["build-scan-agree.gradle"] 
        CI_Container["build.Containerfile"] 
        CI_GH_Gradle[".github/workflows/gradle.yml"] 
        CI_GH_Graal[".github/workflows/graalvm.yml"] 
        CI_GitLab[".gitlab-ci.yml"] 
    end

    %% Libraries (Blue)
    subgraph "Libraries"
        Base["base (Data Model & Utilities)"] 
        Core["core (Protocol, Networking, Blockchain, Wallet, Crypto, Script, Store)"] 
    end

    %% CLI Tools (Green)
    subgraph "CLI Tools"
        Tools["tools (Batch/block importers, checkpoint builders)"] 
        WalletTool["wallettool (CLI wallet creation & sync)"] 
    end

    %% UI Applications (Orange)
    subgraph "UI Applications"
        WalletTemplate["wallettemplate (JavaFX GUI app skeleton)"] 
    end

    %% Examples & Tests (Gray)
    subgraph "Examples & Tests"
        ExamplesJava["examples (Java sample apps)"] 
        ExamplesKotlin["examples-kotlin (Kotlin sample app)"] 
        IntegrationTest["integration-test"] 
        TestSupport["test-support"] 
    end

    %% External Systems
    subgraph "External Systems" 
        BitcoinNet["Bitcoin P2P Network"] 
        Protobuf["Google Protobuf"] 
        FileSys["Local File System"] 
    end

    %% Build orchestration
    Gradle["Gradle & CI Orchestration"]

    %% Dependencies & Data Flows
    Gradle -->|orchestrates build| CI_Settings
    Gradle --> CI_Build
    Gradle --> Base
    Gradle --> Core
    Gradle --> Tools
    Gradle --> WalletTool
    Gradle --> WalletTemplate
    Gradle --> ExamplesJava
    Gradle --> ExamplesKotlin
    Gradle --> IntegrationTest
    Gradle --> TestSupport

    Base -->|compile-time dependency| Core
    Core -->|compile-time| Tools
    Core -->|compile-time| WalletTool
    Core -->|compile-time| WalletTemplate
    Core -->|compile-time| ExamplesJava
    Core -->|compile-time| ExamplesKotlin

    WalletTool -->|P2P sync| BitcoinNet
    WalletTemplate -->|wallet ops| Core
    WalletTemplate -->|P2P UI sync| BitcoinNet
    Tools -->|block import/checkpoints| Core

    %% External deps
    Core --> Protobuf
    WalletTool --> Protobuf

    %% File I/O
    WalletTool --> FileSys
    Tools --> FileSys
    Core --> FileSys

    %% Click Events for component mappings
    click CI_Settings "https://github.com/bitcoinj/bitcoinj/blob/master/settings.gradle"
    click CI_Build "https://github.com/bitcoinj/bitcoinj/blob/master/build.gradle"
    click CI_Scan "https://github.com/bitcoinj/bitcoinj/blob/master/build-scan-agree.gradle"
    click CI_Container "https://github.com/bitcoinj/bitcoinj/blob/master/build.Containerfile"
    click CI_GH_Gradle "https://github.com/bitcoinj/bitcoinj/blob/master/.github/workflows/gradle.yml"
    click CI_GH_Graal "https://github.com/bitcoinj/bitcoinj/blob/master/.github/workflows/graalvm.yml"
    click CI_GitLab "https://github.com/bitcoinj/bitcoinj/blob/master/.gitlab-ci.yml"

    click Base "https://github.com/bitcoinj/bitcoinj/tree/master/base/"
    click Base "https://github.com/bitcoinj/bitcoinj/blob/master/base/build.gradle"
    click Base "https://github.com/bitcoinj/bitcoinj/tree/master/base/src/main/java/org/bitcoinj/base/"
    click Base "https://github.com/bitcoinj/bitcoinj/tree/master/base/src/main/java/org/bitcoinj/base/internal/"
    click Base "https://github.com/bitcoinj/bitcoinj/tree/master/base/src/test/java/org/bitcoinj/base/"

    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/"
    click Core "https://github.com/bitcoinj/bitcoinj/blob/master/core/build.gradle"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/core/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/crypto/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/net/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/net/discovery/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/store/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/wallet/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/script/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/java/org/bitcoinj/jni/"
    click Core "https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/proto/wallet.proto"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/main/resources/"
    click Core "https://github.com/bitcoinj/bitcoinj/tree/master/core/src/test/java/org/bitcoinj/"

    click Tools "https://github.com/bitcoinj/bitcoinj/tree/master/tools/"
    click Tools "https://github.com/bitcoinj/bitcoinj/blob/master/tools/build.gradle"
    click Tools "https://github.com/bitcoinj/bitcoinj/blob/master/tools/src/main/java/org/bitcoinj/tools/BlockImporter.java"
    click Tools "https://github.com/bitcoinj/bitcoinj/blob/master/tools/src/main/java/org/bitcoinj/tools/BuildCheckpoints.java"
    click Tools "https://github.com/bitcoinj/bitcoinj/blob/master/tools/src/main/java/org/bitcoinj/tools/TestFeeLevel.java"
    click Tools "https://github.com/bitcoinj/bitcoinj/blob/master/tools/src/main/java/org/bitcoinj/tools/WatchMempool.java"

    click WalletTool "https://github.com/bitcoinj/bitcoinj/tree/master/wallettool/"
    click WalletTool "https://github.com/bitcoinj/bitcoinj/blob/master/wallettool/build.gradle"
    click WalletTool "https://github.com/bitcoinj/bitcoinj/blob/master/wallettool/src/main/graal/reflect-config.json"
    click WalletTool "https://github.com/bitcoinj/bitcoinj/blob/master/wallettool/src/main/graal/resource-config.json"
    click WalletTool "https://github.com/bitcoinj/bitcoinj/blob/master/wallettool/src/main/java/org/bitcoinj/wallettool/WalletTool.java"
    click WalletTool "https://github.com/bitcoinj/bitcoinj/blob/master/wallettool/src/test/java/org/bitcoinj/wallettool/WalletToolTest.java"

    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/tree/master/wallettemplate/"
    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/blob/master/wallettemplate/build.gradle"
    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/blob/master/wallettemplate/src/main/java/module-info.java"
    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/tree/master/wallettemplate/src/main/java/org/bitcoinj/walletfx/"
    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/tree/master/wallettemplate/src/main/resources/org/bitcoinj/walletfx"
    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/tree/master/wallettemplate/src/main/resources/wallettemplate/"
    click WalletTemplate "https://github.com/bitcoinj/bitcoinj/blob/master/wallettemplate/src/test/java/wallettemplate/WalletSetPasswordControllerTest.java"

    click ExamplesJava "https://github.com/bitcoinj/bitcoinj/tree/master/examples/"
    click ExamplesJava "https://github.com/bitcoinj/bitcoinj/blob/master/examples/build.gradle"
    click ExamplesJava "https://github.com/bitcoinj/bitcoinj/tree/master/examples/src/main/java/org/bitcoinj/examples/"

    click ExamplesKotlin "https://github.com/bitcoinj/bitcoinj/tree/master/examples-kotlin/"
    click ExamplesKotlin "https://github.com/bitcoinj/bitcoinj/blob/master/examples-kotlin/build.gradle"
    click ExamplesKotlin "https://github.com/bitcoinj/bitcoinj/blob/master/examples-kotlin/src/main/kotlin/org/bitcoinj/ForwardingService.kt"

    click IntegrationTest "https://github.com/bitcoinj/bitcoinj/tree/master/integration-test/"
    click IntegrationTest "https://github.com/bitcoinj/bitcoinj/blob/master/integration-test/build.gradle"
    click IntegrationTest "https://github.com/bitcoinj/bitcoinj/tree/master/integration-test/src/test/java/org/bitcoinj/"
    click IntegrationTest "https://github.com/bitcoinj/bitcoinj/tree/master/integration-test/src/test/resources/"

    click TestSupport "https://github.com/bitcoinj/bitcoinj/tree/master/test-support/"
    click TestSupport "https://github.com/bitcoinj/bitcoinj/blob/master/test-support/build.gradle"
    click TestSupport "https://github.com/bitcoinj/bitcoinj/tree/master/test-support/src/main/java/org/bitcoinj/test/support/"

    %% Styles
    classDef libraries fill:#cce5ff,stroke:#004085,color:#004085
    classDef cli fill:#d4edda,stroke:#155724,color:#155724
    classDef ui fill:#fff3cd,stroke:#856404,color:#856404
    classDef examples fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef ci fill:#f8d7da,stroke:#721c24,color:#721c24

    class Base,Core libraries
    class Tools,WalletTool cli
    class WalletTemplate ui
    class ExamplesJava,ExamplesKotlin,IntegrationTest,TestSupport examples
    class CI_Settings,CI_Build,CI_Scan,CI_Container,CI_GH_Gradle,CI_GH_Graal,CI_GitLab ci
```
