# cybercongress/cyber-ts architecture

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

- Interactive diagram: https://gitdiagram.com/cybercongress/cyber-ts
- Repository: https://github.com/cybercongress/cyber-ts

## Overview

##### Main Components
- SDK Core Module: This forms the heart of the library and includes public exports such as the “cyber” object, the “ClientFactory” for creating RPC clients, and message composition modules for different blockchain operations.
- Message Composition Modules: These are organized by domain (e.g., cosmos, cosmwasm, ibc, and cyber exchange). They provide helper methods (withTypeUrl or fromPartial) for creating structured messages.
- RPC Client and Signing Modules: Components such as “getSigningCyberClient” and the functions for creating offline or proto signers to handle wallet connections, signing transactions, and broadcasting them.
- Proto and Amino Converters: Modules that handle the conversion between protocol buffer definitions and Amino message types. These are essential for correctly formatting and processing blockchain messages.
- Code Generation and Build Tools: Scripts (such as “scripts/codegen.ts”) and configuration files that generate and bundle the SDK’s artifacts, ensuring consistent protocol definitions across the packages.
- Contracts (Gift & Passport): Although not the main focus (as they are examples or part of contract testing/definitions), these provide definitions for the blockchain smart contracts used within the ecosystem.

##### Relationships and Interactions
- The ClientFactory (SDK Core) creates RPC clients that act as an intermediary between the developer’s application and the blockchain network.
- Message Composer modules (split by module type) are used by the developer to create transaction payloads.
- The signing modules (using either Amino or Proto signers) are responsible for signing these transactions before broadcasting them via the RPC client.
- Proto definitions and conversion layers (found under packages/cyber-ts/proto and related src directories) are compiled during build/codegen and then consumed by the client and message composition modules.
- External integrations (wallets like Keplr or cosmos-kit) connect to the signing modules; these are depicted as external components interacting with the SDK rather than part of the core.

##### Architectural Patterns and Design Principles
- Modular Design/Separation of Concerns: Each major functional area (e.g., RPC interactions, message composition, signing) is encapsulated in its own module or package.
- Monorepo Structure: Managed via Lerna, enabling the organization of multiple packages (for instance, “cyber-ts”) and shared code (like protos and helper utilities).
- Extensibility: The design of message composers and client factories allows the SDK to be extended to support new blockchain modules or configuration options easily.
- Abstraction of Complexity: Developers use high-level functions to create and sign messages without a deep understanding of lower-level protobuf or Amino details.

- Provide a high-level overview and also detail certain “lower-level” connections (like how the proto definitions from packages/cyber-ts/proto feed into the Registry and AminoTypes construction in the advanced usage).
- Components are clearly separated while showing the data flow and dependency chain from initialization (client creation) to message construction and transaction broadcasting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Interaction
    Developer["Developer's Application"]:::external

    %% SDK Core Module
    subgraph "SDK Core"
        SDK["SDK Core (ClientFactory, Public API)"]:::sdk
    end

    %% Message Composition Modules
    subgraph "Message Composition Modules"
        CosmosMC["Cosmos Message Composers"]:::msgComp
        CosmWasmMC["CosmWasm Message Composers"]:::msgComp
        CyberMC["Cyber Message Composers (includes IBC & Cyber)"]:::msgComp
    end

    %% RPC Client and Signing Modules
    subgraph "RPC Client & Signing Modules"
        RPCClient["RPC Client & Query Modules"]:::rpc
        Signing["Signing Modules"]:::rpc
    end

    %% Proto and Amino Conversion Layers
    subgraph "Conversion Layers"
        Proto["Proto Definitions & Conversions"]:::conv
        Amino["Amino Conversion Utilities"]:::conv
    end

    %% Development Tools
    subgraph "Development Tools"
        Codegen["Code Generation Script"]:::dev
        Aminos["Amino Conversion Script"]:::dev
    end

    %% Smart Contracts
    subgraph "Smart Contracts"
        Gift["Gift Contracts"]:::contract
        Passport["Passport Contracts"]:::contract
    end

    %% External Wallet Integration
    Wallet["Wallet/Signer Integration (Keplr, cosmos-kit)"]:::external

    %% Connections
    Developer -->|"callsAPI"| SDK

    SDK -->|"createsClient"| RPCClient
    SDK -->|"exposesMsgComposers"| CosmosMC
    SDK -->|"exposesMsgComposers"| CosmWasmMC
    SDK -->|"exposesMsgComposers"| CyberMC

    CosmosMC -->|"composesTx"| RPCClient
    CosmWasmMC -->|"composesTx"| RPCClient
    CyberMC -->|"composesTx"| RPCClient

    RPCClient -->|"requiresSign"| Signing
    Signing -->|"usesProto"| Proto
    Signing -->|"usesAmino"| Amino

    Wallet -->|"connectsTo"| Signing

    Codegen -->|"generatesProto"| Proto
    Codegen -->|"assemblesSDK"| SDK
    Aminos -->|"bundlesAmino"| Amino

    %% Click Events for Component Mapping
    click SDK "https://github.com/cybercongress/cyber-ts/blob/main/packages/cyber-ts/src/index.ts"
    click CosmosMC "https://github.com/cybercongress/cyber-ts/tree/main/packages/cyber-ts/src/cosmos"
    click CosmWasmMC "https://github.com/cybercongress/cyber-ts/tree/main/packages/cyber-ts/src/cosmwasm"
    click CyberMC "https://github.com/cybercongress/cyber-ts/tree/main/packages/cyber-ts/src/cyber"
    click RPCClient "https://github.com/cybercongress/cyber-ts/blob/main/packages/cyber-ts/src/cosmos/client.ts"
    click Signing "https://github.com/cybercongress/cyber-ts/blob/main/packages/cyber-ts/src/cosmos/tx/signing/v1beta1/signing.ts"
    click Proto "https://github.com/cybercongress/cyber-ts/tree/main/packages/cyber-ts/proto"
    click Amino "https://github.com/cybercongress/cyber-ts/blob/main/packages/cyber-ts/src/amino/amino.ts"
    click Codegen "https://github.com/cybercongress/cyber-ts/blob/main/packages/cyber-ts/scripts/codegen.ts"
    click Aminos "https://github.com/cybercongress/cyber-ts/blob/main/packages/cyber-ts/scripts/aminos.ts"
    click Gift "https://github.com/cybercongress/cyber-ts/tree/main/contracts/gift"
    click Passport "https://github.com/cybercongress/cyber-ts/tree/main/contracts/passport"

    %% Styles
    classDef sdk fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef msgComp fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef rpc fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef conv fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef dev fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef contract fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef external fill:#fefefe,stroke:#6c757d,stroke-width:2px,stroke-dasharray: 5 5;
```
