# 0xoucan/mictlai architecture

> Architecture diagram of the GitHub repository 0xoucan/mictlai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xoucan/mictlai
- Repository: https://github.com/0xoucan/mictlai

## Overview

##### Project type and purpose
- This is a full-stack AI-powered cross-chain bridge application.
- Frontend (“celo-mind-web”) is a React/Vite web UI for chat-based cross-chain operations.
- Backend (“celo-mind-dn”) is a Node.js/TypeScript API server that orchestrates AI agents and blockchain actions.

##### File structure
- Top level:
- celo-mind-dn/ (backend)
- celo-mind-web/ (frontend)
- launch.sh to install and start both services
- Backend:
- src/action-providers/ contains many providers, but we’ll focus on basic-atomic-swaps
- src/api-server.ts for Express API
- src/chatbot.ts for AI orchestration
- src/services/ for blockchain relay and escrow logic
- src/utils/ for logger, rate limiter, transaction utilities
- .env.example, package.json, tsconfig.json
- Frontend:
- src/components/ for UI widgets (ChatInterface, TransactionMonitor, WalletBalances, etc.)
- src/providers/ for React contexts (WalletContext, PrivyProvider)
- src/services/ for agentService (chat API), blockchainService, transactionService
- Vite configuration, Tailwind config

##### README for additional insights
- The README confirms a two-part architecture: a backend agent server and a frontend
- Backend uses Express, CORS, streaming responses, OpenAI API, Telegram integration
- Frontend uses React, browser wallets, real-time polling of pending transactions, viem library for chain interactions
- Cross-chain atomic swap is the core feature

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (UI)"
        direction TB
        FWApp["Frontend Web App"]:::ui
        ChatInt["ChatInterface"]:::ui
        TransMon["TransactionMonitor"]:::ui
        WalletBal["WalletBalances"]:::ui
        WalletConn["WalletConnect"]:::ui
        Header["Header & MainLayout"]:::ui
        WalletCtx["WalletContext"]:::ui
        PrivyProv["PrivyProvider"]:::ui
        AgentSrv["agentService"]:::ui
        BlockchainSrv["blockchainService"]:::ui
        TxSrv["transactionService"]:::ui
        ConfigF["Global & Network Config"]:::ui
    end

    %% Wallet Extension
    subgraph "Browser Wallet Extension"
        WalletExt["MetaMask/Rabby"]:::external
    end

    %% Backend API and Agent
    subgraph "Backend API & Agent"
        direction TB
        API["API Server"]:::api
        Chatbot["AI Agent / Chatbot"]:::agent
        TeleBot["Telegram Bot Interface"]:::external
    end

    %% Action Provider
    subgraph "Action Provider"
        BasicAS["basic-atomic-swaps"]:::provider
    end

    %% Backend Services & Config
    subgraph "Backend Services & Config"
        direction TB
        Relay["Atomic Swap Relay Service"]:::provider
        NetConst["Network Config"]:::provider
        NetMod["Network Module"]:::provider
        Logger["Logger Utility"]:::util
        RateLimiter["Rate Limiter"]:::util
        TxUtils["Transaction Utilities"]:::util
    end

    %% Blockchain Networks
    subgraph "Blockchain Networks"
        Base["Base"]:::chain
        Arbitrum["Arbitrum"]:::chain
        Mantle["Mantle"]:::chain
        zkSync["zkSync Era"]:::chain
    end

    %% External APIs
    subgraph "External APIs"
        OpenAI["OpenAI API"]:::external
    end

    %% Interactions
    FWApp -->|"calls /api/agent/chat"| API
    API -->|"forwards chat request"| Chatbot
    Chatbot -->|"uses OpenAI"| OpenAI
    Chatbot -->|"invokes provider"| BasicAS
    BasicAS -->|"uses relay"| Relay
    BasicAS -->|"reads network cfg"| NetConst
    BasicAS -->|"calls network module"| NetMod
    Relay -->|"sends tx to"| Base
    Relay -->|"sends tx to"| Arbitrum
    Relay -->|"sends tx to"| Mantle
    Relay -->|"sends tx to"| zkSync
    Chatbot -->|"optional updates"| TeleBot
    API -->|"returns unsigned payload"| FWApp
    FWApp -->|"prompts signature"| WalletExt
    WalletExt -->|"broadcasts tx to"| Base
    WalletExt -->|"broadcasts tx to"| Arbitrum
    WalletExt -->|"broadcasts tx to"| Mantle
    WalletExt -->|"broadcasts tx to"| zkSync
    FWApp -->|"polls status"| API
    FWApp -->|"direct chain query"| BlockchainSrv
    API -->|"logs events"| Logger
    API -->|"rate limits"| RateLimiter
    API -->|"utilizes tx utils"| TxUtils

    %% Click Events
    click FWApp "https://github.com/0xoucan/mictlai/tree/main/celo-mind-web/"
    click API "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/api-server.ts"
    click Chatbot "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/chatbot.ts"
    click BasicAS "https://github.com/0xoucan/mictlai/tree/main/celo-mind-dn/src/action-providers/basic-atomic-swaps/"
    click NetConst "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/constants/network.ts"
    click NetMod "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/network/network.ts"
    click Relay "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/services/atomic-swap-relay.ts"
    click TeleBot "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/telegram-interface.ts"
    click Logger "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/utils/logger.ts"
    click RateLimiter "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/utils/rate-limiter.ts"
    click TxUtils "https://github.com/0xoucan/mictlai/blob/main/celo-mind-dn/src/utils/transaction-utils.ts"
    click ChatInt "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/components/ChatInterface.tsx"
    click TransMon "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/components/TransactionMonitor.tsx"
    click WalletBal "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/components/WalletBalances.tsx"
    click WalletConn "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/components/WalletConnect.tsx"
    click Header "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/components/Header.tsx"
    click Header "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/components/MainLayout.tsx"
    click WalletCtx "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/providers/WalletContext.tsx"
    click PrivyProv "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/providers/PrivyProvider.tsx"
    click AgentSrv "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/services/agentService.ts"
    click BlockchainSrv "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/services/blockchainService.ts"
    click TxSrv "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/services/transactionService.ts"
    click ConfigF "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/config.ts"
    click ConfigF "https://github.com/0xoucan/mictlai/blob/main/celo-mind-web/src/constants/network.ts"

    %% Styles
    classDef ui fill:#CCE5FF,stroke:#1E90FF,color:#000;
    classDef api fill:#D4EDDA,stroke:#28A745,color:#000;
    classDef agent fill:#D4EDDA,stroke:#28A745,color:#000;
    classDef provider fill:#FFF3CD,stroke:#FFC107,color:#000;
    classDef chain fill:#E2E3E5,stroke:#6C757D,color:#000;
    classDef external fill:#E1BEE7,stroke:#9C27B0,color:#000;
    classDef util fill:#F8D7DA,stroke:#DC3545,color:#000;
```
