# gaianet-ai/gaianet-node architecture

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

- Interactive diagram: https://gitdiagram.com/gaianet-ai/gaianet-node
- Repository: https://github.com/gaianet-ai/gaianet-node

## Overview

##### Main Components
- CLI & Node Management: The “gaianet” command-line interface, along with install.sh, uninstall.sh, and update commands that configure the node (using config.json and nodeid.json).
- Configuration & Initialization: Files like config.json determine model parameters, vector DB settings, etc. The initialization procedure (gaianet init) downloads large model files and vector snapshots.
- WASM Runtime & API Server: The core service is delivered via the WasmEdge runtime. The LlamaEdge API Server (rag-api-server.wasm) is started under WasmEdge and is responsible for handling AI chat requests, loading specific WASM modules, and preloading models (e.g., Llama-2 and MiniLM).
- Vector Database (Qdrant): The node launches a Qdrant instance to serve collection management for the retrieval augmented generation (RAG) process.
- Docker & Deployment Support: Docker-related files and workflows indicate containerization support for deployment and consistent builds. Additionally, there is a Docker directory that contains Dockerfiles (including variants for CUDA) and a run script.
- Utilities and Registry Module: Under the utils/registry directory, there is a Rust-based component (with its Cargo.toml and source files) along with a pre-built registry.wasm. This could be used for registering or interfacing with other WASM modules, providing an extensible “registry” of functionality.

##### Out Relationships and Interactions
- The CLI tool (gaianet) drives all operations:
- “install” triggers installation of dependencies (WasmEdge, Qdrant, etc.) and downloads configuration, identifiers, and model files.
- “init” uses config.json to initialize the node and orchestrate the download of models and vector snapshots.
- “start” creates a running instance which:
▪ Starts the Qdrant vector database
▪ Launches the LlamaEdge API Server within the WasmEdge runtime, preloading its WASM modules
▪ Optionally runs additional components (such as the registry service from utils/registry if used in that context)
- “stop” cleanly shuts down the Qdrant, WasmEdge, and any FRPC (frpc.toml) processes.
- Data Flow:
- User or external clients interact with the node via a public URL (or localhost when started “--local-only”), which routes requests to the LlamaEdge API Server.
- The API server communicates with the Qdrant vector database to retrieve context data (model inference / retrieval augmented generation).
- Updates and configurations propagate from the CLI commands to the underlying WASM modules and database.

##### Architectural Patterns and Technologies
- Modular Design: Separation between the CLI management layer, runtime (WasmEdge executing WASM modules) layer, and a dedicated vector DB (Qdrant) for specialized data (knowledge base retrieval).
- Containerization: Docker components and CI/CD workflows in .github indicate a container-based deployment and ongoing integration.
- Extensibility: The use of a registry module (utils/registry) and WASM-based API servers facilitates extension and integration of additional modules.
- Deployment Flexibility: Support for multiple deployment environments (native via install scripts, Docker-based, and potentially using CUDA variants) is evident.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User/External Client"]:::external
    A -->|"sends command"| B["CLI & Node Management"]:::control

    subgraph "CLI Files"
        B1["gaianet"]:::file
        B2["install.sh"]:::file
        B3["uninstall.sh"]:::file
        B4["nodeid.json"]:::file
    end
    B --> B1
    B --> B2
    B --> B3
    B --> B4

    B -->|"init/config/install"| C["Configuration & Initialization"]:::config

    subgraph "Configuration Files"
        C1["config.json"]:::file
        C2["vector.toml"]:::file
    end
    C --> C1
    C --> C2

    B -->|"start/stop"| D["WasmEdge Runtime (LlamaEdge API Server)"]:::runtime
    D -->|"preloads"| D1["WASM Modules (Llama-2, MiniLM)"]:::runtime
    D -->|"queries"| E["Qdrant Vector Database"]:::database

    F["Registry Module (WASM)"]:::runtime
    F -- "registers with" --> D

    subgraph "Registry Files"
        R1["Cargo.toml"]:::file
        R2["README.md"]:::file
        R3["registry.wasm"]:::file
        R4["src"]:::folder
    end
    F --> R1
    F --> R2
    F --> R3
    F --> R4

    subgraph "Docker & Deployment Support"
        G1["Dockerfile"]:::dockerfile
        G2["Dockerfile.cuda11"]:::dockerfile
        G3["Dockerfile.cuda12"]:::dockerfile
        G4["run.sh"]:::dockerfile
    end
    B -->|"deployment scripts"| G1
    B --> G2
    B --> G3
    B --> G4

    %% Click Events for CLI & Node Management Files
    click B1 "https://github.com/gaianet-ai/gaianet-node/tree/main/gaianet"
    click B2 "https://github.com/gaianet-ai/gaianet-node/blob/main/install.sh"
    click B3 "https://github.com/gaianet-ai/gaianet-node/blob/main/uninstall.sh"
    click B4 "https://github.com/gaianet-ai/gaianet-node/blob/main/nodeid.json"

    %% Click Events for Configuration Files
    click C1 "https://github.com/gaianet-ai/gaianet-node/blob/main/config.json"
    click C2 "https://github.com/gaianet-ai/gaianet-node/blob/main/vector.toml"

    %% Click Events for Docker & Deployment Support Files
    click G1 "https://github.com/gaianet-ai/gaianet-node/tree/main/docker/Dockerfile"
    click G2 "https://github.com/gaianet-ai/gaianet-node/blob/main/docker/Dockerfile.cuda11"
    click G3 "https://github.com/gaianet-ai/gaianet-node/blob/main/docker/Dockerfile.cuda12"
    click G4 "https://github.com/gaianet-ai/gaianet-node/blob/main/docker/run.sh"

    %% Click Events for Registry Files and Module
    click R1 "https://github.com/gaianet-ai/gaianet-node/blob/main/utils/registry/Cargo.toml"
    click R2 "https://github.com/gaianet-ai/gaianet-node/blob/main/utils/registry/README.md"
    click R3 "https://github.com/gaianet-ai/gaianet-node/blob/main/utils/registry/registry.wasm"
    click R4 "https://github.com/gaianet-ai/gaianet-node/tree/main/utils/registry/src"
    click F "https://github.com/gaianet-ai/gaianet-node/tree/main/utils/registry"

    %% Class Definitions
    classDef external fill:#ffefc6,stroke:#b58900,stroke-width:2px;
    classDef control fill:#cce5ff,stroke:#007acc,stroke-width:2px;
    classDef config fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef runtime fill:#fce5cd,stroke:#d97706,stroke-width:2px;
    classDef database fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef dockerfile fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef file fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef folder fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
```
