# gasp-xyz/gasp-dev-kit architecture

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

- Interactive diagram: https://gitdiagram.com/gasp-xyz/gasp-dev-kit
- Repository: https://github.com/gasp-xyz/gasp-dev-kit

## Overview

##### Project Type and Purpose
- Recognize that this is a library/SDK (not a full-stack web app)—its focus is on communication with a blockchain node.
- The README describes it as a “comprehensive toolset” with method groups covering query, fee, RPC, tokens, xyk, and utility operations.
- Its primary intent is to abstract complex blockchain interactions (e.g., liquidity pool management, price calculations, asset transfers) into an easier-to-use API.

##### High-Level Architectural Components
- SDK Core / Entry Point: Represent the public API exposed to developers via the Mangata instance (e.g., using Mangata.instance() to obtain a connection).
- Query Module: Methods for fetching data from the blockchain (e.g., getAssetInfo, getBlockNumber, getPools).
- RPC Module: Methods that perform calculations and node-related queries (e.g., getChain, getNodeVersion, calculateBuyPrice).
- XYK (Liquidity) Module: Methods to handle liquidity pool actions (e.g., createPool, activateLiquidity).
- Fee Module: Methods to obtain fee structures for various operations.
- Tokens Module: Methods to manage token transfers and balances.
- Utility Module: Utility functions that support parameter validation, error handling, logging, and transaction signing.
- Submitable Extrinsic: For building and batching transactions.
- Type and Interface Definitions: A separate package devoted to type definitions and interfaces (“packages/types” and “packages/type-definitions”) which supports type safety and structure for API responses and function parameters.

##### Interaction and Data Flow
- Application/Client Code calls the SDK’s entry point.
- The entry point then forwards calls to the appropriate module (query, rpc, tokens, etc.).
- These modules often use underlying utilities (found in the "utils" directory) for tasks like error handling and signing transactions.
- For blockchain operations, the SDK forms connections through given endpoints (e.g., wss://kusama-archive.mangata.online), interacting with external Mangata nodes.
- How client code initiates calls to the SDK.
- The communication from each module to external services (blockchain nodes).
- Internal dependencies (e.g., utility functions supporting multiple modules).

##### Architectural Patterns and Design Principles
- Modular Design: Organized separation by method groups (e.g., fee, query, rpc, xyk) suggests a modular architecture.
- Abstraction: The SDK abstracts low-level blockchain interactions into higher-level API calls.
- Configuration and Testing: Notice the existence of multiple configuration files (ESLint, Prettier, tsconfig) and tests – indicating adherence to best practices.
- Object-Oriented and Functional Mix: Although written in TypeScript, functionality is grouped into objects (“Mangata instance”, method groups) and helper utility functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Client Application"):::client
    B("Public SDK API Entry Point"):::api
    C("Mangata Instance (SDK Core)"):::core

    subgraph "SDK Method Modules"
        D("Query Module"):::module
        E("RPC Module"):::module
        F("XYK (Liquidity) Module"):::module
        G("Fee Module"):::module
        H("Tokens Module"):::module
        I("Utility Module"):::module
        J("Submitable Extrinsic"):::module
    end

    K("Utility Functions"):::utils
    L("Mangata Blockchain Node"):::external

    subgraph "Type Definitions"
        M("Type Definitions Package"):::types
        N("Supplementary Types"):::types
    end

    O("Test Suite"):::test

    A -->|"calls"| B
    B -->|"forwardsTo"| C
    C -->|"routesTo"| D
    C -->|"routesTo"| E
    C -->|"routesTo"| F
    C -->|"routesTo"| G
    C -->|"routesTo"| H
    C -->|"routesTo"| I
    C -->|"routesTo"| J

    D -->|"uses"| K
    E -->|"uses"| K
    F -->|"uses"| K
    G -->|"uses"| K
    H -->|"uses"| K
    I -->|"uses"| K
    J -->|"uses"| K

    D -->|"calls"| L
    E -->|"calls"| L
    F -->|"calls"| L
    G -->|"calls"| L
    H -->|"calls"| L
    I -->|"calls"| L
    J -->|"calls"| L

    C -->|"defines"| M
    C -->|"defines"| N

    %% Click Events
    click C "https://github.com/gasp-xyz/gasp-dev-kit/blob/main/packages/sdk/src/mangataInstance.ts"
    click B "https://github.com/gasp-xyz/gasp-dev-kit/blob/main/packages/sdk/src/index.ts"
    click D "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/methods/query"
    click E "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/methods/rpc"
    click F "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/methods/xyk"
    click G "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/methods/fee"
    click H "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/methods/tokens"
    click I "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/methods/utility"
    click M "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/type-definitions"
    click N "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/types"
    click K "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/utils"
    click O "https://github.com/gasp-xyz/gasp-dev-kit/tree/main/packages/sdk/src/tests"

    %% Styles
    classDef client fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef api fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef core fill:#66ff66,stroke:#333,stroke-width:2px;
    classDef module fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef utils fill:#dddddd,stroke:#333,stroke-width:2px;
    classDef external fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef types fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef test fill:#c0c0c0,stroke:#333,stroke-width:2px;
```
