# capgoblin/argonaut architecture

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

## Overview

##### A smart contract module written in Cairo for Starknet (in the “argonaut” directory).
2. A Telegram bot backend (in the “bot” directory) implemented in Node.js/TypeScript that handles Telegram commands, interacts with the on-chain contract via Starknet.js, and integrates ArgentTMA SDK.
3. A frontend mini-app (in the “tma” directory) built with Next.js and React that provides a user interface for initiating multisig transactions and viewing their status.

##### Main components
- Smart Contract Layer: Represent the multisig wallet contract developed in Cairo (files like “src/lib.cairo”, “multisig.cairo”, etc.). Indicate that this contract handles proposals, confirmations, revocations, and executions on Starknet.
- Backend/Telegram Bot Layer: Highlight the “bot” directory’s components as the Telegram command processor which interprets commands, calls API methods (e.g., /listTxns, /listSigners), and interacts with the smart contract via Starknet.js.
- Frontend Mini-App Layer: Represent the “tma” directory components as the user interface layer (Next.js, React with Tailwind CSS) that users interact with to submit transactions and observe wallet activity.

##### Relationships and interactions
- Integration with external APIs where applicable:
- Telegram Bot API (for the bot layer).
- Starknet RPC APIs (for smart contract interactions).
- ArgentTMA SDK (as a further abstraction for managing wallet actions).
- Also, illustrate how data flows between the user interface, command processor backend, and the smart contract. For example, a “submit transaction” flow will start from the user (tma), continue to the bot (backend), and then be committed on-chain.

##### Architectural patterns and design principles
- Separation of concerns: Note the clear separation between contract logic (blockchain), business logic (Telegram bot commands and transaction handling in Node.js), and front-end UI display.
- Use of modern web architectural standards: Next.js for the frontend, TypeScript for the backend, and Cairo for blockchain contracts.
- Modular design: Demonstrated by having separate directories/modules for tests, configurations, and distinct functionalities (e.g., libraries under bot/controller/lib and tma/components/ui).

##### Technology details
- Backend: Node.js, TypeScript, and Starknet.js.
- Smart contract: Cairo (for Starknet).
- Frontend: Next.js, Tailwind CSS, and React.
- Use of external integrations/APIs like Telegram Bot API and ArgentTMA SDK.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        TMA["Telegram Mini App (TMA)"]:::frontend
        TMAUI["UI Components"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BotCore["Telegram Bot / Command Processor (Core)"]:::backend
        BotController["Bot Controller"]:::backend
        TelegramHelper["Telegram Helper"]:::backend
        ArgentTMA["ArgentTMA SDK Integration"]:::backend
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        Contract["Starknet Multisig Smart Contract (Argonaut)"]:::blockchain
        ContractLib["Contract Library"]:::blockchain
        ContractTests["Contract Tests"]:::blockchain
    end

    %% External Services
    TelegramAPI["Telegram Bot API"]:::external
    StarknetRPC["Starknet RPC API"]:::external

    %% Data Flows
    TMA -->|"SubmitTransaction"| BotCore
    TelegramAPI -->|"ReceiveCommands"| BotCore
    BotCore -->|"ProcessCommand"| BotController
    BotController -->|"InvokeTransaction"| Contract
    BotController -->|"ManageWallet"| ArgentTMA
    ContractLib -->|"SupportFunctions"| Contract
    ContractTests -->|"ValidateContract"| Contract
    Contract -->|"OnChainInteraction"| StarknetRPC

    %% Click Events
    click TMA "https://github.com/capgoblin/argonaut/blob/main/tma/app/layout.tsx"
    click TMAUI "https://github.com/capgoblin/argonaut/tree/main/tma/components/ui"
    click BotCore "https://github.com/capgoblin/argonaut/blob/main/bot/index.ts"
    click BotController "https://github.com/capgoblin/argonaut/blob/main/bot/controller/index.ts"
    click TelegramHelper "https://github.com/capgoblin/argonaut/blob/main/bot/controller/lib/Telegram.ts"
    click Contract "https://github.com/capgoblin/argonaut/blob/main/argonaut/src/multisig.cairo"
    click ContractLib "https://github.com/capgoblin/argonaut/blob/main/argonaut/src/lib.cairo"
    click ContractTests "https://github.com/capgoblin/argonaut/tree/main/argonaut/src/tests"

    %% Styles
    classDef frontend fill:#F9E79F,stroke:#B7950B,color:#000;
    classDef backend fill:#D5F5E3,stroke:#27AE60,color:#000;
    classDef blockchain fill:#AED6F1,stroke:#2471A3,color:#000;
    classDef external fill:#FADBD8,stroke:#E74C3C,color:#000;
```
