# injectivelabs/injective-ts architecture

> Architecture diagram of the GitHub repository injectivelabs/injective-ts, 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/injectivelabs/injective-ts
- Repository: https://github.com/injectivelabs/injective-ts

## Overview

##### Main Components
- Monorepo Core: At the top level, note that this is a monorepo maintained with tools such as Lerna. The core teams organize the code into organized, self-contained packages.
- Packages Directory: This encapsulates several modules:
- sdk-ts: The heart of the SDK, which ties together chain clients, transaction builders, and query logic.
- networks: Provides information about network configurations, endpoints, and chain details.
- exceptions: Contains custom error handling and exception classes to standardize error reporting.
- ts-types: Defines shared TypeScript types, interfaces, and enums across the other packages.
- utils: Contains common utilities, helper functions, number handling (for BigNumber classes), and formatting.
- wallets: This is a collection of wallet implementations (wallet-base, wallet-core, wallet-cosmos, wallet-evm, wallet-ledger, wallet-trezor, wallet-wallet-connect, etc.) responsible for signing transactions and managing key storage.
- Proto Definitions: The “proto” directory holds gRPC and blockchain protocol buffer definitions and templates for generating code. This is an essential element for defining how the SDK communicates with backend services.
- Documentation and Configuration: Directories like docs and .gitbook show that the project documents its API and usage, while configuration files (tsconfig, lerna.json, etc.) indicate build and documentation pipelines.

##### Relationships & Dependencies
- Wallet Module Interactions: The wallets packages provide different strategies and connectors (for Cosmos, EVM, Ledger, Trezor, WalletConnect, etc.). They can be shown as specialized components that interact with both the blockchain (via sdk-ts clients) and with user interfaces.
- Cross-Package Utilities and Shared Contracts: The ts-types and utils packages are consumed across sdk-ts and wallets. Indicate these as supporting layers that supply types, interfaces, and helper functions.

##### Important Architectural Patterns & Design Principles
- Modular and Microkernel Approach: Each package is built as an independent npm module that can be used standalone or in concert. This promotes separation of concerns (for example, handling errors separately from networking).
- Abstraction and Interoperability: The SDK abstracts core blockchain operations (chain clients, wallet strategies, transaction submission, etc.), and employs uniform types and utility classes for consistent behavior across different environments (Node.js vs. browser).

##### Relevant Technologies & Frameworks
- TypeScript: The primary language, with consistent tsconfig settings across modules.
- Lerna (or similar tool): For managing multiple packages in a mono-repository.
- gRPC & Protobuf: Used in the “proto” directory and for client implementations in the sdk-ts package.
- Node.js and Browser Compatible Design: The architecture is intended for cross-environment use.
- Testing Frameworks: Jest is used (as seen with jest.config.js in packages) to ensure reliability.

##### Instructing the Principal Software Engineer: What
- Clear labels for each major component:
- Monorepo Core
- Packages (with sub-components for sdk-ts, exceptions, networks, ts-types, utils, wallets)
- Proto Definitions (gRPC/Protobuf based)
- Documentation & Build/CI pipelines (.github/workflows, docs, etc.)
- Dependencies:
- That wallet packages depend on sdk-ts for chain interactions.
- Link proto directory output to the clients in sdk-ts and indexer.
- Use another style for wallet packages to indicate they are ‘integrators’ with external keys/signing.
- Use annotations to briefly note design patterns:
- “Modular Abstractions”, “API Client Builders”, “gRPC/REST Stubs”, or “Wallet Strategy Pattern” in their respective areas.

##### Final Touches
- Each package is a node.
- Groupings represent functional areas (chain clients, wallet modules, common types).
- Balance detail with readability:
- As many components as possible but keep the labels concise.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    monorepoCore("Monorepo Core"):::core
    docsConfig("Documentation & Configuration"):::doc
    proto("Proto Definitions"):::proto

    subgraph "Packages"
        sdk_ts("sdk-ts"):::corePackages
        networks("networks"):::supportingPackages
        exceptions("exceptions"):::supportingPackages
        ts_types("ts-types"):::supportingPackages
        utils("utils"):::supportingPackages
        wallets("wallets"):::walletPackages
    end

    monorepoCore -->|"manages"| sdk_ts
    monorepoCore -->|"manages"| docsConfig
    monorepoCore -->|"includes"| proto

    sdk_ts -->|"uses"| networks
    sdk_ts -->|"uses"| exceptions
    sdk_ts -->|"uses"| ts_types
    sdk_ts -->|"uses"| utils

    wallets -->|"depends_on"| sdk_ts

    proto -->|"generates"| sdk_ts

    click monorepoCore "https://github.com/injectivelabs/injective-ts/blob/dev/lerna.json"
    click sdk_ts "https://github.com/injectivelabs/injective-ts/tree/dev/packages/sdk-ts"
    click networks "https://github.com/injectivelabs/injective-ts/tree/dev/packages/networks"
    click exceptions "https://github.com/injectivelabs/injective-ts/tree/dev/packages/exceptions"
    click ts_types "https://github.com/injectivelabs/injective-ts/tree/dev/packages/ts-types"
    click utils "https://github.com/injectivelabs/injective-ts/tree/dev/packages/utils"
    click wallets "https://github.com/injectivelabs/injective-ts/tree/dev/packages/wallets"
    click proto "https://github.com/injectivelabs/injective-ts/tree/dev/proto"

    classDef core fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef corePackages fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef supportingPackages fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef walletPackages fill:#FFC1C1,stroke:#333,stroke-width:2px;
    classDef proto fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef doc fill:#CCE5FF,stroke:#333,stroke-width:2px;
```
