# blinddoggy/tronapi architecture

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

- Interactive diagram: https://gitdiagram.com/blinddoggy/tronapi
- Repository: https://github.com/blinddoggy/tronapi

## Overview

To accurately represent the architecture of the chia-blockchain project, follow these tailored guidelines.  Your goal is to decompose the system into logical components, show their relationships, and highlight the technologies and design patterns in use.

##### Project type and purpose
- This is a full-stack cryptocurrency implementation, written primarily in Python, with a small Node.js-based REST API layer under `server.js` + `src/`.
- Core functionality: run a full Chia node (consensus, block storage, mempool, networking), farming/harvesting, wallet services, timelords (VDF), and seeding (peer discovery).

##### Main components
a.  Client layer
- CLI (`chia` commands under `chia/cmds/`), built with Click and Python.
- Optional Web UI / REST API server (`server.js` + `src/controllers/*.js`) written in Node.js/Express.
b.  RPC/Gateway layer
- The Chia Daemon (`chia/daemon/server.py`) exposes JSON-RPC endpoints over HTTP on localhost.
- Node.js controllers and CLI tools communicate over these RPC endpoints.
c.  Service layer (each process is usually spawned by the daemon)
- Full Node (`chia/full_node/full_node.py` + `full_node_api.py`): block and mempool management, network syncing.
- Farmer (`chia/farmer/farmer.py` + `farmer_api.py`): block creation coordinator.
- Harvester (`chia/harvester/harvester.py` + `harvester_api.py`): reads polynomial proofs from disk.
- Wallet (`chia/wallet/wallet.py` + `wallet_node_api.py`): UTXO management, transaction creation.
- Timelord (`chia/timelord/timelord.py` + `timelord_api.py`): VDF orchestration.
- Introducer & Seeder (`chia/introducer/introducer.py`, `chia/seeder/crawler.py`): peer discovery & DNS seeder.
- Data Layer (`chia/data_layer/data_layer_server.py` + plugins): off-chain data storage via S3 or local store.
d.  Persistence layer
- Block store, coin store, mempool caches, SQLite / RocksDB wrappers under `chia/util/db_*` and `chia/full_node/*_store.py`.
- File-based “plots” and log files on disk.
e.  P2P network
- Protocol definitions (`chia/protocols/*.py`) and server (`chia/server/server.py`) implement gossip/flood-style messaging on TCP port 8444.
- UPnP support for NAT traversal.

##### Relationships & Data flows
1.  CLI / Web UI → HTTP RPC → Daemon
2.  Daemon → spawns/internal dispatch → each sub-service
3.  Full Node ↔ P2P Network ← other peers
4.  Farmer requests proofs from Harvester → proposes blocks to Full Node
5.  Wallet submits transactions to Full Node → broadcast to network
6.  Timelord ↔ Full Node chain snapshots for VDF proofs
7.  Data Layer plugin ↔ external S3 service or local object store
8.  Introducer/Seeder maintain peer lists and feed Full Node

##### Architectural patterns & principles
- Modular microservices: each daemon sub-service has its own RPC API.
- Hexagonal architecture: clear ports/adapters (CLI & Web UI are adapters, RPC is the port, services are the core).
- Event-driven & async: Python `asyncio` for networking and RPC.
- Domain separation: consensus (`chia/consensus/`), networking (`chia/server/`), storage (`chia/full_node/*_store.py`), CLI (`chia/cmds/`), puzzles (`chia/wallet/puzzles`, `chia/consensus/puzzles`).

##### Technologies & frameworks
- Python 3.8+ with asyncio, Click (CLI), JSON-RPC, uvicorn-like server for RPC.
- Node.js/Express for REST layer (if used).
- SQLite / RocksDB via Python wrappers.
- Jinja2 for build scripts (packaging).
- CLVM puzzles (.clsp/.clib) for smart‐contract logic.
- BLS signatures, Proof-of-Space & VDF cryptography.

