# 0xoucan/celo-mind-web architecture

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

- Interactive diagram: https://gitdiagram.com/0xoucan/celo-mind-web
- Repository: https://github.com/0xoucan/celo-mind-web

## Overview

##### Layers and Main Components
- Presentation Layer (UI)
– Components: MainLayout, Header, ChatInterface, InfoPanel, WalletBalances, TransactionMonitor
- State & Integration Layer
– Providers: WalletContext, PrivyProvider
– Config & Constants: config.ts, network constants
- Services Layer (Client Logic)
– agentService.ts (talks to backend AI API)
– blockchainService.ts (direct blockchain calls, balance fetch)
– transactionService.ts (queueing, polling, status)
- External Systems Layer
– CeloMΔIND Backend API (http://localhost:4000)
– External Wallets (MetaMask, Rabby) via Privy SDK
– Celo Blockchain & DeFi Protocols (AAVE, ICHI, Mento)
– CeloScan Explorer

##### Relationships & Data Flows
- User → ChatInterface: enters natural-language commands
- ChatInterface → agentService → Backend API (/api/agent/chat)
- Backend AI → returns transaction request(s) → agentService → ChatInterface
- ChatInterface → transactionService → PrivyProvider → External Wallet (sign)
- Signed Tx → blockchainService → Celo Blockchain → DeFi Protocols
- transactionService polls status → TransactionMonitor → UI
- blockchainService fetches balances → WalletBalances → UI

##### Architectural Patterns
- Layered architecture separating UI, state/integration, services, and external systems
- Context-based state management (React Context for Wallet)
- Service-based abstraction for API & blockchain interactions
- Dependency injection via Providers (PrivyProvider)
- Real-time polling & reactive updates

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Presentation Layer"
        ML["MainLayout"]:::frontend
        H["Header"]:::frontend
        CI["ChatInterface"]:::frontend
        IP["InfoPanel"]:::frontend
        WB["WalletBalances"]:::frontend
        TM["TransactionMonitor"]:::frontend
    end

    subgraph "State & Integration Layer"
        WC["WalletContext"]:::state
        PP["PrivyProvider"]:::state
        CFG["config.ts"]:::state
        NET["network constants"]:::state
    end

    subgraph "Services Layer"
        AS["agentService"]:::service
        BS["blockchainService"]:::service
        TS["transactionService"]:::service
    end

    subgraph "External Systems Layer"
        API["CeloMΔIND Backend API"]:::external
        EW["External Wallets"]:::external
        CB["Celo Blockchain & DeFi Protocols"]:::external
        CS["CeloScan Explorer"]:::external
    end

    %% Data Flows
    User["User"]:::external -->|"enters commands"| CI
    CI -->|"POST /api/agent/chat"| AS
    AS -->|"response (tx requests)"| CI
    CI -->|"initiateTx"| TS
    TS -->|"signTx"| PP
    PP -->|"connect/sign"| EW
    TS -->|"broadcastTx"| BS
    BS -->|"onchain call"| CB
    TS -->|"pollStatus"| TM
    BS -->|"fetchBalance"| WB
    CB -->|"onchain data"| CS

    %% Click Events
    click ML "https://github.com/0xoucan/celo-mind-web/blob/main/src/components/MainLayout.tsx"
    click H "https://github.com/0xoucan/celo-mind-web/blob/main/src/components/Header.tsx"
    click CI "https://github.com/0xoucan/celo-mind-web/blob/main/src/components/ChatInterface.tsx"
    click IP "https://github.com/0xoucan/celo-mind-web/blob/main/src/components/InfoPanel.tsx"
    click WB "https://github.com/0xoucan/celo-mind-web/blob/main/src/components/WalletBalances.tsx"
    click TM "https://github.com/0xoucan/celo-mind-web/blob/main/src/components/TransactionMonitor.tsx"
    click WC "https://github.com/0xoucan/celo-mind-web/blob/main/src/providers/WalletContext.tsx"
    click PP "https://github.com/0xoucan/celo-mind-web/blob/main/src/providers/PrivyProvider.tsx"
    click CFG "https://github.com/0xoucan/celo-mind-web/blob/main/src/config.ts"
    click NET "https://github.com/0xoucan/celo-mind-web/blob/main/src/constants/network.ts"
    click AS "https://github.com/0xoucan/celo-mind-web/blob/main/src/services/agentService.ts"
    click BS "https://github.com/0xoucan/celo-mind-web/blob/main/src/services/blockchainService.ts"
    click TS "https://github.com/0xoucan/celo-mind-web/blob/main/src/services/transactionService.ts"

    %% Styles
    classDef frontend fill:#cceeff,stroke:#333,stroke-width:1px
    classDef state fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef service fill:#ffdd99,stroke:#333,stroke-width:1px
    classDef external fill:#eeeeee,stroke:#333,stroke-width:1px
```
