# vcity-team/vcitychain architecture

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

- Interactive diagram: https://gitdiagram.com/vcity-team/vcitychain
- Repository: https://github.com/vcity-team/vcitychain

## Overview

#### Purpose and Entry Points
This is a Go implementation of a Polygon Edge–style EVM blockchain node, with pluggable consensus (DPoS/PolyBFT, IBFT, development), P2P networking, transaction execution, synchronization, bridge/root-chain operations, and operator tooling. The primary binary begins at `main.go`, builds the command hierarchy in `command/root/root.go`, and starts a node through `command/server/server.go` and `server/server.go`.

#### Node Composition and Lifecycle
`server/server.go` is the runtime composition boundary: it connects chain configuration, blockchain storage, state execution, consensus, networking, txpool, sync, RPC, and system services. `server/config.go` defines node-level configuration, while `server/system_service.go` exposes node management over generated gRPC interfaces in `server/proto/system.proto`. The CLI is both the node launcher and an operational control plane, including genesis, secrets, peers, status, backup, rollback, and root/sidechain commands.

#### Chain, Blocks, and Persistent Storage
The canonical chain layer in `blockchain/blockchain.go` validates, stores, finalizes, and publishes blocks; subscriptions in `blockchain/subscription.go` let dependent subsystems react to chain events. Storage is abstracted by `blockchain/storage/storage.go`, with LevelDB production persistence at `blockchain/storage/leveldb/leveldb.go` and an in-memory implementation for ephemeral/test use. Archive operations provide offline chain data boundaries through `archive/backup.go` and `archive/restore.go`.

#### EVM State Transition Boundary
Transactions and block execution enter the state layer through `state/executor.go` and `state/txn.go`. Account/storage state is maintained in an immutable Merkle trie under `state/immutable-trie/state.go` and `state/immutable-trie/trie.go`. The execution runtime dispatches EVM bytecode in `state/runtime/evm/evm.go`, with native protocol behavior isolated as precompiles in `state/runtime/precompiled/precompiled.go`. This separates consensus block selection from deterministic execution and state-root production.

#### Transaction Admission and Public APIs
The transaction pool in `txpool/txpool.go` accepts, validates, orders, and tracks pending transactions; event subscriptions are managed by `txpool/event_manager.go`. JSON-RPC requests are routed by `jsonrpc/dispatcher.go`, with Ethereum-compatible methods in `jsonrpc/eth_endpoint.go`, txpool methods in `jsonrpc/txpool_endpoint.go`, and bridge/DPoS extensions in `jsonrpc/bridge_endpoint.go` and `jsonrpc/dpos_endpoint.go`. RPC queries cross into blockchain, state, txpool, and network abstractions rather than directly owning those stores.

#### Networking and Synchronization
The libp2p-oriented network server lives in `network/server.go`, with peer discovery in `network/discovery/discovery.go`, gossip in `network/gossip.go`, and gRPC transport support in `network/grpc/grpc.go`. Consensus and sync traffic use generated protobuf contracts under `network/proto/` and consensus-specific proto directories. `syncer/syncer.go` coordinates peer selection, trusted/canonical tip decisions, block ingestion, and state healing; `syncer/service.go` is its service-facing boundary.

#### Consensus, Validators, and Cross-Chain Protocols
Consensus is selected through the common contract in `consensus/consensus.go`. The active feature-rich DPoS implementation is centered on `consensus/dpos/dpos.go` and `consensus/dpos/consensus_runtime.go`; it combines validator/stake state, epoch transitions, governance, BLS signatures, block production, fault handling, rewards, and state-sync/checkpoint logic. Legacy/alternative engines remain in `consensus/ibft/ibft.go`, `consensus/polybft/polybft.go`, and `consensus/dev/dev.go`. Validator cryptography and sets are shared in `validators/set.go` and `bls/signature.go`. Root-chain deployment, staking, validator registration, bridge transfers, and checkpoint-related operator workflows are exposed under `command/rootchain/rootchain.go` and `command/bridge/bridge.go`, implying integration with external EVM root-chain contracts.