##### Final checklist
- Component labels (e.g., Full Node, Farmer, Harvester)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph "Client Layer"
        CLI["CLI (chia/cmds/)"]:::pythonService
        REST["REST API (Node.js/Express)"]:::jsService
    end

    %% Gateway Layer
    subgraph "RPC/Gateway Layer"
        Daemon["Daemon (JSON-RPC HTTP 8555)"]:::pythonService
    end

    %% Services Layer
    subgraph "Chia Daemon Services"
        FullNode["Full Node"]:::pythonService
        Farmer["Farmer"]:::pythonService
        Harvester["Harvester"]:::pythonService
        Wallet["Wallet"]:::pythonService
        Timelord["Timelord"]:::pythonService
        Introducer["Introducer"]:::pythonService
        Seeder["Seeder"]:::pythonService
        DataLayer["Data Layer"]:::pythonService
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        BlockStore["Block Store DB"]:::storage
        CoinStore["Coin Store DB"]:::storage
        MempoolCache["Mempool Cache"]:::storage
        Plots["Plots on Disk"]:::storage
    end

    %% P2P Network
    subgraph "P2P Network"
        P2P["P2P Network (TCP 8444)"]:::external
        UPnP["UPnP NAT Traversal"]:::external
    end

    %% External Services
    S3["S3 Plugin"]:::external

    %% Connections
    CLI -->|"RPC 8555"| Daemon
    REST -->|"RPC 8555"| Daemon

    Daemon -->|spawn| FullNode
    Daemon -->|spawn| Farmer
    Daemon -->|spawn| Harvester
    Daemon -->|spawn| Wallet
    Daemon -->|spawn| Timelord
    Daemon -->|spawn| Introducer
    Daemon -->|spawn| Seeder
    Daemon -->|spawn| DataLayer

    FullNode ---|async P2P| P2P
    P2P ---|async| FullNode

    Harvester ---|requests proofs| Farmer
    Farmer ---|propose block| FullNode

    Wallet ---|submit tx| FullNode

    Timelord ---|chain snapshots| FullNode
    FullNode ---|chain snapshots| Timelord

    DataLayer ---|plugin| S3

    Introducer ---|peer list| FullNode
    Seeder ---|seed peers| FullNode

    FullNode --> BlockStore
    FullNode --> CoinStore
    FullNode --> MempoolCache
    Harvester --> Plots

    %% Click Events
    click CLI "https://github.com/blinddoggy/tronapi/tree/main/chia/cmds/"
    click REST "https://github.com/blinddoggy/tronapi/blob/main/server.js"
    click Daemon "https://github.com/blinddoggy/tronapi/blob/main/chia/daemon/server.py"

    click FullNode "https://github.com/blinddoggy/tronapi/blob/main/chia/full_node/full_node.py"
    click FullNode "https://github.com/blinddoggy/tronapi/blob/main/chia/full_node/full_node_api.py"

    click Farmer "https://github.com/blinddoggy/tronapi/blob/main/chia/farmer/farmer.py"
    click Farmer "https://github.com/blinddoggy/tronapi/blob/main/chia/farmer/farmer_api.py"

    click Harvester "https://github.com/blinddoggy/tronapi/blob/main/chia/harvester/harvester.py"
    click Harvester "https://github.com/blinddoggy/tronapi/blob/main/chia/harvester/harvester_api.py"

    click Wallet "https://github.com/blinddoggy/tronapi/blob/main/chia/wallet/wallet.py"
    click Wallet "https://github.com/blinddoggy/tronapi/blob/main/chia/wallet/wallet_node_api.py"

    click Timelord "https://github.com/blinddoggy/tronapi/blob/main/chia/timelord/timelord.py"
    click Timelord "https://github.com/blinddoggy/tronapi/blob/main/chia/timelord/timelord_api.py"

    click Introducer "https://github.com/blinddoggy/tronapi/blob/main/chia/introducer/introducer.py"
    click Introducer "https://github.com/blinddoggy/tronapi/blob/main/chia/introducer/introducer_api.py"

    click Seeder "https://github.com/blinddoggy/tronapi/blob/main/chia/seeder/crawler.py"
    click Seeder "https://github.com/blinddoggy/tronapi/blob/main/chia/seeder/crawler_api.py"

    click DataLayer "https://github.com/blinddoggy/tronapi/blob/main/chia/data_layer/data_layer_server.py"
    click DataLayer "https://github.com/blinddoggy/tronapi/blob/main/chia/data_layer/data_layer_api.py"
    click S3 "https://github.com/blinddoggy/tronapi/blob/main/chia/data_layer/s3_plugin_service.py"

    click P2P "https://github.com/blinddoggy/tronapi/blob/main/chia/server/server.py"
    click P2P "https://github.com/blinddoggy/tronapi/tree/main/chia/protocols/"
    click UPnP "https://github.com/blinddoggy/tronapi/blob/main/chia/server/upnp.py"

    click BlockStore "https://github.com/blinddoggy/tronapi/blob/main/chia/full_node/block_store.py"
    click CoinStore "https://github.com/blinddoggy/tronapi/blob/main/chia/full_node/coin_store.py"
    click MempoolCache "https://github.com/blinddoggy/tronapi/blob/main/chia/full_node/mempool.py"
    click Plots "https://github.com/blinddoggy/tronapi/blob/main/chia/util/db_wrapper.py"

    %% Styles
    classDef pythonService fill:#b2fab4,stroke:#2f6627,stroke-width:1px
    classDef jsService fill:#aedcff,stroke:#075985,stroke-width:1px
    classDef external fill:#ffcc99,stroke:#cc6600,stroke-width:1px
    classDef storage fill:#dddddd,stroke:#555555,stroke-width:1px
```
