# nanocurrency/nano-node architecture

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

## Overview

##### Main Components
- Nano Node Core: The heart of the project (found in directories like “nano/node”, “nano/nano_node”, “nano/nano_rpc”, etc.) that includes the node’s main functionality – transaction processing, consensus, block processing, and network communication.
- Network Layer & Transport: Components for peer-to-peer communication, handling TCP channels, in-process/inproc transport, IPC via flatbuffers, and other network-related operations (e.g., the “nano/node/transport” folder).
- Ledger & Storage: Subsystems responsible for storing blockchain data including blocks, accounts, confirmation heights, and caching (managed in the “nano/store” directory and its LMDB or RocksDB subcomponents).
- Consensus & Vote Processing: Modules handling elections, block confirmation, vote generation, and rebroadcasting (components in “nano/node” related to elections, votes, and the distributed work mechanism).
- RPC & API Services: An interface layer that serves as the public API (via RPC) for external clients and exchange integrations (evidenced by “nano/rpc”, “nano/nano_rpc”).
- Wallet & Security: Areas managing user wallets, private key security, and cryptographic operations (components in “nano/nano_wallet” and “nano/secure”).
- Cryptographic Libraries: Harnessing crypto routines for hashing (blake2) and signature verification (ed25519-donna) which are found in separate “crypto” directories.
- Auxiliary & Build/CI Infrastructure: The project includes comprehensive CI/CD pipelines (under “ci/”, “.github/”, “docker/”), build scripts (CMakeLists.txt, submodules for boost, flatbuffers, etc.), and test directories which are crucial for continuous integration and testing aspects but can be abstracted in the high-level overview.

##### Relationships and Interactions
- The Nano Node Core communicates with the network layer to exchange blocks, votes, and other messages with its peers.
- It also interacts directly with the ledger/storage sub-system to write or retrieve block and account data.
- The RPC/API layer serves as a gateway for external control and monitoring – passing commands between clients and the Nano Node Core.
- Wallet/security components connect to both the node core (for signing transactions) and to the secure storage (to manage wallet data).
- Cryptographic libraries are “called” by several modules (from consensus, vote processing, to signing) to offer secure hashing and signature functionality.
- The CI/CD scripts and test suites ensure that all of these components can be built, deployed, and tested reliably.

##### Architectural Patterns and Design Principles
- Modular Design: The project is divided into multiple self-contained modules (node, rpc, wallet, store, crypto) that interact with well-defined interfaces.
- Layered Architecture: There is a clear separation between the application logic (node, consensus, processing) and infrastructure (network transport and database storage).
- Asynchronous and Event-Driven Programming: Utilizing boost asio for networking and thread pools for managing concurrent processing (as seen in nano/boost/asio and threading components).
- Dependency Injection & Cross-platform Abstractions: The existence of platform-specific directories (e.g., “nano/lib/plat”) shows that the system is designed to work across multiple operating systems.
- CI/CD and Automation: Extensive automation scripts (in “ci/”, “docker/”) ensure that building, testing, and deployment are managed efficiently.

##### Relevant Technologies, Frameworks, and Libraries
- C++ with CMake Build System: Core implementation is in C++ with CMake as the main build configuration.
- Boost (ASIO, Beast, and Process): Used for asynchronous I/O, networking, and other utilities (visible in the “nano/boost” directory and submodules).
- LMDB and RocksDB: For database storage in the ledger component (“nano/store/lmdb”, “nano/store/rocksdb”).
- Flatbuffers: For fast IPC and serialization (noted in “api/flatbuffers” and “nano/ipc_flatbuffers_lib”).
- Cryptographic libraries: ed25519-donna and blake2 implementations are part of the crypto submodules.
- CI/CD Tools: GitHub Actions, GitLab CI, Docker – all play a role in deployment and testing.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Interfaces
    subgraph "External Interfaces"
        rpc["RPC & API Services"]:::interface
        wallet["Wallet & Security"]:::interface
    end

    %% Core Layer
    subgraph "Core Layer"
        nodecore["Nano Node Core"]:::core
        consensus["Consensus & Vote Processing"]:::core
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        network["Network Layer & Transport"]:::network
        ledger["Ledger & Storage"]:::storage
        crypto["Cryptographic Libraries"]:::crypto
    end

    %% Auxiliary Infrastructure
    aux["Auxiliary & Build/CI Infrastructure"]:::ci

    %% Connections
    rpc -->|"controls"| nodecore
    wallet -->|"signs"| nodecore
    nodecore <-->|"communicates"| network
    nodecore -->|"stores"| ledger
    nodecore -->|"manages"| consensus
    nodecore -->|"calls"| crypto
    aux -->|"supports"| nodecore
    aux -->|"supports"| network
    aux -->|"supports"| ledger
    aux -->|"supports"| consensus
    aux -->|"supports"| crypto

    %% Click Events
    click nodecore "https://github.com/nanocurrency/nano-node/tree/develop/nano/nano_node"
    click nodecore "https://github.com/nanocurrency/nano-node/tree/develop/nano/node"
    click network "https://github.com/nanocurrency/nano-node/tree/develop/nano/node/transport"
    click ledger "https://github.com/nanocurrency/nano-node/tree/develop/nano/store"
    click ledger "https://github.com/nanocurrency/nano-node/tree/develop/nano/store/lmdb"
    click ledger "https://github.com/nanocurrency/nano-node/tree/develop/nano/store/rocksdb"
    click consensus "https://github.com/nanocurrency/nano-node/tree/develop/nano/node"
    click rpc "https://github.com/nanocurrency/nano-node/tree/develop/nano/nano_rpc"
    click rpc "https://github.com/nanocurrency/nano-node/tree/develop/nano/rpc"
    click wallet "https://github.com/nanocurrency/nano-node/tree/develop/nano/nano_wallet"
    click wallet "https://github.com/nanocurrency/nano-node/tree/develop/nano/secure"
    click crypto "https://github.com/nanocurrency/nano-node/tree/develop/crypto/blake2"
    click crypto "https://github.com/nanocurrency/nano-node/tree/develop/crypto/ed25519-donna"
    click crypto "https://github.com/nanocurrency/nano-node/tree/develop/nano/crypto"
    click aux "https://github.com/nanocurrency/nano-node/tree/develop/ci"
    click aux "https://github.com/nanocurrency/nano-node/blob/develop/.github"
    click aux "https://github.com/nanocurrency/nano-node/tree/develop/docker"

    %% Styles
    classDef interface fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef core fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef network fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef storage fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef crypto fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef ci fill:#FFE4E1,stroke:#333,stroke-width:2px;
```