#### Secrets and Deployment Runtime
Node and validator keys are accessed through a provider abstraction in `secrets/secrets.go`, with local filesystem, AWS SSM, GCP Secret Manager, and HashiCorp Vault backends at `secrets/local/local.go`, `secrets/awsssm/aws_ssm.go`, `secrets/gcpssm/gcp_ssm.go`, and `secrets/hashicorpvault/hashicorp_vault.go`. Local containerized operation is supported by `docker/local/docker-compose.yml`. The docs README is scoped to the separate MkDocs documentation site under `docs/`, not the node’s primary runtime.

Main entry points: [`server/server.go`](https://github.com/vcity-team/vcitychain/blob/develop/server/server.go) (Node server), [`blockchain/blockchain.go`](https://github.com/vcity-team/vcitychain/blob/develop/blockchain/blockchain.go) (Blockchain), [`state/executor.go`](https://github.com/vcity-team/vcitychain/blob/develop/state/executor.go) (State executor), [`consensus/dpos/consensus_runtime.go`](https://github.com/vcity-team/vcitychain/blob/develop/consensus/dpos/consensus_runtime.go) (DPoS runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Operations"]
  node_main["Node binary<br/>Go entrypoint<br/>[main.go]"]
  node_cli["Command hierarchy<br/>CLI control plane<br/>[root.go]"]
  node_server_command["Server command<br/>CLI launcher<br/>[server.go]"]
end

subgraph group_node["Node Runtime"]
  node_node_server{{"Node server<br/>runtime composition<br/>[server.go]"}}
  node_node_config["Node configuration<br/>configuration model<br/>[config.go]"]
  node_txpool["Transaction pool<br/>transaction admission<br/>[txpool.go]"]
  node_secrets["Secrets providers<br/>key-provider abstraction<br/>[secrets.go]"]
end

subgraph group_chain["Chain &amp; Execution"]
  node_blockchain{{"Blockchain<br/>canonical chain<br/>[blockchain.go]"}}
  node_storage[("Chain storage<br/>storage abstraction<br/>[storage.go]")]
  node_executor{{"State executor<br/>state transition<br/>[executor.go]"}}
  node_trie[("Immutable Merkle trie<br/>account state<br/>[state.go]")]
  node_evm["EVM runtime<br/>bytecode execution<br/>[evm.go]"]
  node_archive["Archive backup<br/>offline chain export<br/>[backup.go]"]
end

subgraph group_networking["Networking &amp; Sync"]
  node_network{{"Network server<br/>libp2p networking<br/>[server.go]"}}
  node_syncer["Syncer<br/>chain synchronization<br/>[syncer.go]"]
end

subgraph group_consensus["Consensus &amp; Cross-Chain"]
  node_consensus_contract["Consensus contract<br/>engine interface<br/>[consensus.go]"]
  node_dpos{{"DPoS runtime<br/>primary consensus engine"}}
  node_validators["Validator set<br/>validator cryptography<br/>[set.go]"]
  node_rootchain_cli["Root-chain operations<br/>operator workflows<br/>[rootchain.go]"]
end

subgraph group_interfaces["Public Services"]
  node_system_service["System service<br/>gRPC management API<br/>[system_service.go]"]
  node_jsonrpc["JSON-RPC dispatcher<br/>Ethereum RPC API<br/>[dispatcher.go]"]
end

node_main -->|"builds"| node_cli
node_cli -->|"launch command"| node_server_command
node_server_command -->|"starts"| node_node_server
node_node_config -->|"configures"| node_node_server
node_node_server -->|"hosts"| node_blockchain
node_node_server -->|"hosts"| node_txpool
node_node_server -->|"hosts"| node_network
node_node_server -->|"hosts"| node_syncer
node_node_server -->|"selects"| node_consensus_contract
node_node_server -->|"serves"| node_jsonrpc
node_node_server -->|"serves"| node_system_service
node_node_server -->|"loads keys"| node_secrets
node_blockchain -->|"persists blocks"| node_storage
node_blockchain -->|"validates execution"| node_executor
node_executor -->|"reads and commits state"| node_trie
node_executor -->|"dispatches bytecode"| node_evm
node_txpool -->|"prevalidates transactions"| node_executor
node_jsonrpc -->|"queries chain"| node_blockchain
node_jsonrpc -->|"submits and queries txs"| node_txpool
node_network -->|"provides peers and transport"| node_syncer
node_syncer -->|"ingests canonical blocks"| node_blockchain
node_consensus_contract -->|"implemented by"| node_dpos
node_dpos -->|"uses validator set"| node_validators
node_dpos -->|"finalizes selected blocks"| node_blockchain
node_rootchain_cli -.->|"operates protocol workflows"| node_dpos
node_archive -->|"exports chain data"| node_storage

click node_main "https://github.com/vcity-team/vcitychain/blob/develop/main.go"
click node_cli "https://github.com/vcity-team/vcitychain/blob/develop/command/root/root.go"
click node_server_command "https://github.com/vcity-team/vcitychain/blob/develop/command/server/server.go"
click node_node_server "https://github.com/vcity-team/vcitychain/blob/develop/server/server.go"
click node_node_config "https://github.com/vcity-team/vcitychain/blob/develop/server/config.go"
click node_system_service "https://github.com/vcity-team/vcitychain/blob/develop/server/system_service.go"
click node_jsonrpc "https://github.com/vcity-team/vcitychain/blob/develop/jsonrpc/dispatcher.go"
click node_blockchain "https://github.com/vcity-team/vcitychain/blob/develop/blockchain/blockchain.go"
click node_storage "https://github.com/vcity-team/vcitychain/blob/develop/blockchain/storage/storage.go"
click node_executor "https://github.com/vcity-team/vcitychain/blob/develop/state/executor.go"
click node_trie "https://github.com/vcity-team/vcitychain/blob/develop/state/immutable-trie/state.go"
click node_evm "https://github.com/vcity-team/vcitychain/blob/develop/state/runtime/evm/evm.go"
click node_txpool "https://github.com/vcity-team/vcitychain/blob/develop/txpool/txpool.go"
click node_network "https://github.com/vcity-team/vcitychain/blob/develop/network/server.go"
click node_syncer "https://github.com/vcity-team/vcitychain/blob/develop/syncer/syncer.go"
click node_consensus_contract "https://github.com/vcity-team/vcitychain/blob/develop/consensus/consensus.go"
click node_dpos "https://github.com/vcity-team/vcitychain/blob/develop/consensus/dpos/consensus_runtime.go"
click node_validators "https://github.com/vcity-team/vcitychain/blob/develop/validators/set.go"
click node_secrets "https://github.com/vcity-team/vcitychain/blob/develop/secrets/secrets.go"
click node_rootchain_cli "https://github.com/vcity-team/vcitychain/blob/develop/command/rootchain/rootchain.go"
click node_archive "https://github.com/vcity-team/vcitychain/blob/develop/archive/backup.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_cli,node_server_command toneBlue
class node_node_server,node_node_config,node_txpool,node_secrets toneAmber
class node_blockchain,node_storage,node_executor,node_trie,node_evm,node_archive toneMint
class node_network,node_syncer toneRose
class node_consensus_contract,node_dpos,node_validators,node_rootchain_cli toneIndigo
class node_system_service,node_jsonrpc toneTeal
```

## Components

### Entry & Operations

- [Node binary](https://github.com/vcity-team/vcitychain/blob/develop/main.go): Go entrypoint · `main.go`
- [Command hierarchy](https://github.com/vcity-team/vcitychain/blob/develop/command/root/root.go): CLI control plane · `command/root/root.go`
- [Server command](https://github.com/vcity-team/vcitychain/blob/develop/command/server/server.go): CLI launcher · `command/server/server.go`

### Node Runtime

- [Node server](https://github.com/vcity-team/vcitychain/blob/develop/server/server.go): runtime composition · Wires the node subsystems and lifecycle. · `server/server.go`
- [Node configuration](https://github.com/vcity-team/vcitychain/blob/develop/server/config.go): configuration model · `server/config.go`
- [Transaction pool](https://github.com/vcity-team/vcitychain/blob/develop/txpool/txpool.go): transaction admission · `txpool/txpool.go`
- [Secrets providers](https://github.com/vcity-team/vcitychain/blob/develop/secrets/secrets.go): key-provider abstraction · Supports local, cloud secret-manager, and Vault backends. · `secrets/secrets.go`

### Chain & Execution

- [Blockchain](https://github.com/vcity-team/vcitychain/blob/develop/blockchain/blockchain.go): canonical chain · Validates, persists, finalizes, and publishes blocks. · `blockchain/blockchain.go`
- [Chain storage](https://github.com/vcity-team/vcitychain/blob/develop/blockchain/storage/storage.go): storage abstraction · LevelDB and in-memory implementations sit behind this boundary. · `blockchain/storage/storage.go`
- [State executor](https://github.com/vcity-team/vcitychain/blob/develop/state/executor.go): state transition · Executes transactions and produces deterministic state roots. · `state/executor.go`
- [Immutable Merkle trie](https://github.com/vcity-team/vcitychain/blob/develop/state/immutable-trie/state.go): account state · `state/immutable-trie/state.go`
- [EVM runtime](https://github.com/vcity-team/vcitychain/blob/develop/state/runtime/evm/evm.go): bytecode execution · `state/runtime/evm/evm.go`
- [Archive backup](https://github.com/vcity-team/vcitychain/blob/develop/archive/backup.go): offline chain export · `archive/backup.go`

### Networking & Sync

- [Network server](https://github.com/vcity-team/vcitychain/blob/develop/network/server.go): libp2p networking · Provides peer discovery, gossip, and gRPC transport. · `network/server.go`
- [Syncer](https://github.com/vcity-team/vcitychain/blob/develop/syncer/syncer.go): chain synchronization · Selects peer tips and ingests/heals chain state. · `syncer/syncer.go`

### Consensus & Cross-Chain

- [Consensus contract](https://github.com/vcity-team/vcitychain/blob/develop/consensus/consensus.go): engine interface · `consensus/consensus.go`
- [DPoS runtime](https://github.com/vcity-team/vcitychain/blob/develop/consensus/dpos/consensus_runtime.go): primary consensus engine · Coordinates validators, epochs, production, rewards, and checkpoints. · `consensus/dpos/consensus_runtime.go`
- [Validator set](https://github.com/vcity-team/vcitychain/blob/develop/validators/set.go): validator cryptography · `validators/set.go`
- [Root-chain operations](https://github.com/vcity-team/vcitychain/blob/develop/command/rootchain/rootchain.go): operator workflows · Deploys and operates staking, bridge, and checkpoint contracts. · `command/rootchain/rootchain.go`

### Public Services

- [System service](https://github.com/vcity-team/vcitychain/blob/develop/server/system_service.go): gRPC management API · `server/system_service.go`
- [JSON-RPC dispatcher](https://github.com/vcity-team/vcitychain/blob/develop/jsonrpc/dispatcher.go): Ethereum RPC API · `jsonrpc/dispatcher.go`

## Connections

- Node binary → Command hierarchy: builds
- Command hierarchy → Server command: launch command
- Server command → Node server: starts
- Node configuration → Node server: configures
- Node server → Blockchain: hosts
- Node server → Transaction pool: hosts
- Node server → Network server: hosts
- Node server → Syncer: hosts
- Node server → Consensus contract: selects
- Node server → JSON-RPC dispatcher: serves
- Node server → System service: serves
- Node server → Secrets providers: loads keys
- Blockchain → Chain storage: persists blocks
- Blockchain → State executor: validates execution
- State executor → Immutable Merkle trie: reads and commits state
- State executor → EVM runtime: dispatches bytecode
- Transaction pool → State executor: prevalidates transactions
- JSON-RPC dispatcher → Blockchain: queries chain
- JSON-RPC dispatcher → Transaction pool: submits and queries txs
- Network server → Syncer: provides peers and transport
- Syncer → Blockchain: ingests canonical blocks
- Consensus contract → DPoS runtime: implemented by
- DPoS runtime → Validator set: uses validator set
- DPoS runtime → Blockchain: finalizes selected blocks
- Root-chain operations → DPoS runtime: operates protocol workflows
- Archive backup → Chain storage: exports chain data
