# dapplink-labs/wallet-chain-account architecture

> Architecture diagram of the GitHub repository dapplink-labs/wallet-chain-account, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dapplink-labs/wallet-chain-account
- Repository: https://github.com/dapplink-labs/wallet-chain-account

## Overview

##### Main Components
- Client / Upper-Layer Service: This represents any external service or client consuming the gRPC interface (for example, via grpcui or a custom client).
- RPC Server: The entry point of the application (main.go) that sets up and exposes the gRPC service. Note the RPC service definitions and generated protobuf code under the “rpc” folder (account and common subdirectories).
- Chain Gateway / Dispatcher: The “chaindispatcher” package (dispatcher.go) acts as an adapter to forward requests to the appropriate chain module. This layer makes the routing decision across different blockchain implementations.
- Chain Modules: The “chain” directory is segmented into subdirectories for each blockchain (aptos, ethereum, cosmos, sui, solana, etc.). Each module encapsulates chain-specific logic, transaction handling, and integration with underlying blockchain networks.
- Common Utilities & Helpers: Refer to the “common” folder (global constants, helpers, retry strategies, and utility packages) which support the core business logic, error handling, and common operations across modules.
- Configuration & Deployment: The “config” package (config.go) and external files (config.yml, Dockerfile, charts directory) handle runtime configuration and provide deployment artifacts such as Docker and Helm charts.

##### Relationships & Interactions
- The Client initiates requests (RPC calls) to the RPC Server.
- The RPC Server processes incoming gRPC requests and then leverages the Chain Gateway/Dispatcher to decide which specific blockchain chain module should handle the request.
- The chain modules implement the business logic for interacting with each respective blockchain. They use utility functions from the “common” packages as needed.
- Responses (e.g., account data, transaction details) are sent back through this chain: from the chain module → back through the dispatcher → to the RPC Server → then returned to the Client.
- Deployment artifacts (Dockerfile, Helm charts) ensure the system is containerized and can be orchestrated (for cloud/Kubernetes setups).

##### Incorporate Architectural Patterns and Technologies
- Modularity/Separation of Concerns: Clearly separated directories for each blockchain imply a modular design where changes for one blockchain do not affect the others.
- Adapter/Dispatcher Pattern: The “chaindispatcher” layer is crucial as it decouples the gRPC interface from the specific implementation details of each blockchain.
- RPC and gRPC Communication: The service exposes a clear gRPC API defined and generated in the “rpc” directory.
- Testing and Continuous Integration: The presence of “.github/workflows” and numerous *_test.go files indicates thorough test coverage and CI/CD practice.
- Containerization and Deployment: Dockerfile and Helm charts (in the “charts” directory) indicate that the service is designed to run in containerized environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client / Upper-Layer Service
    Client["Client (Upper-Layer Service)"]:::client

    %% RPC Layer
    subgraph "RPC Layer"
        RPC["RPC Server / gRPC Interface"]:::server
    end

    %% Chain Gateway/Dispatcher
    Dispatcher["Chain Gateway/Dispatcher"]:::dispatcher

    %% Chain Modules for different blockchains
    subgraph "Chain Modules"
        Aptos["Aptos Module"]:::chain
        Ethereum["Ethereum Module"]:::chain
        Cosmos["Cosmos Module"]:::chain
        Sui["Sui Module"]:::chain
        Solana["Solana Module"]:::chain
    end

    %% Common Utilities & Helpers
    Common["Common Utilities & Helpers"]:::common

    %% Configuration & Deployment
    Deploy["Configuration & Deployment"]:::config

    %% Flow connections
    Client -->|"RPC_Request"| RPC
    RPC -->|"DispatchesTo"| Dispatcher
    Dispatcher -->|"RoutesTo_Aptos"| Aptos
    Dispatcher -->|"RoutesTo_Ethereum"| Ethereum
    Dispatcher -->|"RoutesTo_Cosmos"| Cosmos
    Dispatcher -->|"RoutesTo_Sui"| Sui
    Dispatcher -->|"RoutesTo_Solana"| Solana
    Aptos -->|"Uses"| Common
    Ethereum -->|"Uses"| Common
    Cosmos -->|"Uses"| Common
    Sui -->|"Uses"| Common
    Solana -->|"Uses"| Common
    Deploy ---|"LoadsConfig"| RPC

    %% Click Events
    click RPC "https://github.com/dapplink-labs/wallet-chain-account/blob/main/main.go"
    click RPC "https://github.com/dapplink-labs/wallet-chain-account/tree/main/rpc/"
    click Dispatcher "https://github.com/dapplink-labs/wallet-chain-account/blob/main/chaindispatcher/dispatcher.go"
    click Aptos "https://github.com/dapplink-labs/wallet-chain-account/tree/main/chain/aptos"
    click Ethereum "https://github.com/dapplink-labs/wallet-chain-account/tree/main/chain/ethereum"
    click Cosmos "https://github.com/dapplink-labs/wallet-chain-account/tree/main/chain/cosmos"
    click Sui "https://github.com/dapplink-labs/wallet-chain-account/tree/main/chain/sui"
    click Solana "https://github.com/dapplink-labs/wallet-chain-account/tree/main/chain/solana"
    click Common "https://github.com/dapplink-labs/wallet-chain-account/tree/main/common/"
    click Deploy "https://github.com/dapplink-labs/wallet-chain-account/blob/main/config/config.go"
    click Deploy "https://github.com/dapplink-labs/wallet-chain-account/blob/main/config.yml"
    click Deploy "https://github.com/dapplink-labs/wallet-chain-account/tree/main/Dockerfile"
    click Deploy "https://github.com/dapplink-labs/wallet-chain-account/tree/main/charts/"

    %% Styles
    classDef client fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef server fill:#87CEFA,stroke:#1E90FF,stroke-width:2px;
    classDef dispatcher fill:#98FB98,stroke:#32CD32,stroke-width:2px;
    classDef chain fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef common fill:#AFEEEE,stroke:#40E0D0,stroke-width:2px;
    classDef config fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
```
