# truenetworkio/true architecture

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

- Interactive diagram: https://gitdiagram.com/truenetworkio/true
- Repository: https://github.com/truenetworkio/true

## Overview

##### Project type and purpose
- This is a Substrate-based blockchain node template written in Rust, split into multiple Cargo crates.
- It provides a node binary (`node/` crate) that spins up a peer-to-peer blockchain, a runtime (`runtime/` crate) compiled to Wasm containing FRAME pallets, and custom pallets (`pallets/algorithms`, `pallets/credentials`, `pallets/issuers`).
- It also includes AssemblyScript scripts (`asm-scripts/`) for generating Wasm artifacts and helper files for front-end integration or smart-contract-style modules.

##### File structure
Top-level crates and directories:
- `node/` – the blockchain node application (networking, consensus, RPC server, CLI, chain specs).
- `runtime/` – the state transition logic (Wasm runtime composed of FRAME pallets).
- `pallets/…` – custom FRAME pallets providing domain logic (algorithms, credentials, issuers).
- `asm-scripts/` – AssemblyScript project producing Wasm modules or demo front-ends.
- Tooling & config: `Cargo.toml`, `Containerfile`, Nix flake (`flake.nix`), `scripts/`, `.github/`, `.devcontainer/`, etc.

##### README for additional insights
- Confirms the split between node, runtime, and pallets.
- Highlights key subsystem responsibilities: libp2p networking, consensus (Aura, GRANDPA), RPC, chain spec, FRAME pallet composition via macros.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients" 
        direction TB
        PolkadotJS["Polkadot-JS Apps"]:::external
        P2PPeers["P2P Network Peers"]:::external
    end

    %% Node Binary
    subgraph "Node Binary (node/ crate)" 
        direction TB
        CLI["CLI Entry\nmain.rs"]:::core
        Lib["Library\nlib.rs"]:::core
        Service["Service & Consensus\nservice.rs"]:::network
        ChainSpec["Chain Spec\nchain_spec.rs"]:::network
        RPC["RPC Server\nrpc.rs"]:::network
        Command["CLI Commands\ncommand.rs"]:::core
        NodeCargo["Cargo.toml"]:::core
    end

    %% Runtime
    subgraph "Runtime (runtime/ crate) → Wasm" 
        direction TB
        RuntimeLib["Runtime Logic\nlib.rs"]:::core
        BuildRS["Build Script\nbuild.rs"]:::core
        RuntimeCargo["Cargo.toml"]:::core
        subgraph "FRAME Pallets"
            direction TB
            SystemPallet["FRAME System"]:::core
            UtilityPallet["FRAME Utility\n& Consensus"]:::core
            subgraph "Custom Pallets"
                direction TB
                AlgPallet["Algorithms\nalgorithms/src/lib.rs"]:::core
                CredPallet["Credentials\ncredentials/src/lib.rs"]:::core
                IssuersPallet["Issuers\nissuers/src/lib.rs"]:::core
            end
        end
    end

    %% Wasm VM
    WasmVM["Wasm Execution VM"]:::storage

    %% Storage
    RocksDB["RocksDB Storage"]:::storage

    %% AssemblyScript
    subgraph "AssemblyScript Scripts (asm-scripts/)" 
        direction TB
        ASIndex["assembly/index.ts"]:::external
        ASConfig["asconfig.json"]:::external
        ASBuild["build/"]:::external
        ASTests["tests/index.js"]:::external
        ASPkg["package.json"]:::external
    end

    %% Workspace & Tooling
    subgraph "Workspace & Tooling" 
        direction TB
        RootCargo["Cargo.toml (root)"]:::core
        Flake["flake.nix"]:::core
        Container["Containerfile"]:::core
        ShellNix["shell.nix"]:::core
        InitScript["scripts/init.sh"]:::core
        CI1[".github/workflows/check.yml"]:::core
        CI2[".github/workflows/release.yml"]:::core
        DevContainer[".devcontainer/devcontainer.json"]:::core
        README["README.md"]:::core
        Docs["docs/rust-setup.md"]:::core
    end

    %% Relationships
    PolkadotJS -->|RPC calls| RPC
    P2PPeers <-->|Gossip & block/tx| Service
    CLI --> Lib
    CLI --> Command
    Service -->|loads Wasm blob| WasmVM
    WasmVM --> RuntimeLib
    RuntimeLib --> SystemPallet
    SystemPallet --> UtilityPallet
    UtilityPallet --> AlgPallet
    UtilityPallet --> CredPallet
    UtilityPallet --> IssuersPallet
    Service --> RocksDB
    RootCargo -->|builds| NodeCargo
    RootCargo --> RuntimeCargo
    RootCargo -->|includes| Flint["pallets/algorithms"]:::core
    RootCargo -->|includes| Flcred["pallets/credentials"]:::core
    RootCargo -->|includes| Fliss["pallets/issuers"]:::core
    ASIndex -->|generates Wasm| WasmVM

    %% Click Events
    click CLI "https://github.com/truenetworkio/true/blob/main/node/src/main.rs"
    click Lib "https://github.com/truenetworkio/true/blob/main/node/src/lib.rs"
    click Service "https://github.com/truenetworkio/true/blob/main/node/src/service.rs"
    click ChainSpec "https://github.com/truenetworkio/true/blob/main/node/src/chain_spec.rs"
    click RPC "https://github.com/truenetworkio/true/blob/main/node/src/rpc.rs"
    click Command "https://github.com/truenetworkio/true/blob/main/node/src/command.rs"
    click NodeCargo "https://github.com/truenetworkio/true/blob/main/node/Cargo.toml"
    click RuntimeLib "https://github.com/truenetworkio/true/blob/main/runtime/src/lib.rs"
    click BuildRS "https://github.com/truenetworkio/true/blob/main/runtime/build.rs"
    click RuntimeCargo "https://github.com/truenetworkio/true/blob/main/runtime/Cargo.toml"
    click AlgPallet "https://github.com/truenetworkio/true/blob/main/pallets/algorithms/src/lib.rs"
    click CredPallet "https://github.com/truenetworkio/true/blob/main/pallets/credentials/src/lib.rs"
    click IssuersPallet "https://github.com/truenetworkio/true/blob/main/pallets/issuers/src/lib.rs"
    click ASIndex "https://github.com/truenetworkio/true/blob/main/asm-scripts/assembly/index.ts"
    click ASConfig "https://github.com/truenetworkio/true/blob/main/asm-scripts/asconfig.json"
    click ASBuild "https://github.com/truenetworkio/true/tree/main/asm-scripts/build/"
    click ASTests "https://github.com/truenetworkio/true/blob/main/asm-scripts/tests/index.js"
    click ASPkg "https://github.com/truenetworkio/true/blob/main/asm-scripts/package.json"
    click RootCargo "https://github.com/truenetworkio/true/blob/main/Cargo.toml"
    click Flake "https://github.com/truenetworkio/true/blob/main/flake.nix"
    click Container "https://github.com/truenetworkio/true/tree/main/Containerfile"
    click ShellNix "https://github.com/truenetworkio/true/blob/main/shell.nix"
    click InitScript "https://github.com/truenetworkio/true/blob/main/scripts/init.sh"
    click CI1 "https://github.com/truenetworkio/true/blob/main/.github/workflows/check.yml"
    click CI2 "https://github.com/truenetworkio/true/blob/main/.github/workflows/release.yml"
    click DevContainer "https://github.com/truenetworkio/true/blob/main/.devcontainer/devcontainer.json"
    click README "https://github.com/truenetworkio/true/blob/main/README.md"
    click Docs "https://github.com/truenetworkio/true/blob/main/docs/rust-setup.md"

    %% Styles
    classDef core fill:#AED6F1,stroke:#34495E,color:#34495E
    classDef network fill:#A9DFBF,stroke:#1D8348,color:#1D8348
    classDef external fill:#F5B041,stroke:#B9770E,color:#B9770E
    classDef storage fill:#D5D8DC,stroke:#424949,color:#424949
```
