# ava-labs/hypersdk architecture

> Architecture diagram of the GitHub repository ava-labs/hypersdk, 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/ava-labs/hypersdk
- Repository: https://github.com/ava-labs/hypersdk

## Overview

##### Main Components

- Blockchain Core & Chain Logic:
– Represent the core chain components found in the “chain” directory (e.g., chain.go, builder.go, parser.go, transaction processing, genesis handling).
– Include the “internal/chain”, “internal/executor”, “internal/mempool”, and other internal modules that manage block validation, state transitions, and consensus-related data flows.

- Virtual Machine (VM) and Services:
– Highlight the “vm” directory, especially “vm/defaultvm/vm.go” and “vm/option.go”. This covers the VM instantiation and its customization.
– Indicate that “Services” can be registered as options to the VM (see explanations in the README about how Options enable APIs and event notifications).
– Show how these services plug into the blockchain for custom APIs, state syncing, and fee management.

- API Layers:
– Separate the API endpoints into components – “api” with its submodules (indexer, JSON-RPC, state, websocket).
– Note that these interfaces allow external clients or explorers to interact with the blockchain.

- Action and Transaction Handling:
– Mention the linkage between action parsing (in “chain/transaction_codec.go” and “chain/transaction_marshaller.go”) and state transition functions.

- Authentication & Cryptography:
– Emphasize the “auth” directory for signature and key management (using bls, ed25519, secp256r1 algorithms from “crypto”).

- State Management & Storage:
– Include the “state” directory for managing the persistent state (key-value store interactions).
– Include “storage” and components from “internal/pebble” which indicate that the framework supports pluggable storage backends.

- Networking & Communication:
– Capture networking components like “pubsub”, “statesync”, and the “api/ws” module to illustrate inter-node communication and client connectivity.
– Include reference to “snow” modules that indicate network and state syncing capabilities.

- Development Tools and Build Infrastructure:
– Show ancillary components like “cli” and “cmd” directories, used for command-line tools and client interactions.
– Optionally reference the extensive “tests” structure (unit, integration, e2e), “scripts”, and “examples” (like MorpheusVM) that help developers interact with and test the system.

##### Relationships and Interactions

- Data Flow & Execution Pipeline:
– Follow the flow from the action’s execution (implementing Execute) → processed by the blockchain engine (chain/executor) → state update (state/storage).
– Highlight the VM layer as mediating customization via options and services.

- Modular Architecture:
– Emphasize how components interact:
- The “chain” orchestrates block creation and parsing.
- The “internal” packages (executor, mempool, etc.) support processing and ordering.
- The “api” layer exposes the functionality externally.
- The “crypto” and “auth” modules validate and secure the transactions.

##### Architectural Patterns and Technologies

- Modular & Pluggable Design:
– Note that HyperSDK is built in a highly modular fashion. Components like the VM can be customized with different “Options” and services and storage can be swapped (as indicated by “Customizability” in the README).

- Service Registration and Dependency Injection:
– Emphasize the pattern where services are registered via “Options” at VM initialization. This facilitates easier integration of custom behavior (such as the Indexer, custom API, or event subscriptions).

- Technologies and Frameworks:
– Go is the primary language, with testing handled in a structured manner (see “*_test.go” files).
– The project utilizes Docker for containerized development (e.g., Dockerfile, .devcontainer files) and GitHub Actions for CI/CD pipelines.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interfaces
    subgraph "External Interfaces"
        CLITools["CLI & Client Tools"]:::external
        APIGateway["API Gateway"]:::api
        DevTools["Dev Tools"]:::tools
    end

    %% Transaction Processing Layer
    subgraph "Transaction Processing"
        ActionExec["Action Execution (ABI)"]:::core
        VMOptions["VM & Options"]:::core
        ChainProc["Chain / Block Processing"]:::core
        TxExecutor["Transaction Executor"]:::core
        Mempool["Mempool"]:::core
    end

    %% State and Security Layer
    subgraph "State & Security"
        StateManagement["State Management & Storage"]:::state
        AuthCrypto["Authentication & Crypto"]:::crypto
        Networking["Networking & Communication"]:::net
    end

    %% Flows between External Interfaces and Transaction Processing
    CLITools -->|"submits transaction"| APIGateway
    APIGateway -->|"for action execution"| ActionExec

    %% Flow inside Transaction Processing
    ActionExec -->|"executes in"| VMOptions
    VMOptions -->|"invokes"| ChainProc
    ChainProc -->|"processes transaction"| TxExecutor
    TxExecutor -->|"queues for inclusion"| Mempool

    %% Interaction with State & Security Layer
    ChainProc -->|"updates state"| StateManagement
    StateManagement -->|"provides state data"| APIGateway
    ChainProc -->|"verifies via"| AuthCrypto
    ChainProc -->|"communicates to peers"| Networking

    %% Styles
    classDef external fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef tools fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef core fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef state fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef crypto fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef net fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Click Events for External Interfaces
    click CLITools "https://github.com/ava-labs/hypersdk/tree/main/cli/"
    click APIGateway "https://github.com/ava-labs/hypersdk/tree/main/api/indexer"
    click APIGateway "https://github.com/ava-labs/hypersdk/tree/main/api/jsonrpc"
    click APIGateway "https://github.com/ava-labs/hypersdk/tree/main/api/state"
    click APIGateway "https://github.com/ava-labs/hypersdk/tree/main/api/ws"
    click DevTools "https://github.com/ava-labs/hypersdk/tree/main/cmd/hypersdk-cli"
    click DevTools "https://github.com/ava-labs/hypersdk/tree/main/cmd/abigen"
    click DevTools "https://github.com/ava-labs/hypersdk/tree/main/examples/morpheusvm"

    %% Click Events for Transaction Processing
    click ActionExec "https://github.com/ava-labs/hypersdk/blob/main/abi/abi.go"
    click VMOptions "https://github.com/ava-labs/hypersdk/blob/main/vm/defaultvm/vm.go"
    click VMOptions "https://github.com/ava-labs/hypersdk/blob/main/vm/option.go"
    click ChainProc "https://github.com/ava-labs/hypersdk/blob/main/chain/chain.go"
    click TxExecutor "https://github.com/ava-labs/hypersdk/tree/main/internal/executor"
    click Mempool "https://github.com/ava-labs/hypersdk/tree/main/internal/mempool"

    %% Click Events for State & Security
    click StateManagement "https://github.com/ava-labs/hypersdk/blob/main/state/state.go"
    click AuthCrypto "https://github.com/ava-labs/hypersdk/blob/main/auth/bls.go"
    click Networking "https://github.com/ava-labs/hypersdk/tree/main/pubsub/"
```
