# vocdoni/vocdoni-node architecture

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

## Overview

This project, vocdoni-node, is the core component of Vocdoni’s decentralized governance protocol. It is a Golang-based distributed node integrating critical blockchain functionality (such as go-ethereum, go-ipfs, and tendermint) directly into a single process. The system can run in different operational modes (gateway and miner), and its architecture spans multiple domains, including API handling, cryptographic operations, blockchain indexing, and state management.

##### Main Components Identification
- API Layer & Node Modes: Represent the gateway mode (serving REST API calls, external requests, and blockchain sync) and miner (validator) mode.
- Command Line Tools & CLI: Incorporate the various “cmd” directories (cli, end2endtest, node, tools, voconed) that serve different operational and development/testing functions.
- Core Business Logic: Highlight the “api” package, which includes account management, elections, votes, and the integrated API server. Also mark the “apiclient” which wraps API interactions.
- Blockchain & Distributed Ledger Components: Include the “vochain” package (and subdirectories such as genesis, indexer, state, transaction, etc.) that encapsulate blockchain operations, state handling, and consensus management.
- Database & Storage Components: Illustrate “statedb”, the “db” directories (goleveldb, mongodb, pebbledb, etc.), and perhaps other storage utilities (data package, censustree) to highlight how persistent state and offchain data are handled.
- Cryptography and Zero-Knowledge Proofs: Show the “crypto” package (with submodules for Ethereum, nacl, saltedkey, and zk) and “subpub” libraries for secure communications.
- Additional Services: Include components like “service”, “snapshot”, and “tree” architecture for secondary functions such as indexing, data snapshots, and cryptographic proofs.
- External tools and integrations: Mention dockerfiles (for orchestration/deployment), testing suites, automation (GitHub workflows), and configuration modules.

##### Depicting Relationships & Interactions
- How the CLI and sandbox tools are used to interact with both API and low-level blockchain functionalities.
- Dependencies where the node (both gateway and miner mode) encapsulates third-party libraries (go-ethereum, go-ipfs, tendermint) for handling consensus and network operations, thereby eliminating external RPC/IPC.

##### Architectural Patterns & Design Principles
- Monolithic Process Integration: Emphasize that all components run within a single process to reduce inter-process communications overhead.
- Modular Design: Each package represents a specific concern (API, blockchain, crypto, storage, etc.), following separation of concerns.
- Extensibility: Several areas (such as the “crypto/zk” and “api/docs”) suggest that the design is built for easy extension, especially as new validation or consensus proof methods are added.
- Testability: The presence of a rich test directory and multiple “*_test.go” files highlights heavy emphasis on automated testing and robust quality assurance.

##### Technologies, Frameworks, and Libraries
- Golang as the primary language.
- Integrated libraries: go-ethereum, go-ipfs, tendermint (integrated as Go libraries).
- Various database solutions (goleveldb, mongodb, pebbledb) are abstracted and interchangeable.
- Docker and docker-compose configurations for deployment.
- Crypto libraries for Ethereum, nacl, and zero-knowledge circuits.

## Diagram (Mermaid)

