How router-protocol/tangled works
And Outline the Main Components
• DApp / Consumer Layer: Represents client applications (examples like “example-next” and “example”) that integrate the SDK.
• TangledProvider (Core React Component): The entry point for initializing the SDK configuration and providing context (wrapping the DApp).
• React SDK Core Package (@tangled3/react): Contains the bulk of functionality including hooks, providers, actions, connectors, constants, and types – all of which manage interactions with multiple blockchains.
• Package Modules:
– packages/react: Contains actions segmented by blockchain (EVM, Bitcoin, Cosmos, etc.), hooks (like useWallet, useConnect, useChain, etc.), connectors (handling wallet and chain interactions), providers (which establish contexts), and state management (stores).
– packages/solana-react: Provides dedicated wrappers, hooks, and providers specifically for Solana.
– packages/ui: A library of UI components (built with Tailwind and inspired by @shadcn/ui) meant to be used within the React applications.
• Utility & Configuration Layers: Includes utilities, constants, and configurations (such as ESLint, Prettier, build scripts, and CI/CD workflows) that support development and integration.
Relationships and Data Flow
• The DApp imports and uses TangledProvider from the SDK. TangledProvider then makes available various contexts (wallet, chain, and connection management) to its child components.
• Within the SDK, the hooks interact with underlying providers and stores to access or update blockchain-specific data.
• Connectors and actions serve as the bridge that translates UI or hook calls into chain-specific operations (e.g., connecting a wallet, fetching tokens, sending transactions).
• Package modules like “packages/solana-react” work similarly but are specialized for the Solana ecosystem.
• Utility functions and constants support these operations by ensuring standardized configurations and processing logic across chains.
Architectural Patterns and Design Principles
• Modularization: The project is divided into focused packages (core, UI, and Solana-specific), allowing each part of the system to evolve independently.
• Separation of Concerns: Providers manage context, hooks supply individual functionalities (wallet connection, transaction handling, etc.), while connectors and actions encapsulate the logic of specific blockchain interactions.
• Reusability & Extensibility: With clear separation into hooks, components, and connectors, extending support to additional chains or functionalities is simplified.
• Context and State Management: Built using React’s context and state patterns, enabling streamlined data flow between callbacks, hooks, and UI components.