How injectivelabs/injective-ts works
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!