```mermaid
graph TD

  %% Subgraph: API and Node Modes
  subgraph "API and Node Modes"
    API_Server["API Server (gateway)"]:::core
    Node_Operation["Node Operation (gateway/miner)"]:::core
  end

  %% Subgraph: Command Line Tools & CLI
  subgraph "Command Line Tools & CLI"
    CLI_Tools["CLI Tools"]:::tools
    End2End["End-to-End Testing"]:::tools
    Additional_Tools["Additional Tooling"]:::tools
  end

  %% Subgraph: Core Business Logic
  subgraph "Core Business Logic"
    API_Package["API Package (Business Logic)"]:::core
    API_Client["API Client"]:::core
  end

  %% Subgraph: Blockchain Engine
  subgraph "Blockchain Engine"
    Vochain["Blockchain Engine (VoChain)"]:::core
  end

  %% Subgraph: Database & Storage
  subgraph "Database & Storage"
    StateDB["State Database"]:::database
    DB_Adapters["DB Adapters"]:::database
    Data_Utilities["Data Utilities"]:::database
  end

  %% Subgraph: Cryptography & ZK Proofs
  subgraph "Cryptography & ZK Proofs"
    Crypto_Utils["Crypto Utilities"]:::crypto
    Subpub["Secure Communication (Subpub)"]:::crypto
  end

  %% Subgraph: Additional Services
  subgraph "Additional Services"
    Service_Svc["Supporting Services"]:::support
    Snapshot_Svc["Data Snapshotting"]:::support
    Tree_Proof["Tree & Proof Structures"]:::support
  end

  %% Subgraph: External Tools & Integrations
  subgraph "External Tools & Integrations"
    Docker["Dockerfiles & Orchestration"]:::deployment
    CICD["CI/CD & Automated Testing"]:::deployment
  end

  %% Relationships
  API_Server -->|"calls"| API_Package
  API_Package -->|"updates"| Vochain
  API_Package -->|"verifies"| Crypto_Utils
  Vochain -->|"storesState"| StateDB
  Vochain -->|"readsFrom"| DB_Adapters
  Vochain -->|"fetchesData"| Data_Utilities
  CLI_Tools -->|"triggers"| Node_Operation
  CLI_Tools -->|"executes"| API_Package
  End2End -->|"tests"| API_Server
  Additional_Tools -->|"inspects"| Vochain
  Crypto_Utils -->|"supports"| Service_Svc
  Subpub -->|"integratesWith"| Crypto_Utils
  Service_Svc -->|"generatesSnapshot"| Snapshot_Svc
  Tree_Proof -->|"validates"| Service_Svc
  Docker -->|"deploys"| Node_Operation
  CICD -->|"automates"| CLI_Tools

  %% Click Events
  click API_Server "https://github.com/vocdoni/vocdoni-node/blob/main/api/api.go"
  click Node_Operation "https://github.com/vocdoni/vocdoni-node/blob/main/cmd/node/main.go"
  click CLI_Tools "https://github.com/vocdoni/vocdoni-node/tree/main/cmd/cli/"
  click End2End "https://github.com/vocdoni/vocdoni-node/tree/main/cmd/end2endtest/"
  click Additional_Tools "https://github.com/vocdoni/vocdoni-node/tree/main/cmd/tools/"
  click API_Package "https://github.com/vocdoni/vocdoni-node/tree/main/api/"
  click API_Client "https://github.com/vocdoni/vocdoni-node/blob/main/apiclient/client.go"
  click Vochain "https://github.com/vocdoni/vocdoni-node/tree/main/vochain/"
  click StateDB "https://github.com/vocdoni/vocdoni-node/blob/main/statedb/statedb.go"
  click DB_Adapters "https://github.com/vocdoni/vocdoni-node/tree/main/db/"
  click Data_Utilities "https://github.com/vocdoni/vocdoni-node/tree/main/data/"
  click Crypto_Utils "https://github.com/vocdoni/vocdoni-node/tree/main/crypto/"
  click Subpub "https://github.com/vocdoni/vocdoni-node/tree/main/subpub/"
  click Service_Svc "https://github.com/vocdoni/vocdoni-node/tree/main/service/"
  click Snapshot_Svc "https://github.com/vocdoni/vocdoni-node/blob/main/snapshot/snapshot.go"
  click Tree_Proof "https://github.com/vocdoni/vocdoni-node/tree/main/tree/"
  click Docker "https://github.com/vocdoni/vocdoni-node/tree/main/dockerfiles/"
  click CICD "https://github.com/vocdoni/vocdoni-node/tree/main/.github/workflows/"

  %% Styles
  classDef core fill:#b3cde0,stroke:#6497b1,stroke-width:2px;
  classDef tools fill:#decbe4,stroke:#b3cde0,stroke-width:2px;
  classDef database fill:#fdae61,stroke:#d7191c,stroke-width:2px;
  classDef crypto fill:#fee08b,stroke:#f46d43,stroke-width:2px;
  classDef deployment fill:#d9ef8b,stroke:#1a9641,stroke-width:2px;
  classDef support fill:#ccebc5,stroke:#80b1d3,stroke-width:2px;
```
