# router-protocol/tangled architecture

> Architecture diagram of the GitHub repository router-protocol/tangled, 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/router-protocol/tangled
- Repository: https://github.com/router-protocol/tangled

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Layers
    A["DApp / Client Application"]:::external
    B["TangledProvider (SDK Entry Point)"]:::provider

    %% React SDK Core Subgraph
    subgraph "React SDK Core (@tangled3/react)"
        CP["Providers"]:::provider
        CH["Hooks (General)"]:::hook
        CC["Connectors (General)"]:::connector
        CA["Actions & APIs"]:::action
        CS["State Stores & Config"]:::store
    end

    %% Specialized modules
    S["Solana Module (Specialized)"]:::provider
    U["UI Components Library"]:::ui

    %% Data Flow Arrows
    A -->|"initializes"| B
    B -->|"provides_context"| CP
    B -->|"provides_context"| CH
    CH -->|"triggers"| CC
    CC -->|"invokes"| CA
    CA -->|"updates"| CS
    CS -->|"renders_data"| U
    %% Integration with specialized Solana Module
    CH -->|"solana_hooks"| S
    S -->|"solana_connectors"| CC

    %% Click Events
    click A "https://github.com/router-protocol/tangled/tree/main/example-next/"
    click A "https://github.com/router-protocol/tangled/tree/main/example/"
    click B "https://github.com/router-protocol/tangled/blob/main/packages/react/src/providers/TangledContext.tsx"
    click CP "https://github.com/router-protocol/tangled/tree/main/packages/react/src/providers/"
    click CH "https://github.com/router-protocol/tangled/tree/main/packages/react/src/hooks/"
    click CC "https://github.com/router-protocol/tangled/tree/main/packages/react/src/connectors/"
    click CA "https://github.com/router-protocol/tangled/tree/main/packages/react/src/actions/"
    click CS "https://github.com/router-protocol/tangled/tree/main/packages/react/src/store/"
    click S "https://github.com/router-protocol/tangled/tree/main/packages/solana-react/"
    click S "https://github.com/router-protocol/tangled/tree/main/packages/solana-react/src/hooks/"
    click S "https://github.com/router-protocol/tangled/tree/main/packages/solana-react/src/connectors/"
    click U "https://github.com/router-protocol/tangled/tree/main/packages/ui/"

    %% Styles
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef provider fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef hook fill:#A9DFBF,stroke:#229954,stroke-width:2px;
    classDef connector fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef action fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef store fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef ui fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
