# 0xfreysa/agent architecture

> Architecture diagram of the GitHub repository 0xfreysa/agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xfreysa/agent
- Repository: https://github.com/0xfreysa/agent

## Overview

Key Components to Include:

##### Frontend Layer
- Next.js Application Structure
- Main UI Components (Chat interface, FAQ, Terms, Lore sections)
- Web3 Integration Components (Wallet connections)

##### Backend Services Layer
- LLM Integration Services (Claude and OpenAI)
- Blockchain Services
- Social Media Integration (Twitter, Telegram)
- Price Services

##### Smart Contract Layer
- AVA Contract
- Payment Contract
- TypeChain Generated Types

##### Component Relationships

Frontend Layer:
**[Home Page] --- [Chat Component] --- [Game UI]**

**[Web3 Providers] -- [Wallet Connection] -- [Transaction Handling]**

Services Layer:
**[LLM Service]     [Blockchain Service]     [Social Services]**

**[Claude API]        [Ethereum Handler]      [Twitter/Telegram]**
**[OpenAI API]        [Price Service]         [Broadcast Systems]**

Smart Contract Layer:
**[AVA Contract] --- [Payment Contract]**

**[TypeChain Bindings] [Contract Events]**

##### External Integrations
- Base Blockchain Connection
- LLM API Endpoints
- Social Media Broadcasting

##### Important Notes
- Message flow from user input to LLM processing
- Payment verification flow
- Demonstrate how the prize pool updates
- Global timer mechanism
- How historical context is maintained

##### Technical Stack Callouts
- Next.js 13+ (App Router)
- Tailwind CSS
- TypeScript
- Ethereum (Base Chain)
- Multiple LLM Providers
- Web3 Libraries (wagmi)

Remember to:
- Keep the core game loop visible and clear
- Security measures around fund management
- Scalability considerations
- Monitoring and feedback loops
- Document the fail-safes and timer mechanisms

This system design should emphasize the unique aspects of Freysa as an adversarial AI agent game while clearly showing how all components work together to create a secure and engaging experience.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        Home["Home Page"]
        Chat["Chat Interface"]:::chat
        FAQ["FAQ Section"]:::faq
        Terms["Terms Section"]:::terms
        Lore["Lore Section"]:::lore
        Web3Connect["Web3 Components"]:::web3
        GameUI["Game UI Components"]:::gameui
        CoreUI["Core UI Elements"]:::coreui
        Animations["Animation Components"]:::anim
        Forms["Form Components"]:::forms
        Providers["Provider Components"]:::providers
    end

    subgraph Services
        LLMService["LLM Integration"]
        Claude["Claude Service"]:::claude
        OpenAI["OpenAI Service"]:::openai
        
        BlockchainService["Blockchain Services"]:::blockchain
        EthereumHooks["Ethereum Hooks"]:::ethhooks
        WagmiConfig["Wagmi Configuration"]:::wagmi
        
        SocialService["Social Media Integration"]
        Twitter["Twitter Service"]:::twitter
        Telegram["Telegram Service"]:::telegram
        
        PriceService["Price Service"]:::price
    end

    subgraph Contracts
        AVAContract["AVA Contract Types"]:::ava
        PaymentContract["Payment Contract Types"]:::payment
        ContractFactories["Contract Factories"]:::factories
        SmartContracts["Smart Contracts Source"]:::contracts
    end

    Home --> Chat
    Home --> FAQ
    Home --> Terms
    Home --> Lore
    Home --> Web3Connect
    Home --> GameUI

    GameUI --> CoreUI
    GameUI --> Animations
    GameUI --> Forms
    GameUI --> Providers

    Chat --> LLMService
    LLMService --> Claude
    LLMService --> OpenAI

    Web3Connect --> BlockchainService
    BlockchainService --> EthereumHooks
    BlockchainService --> WagmiConfig
    BlockchainService --> Contracts

    GameUI --> SocialService
    SocialService --> Twitter
    SocialService --> Telegram

    BlockchainService --> PriceService

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef chat fill:#e1f5fe,stroke:#333
    classDef faq fill:#e8f5e9,stroke:#333
    classDef terms fill:#f3e5f5,stroke:#333
    classDef lore fill:#fff3e0,stroke:#333
    classDef web3 fill:#fce4ec,stroke:#333
    classDef gameui fill:#e8eaf6,stroke:#333
    classDef coreui fill:#f1f8e9,stroke:#333
    classDef anim fill:#fff8e1,stroke:#333
    classDef forms fill:#e0f2f1,stroke:#333
    classDef providers fill:#f3e5f5,stroke:#333
    classDef blockchain fill:#ffebee,stroke:#333
    classDef ethhooks fill:#fce4ec,stroke:#333
    classDef wagmi fill:#f3e5f5,stroke:#333
    classDef twitter fill:#e3f2fd,stroke:#333
    classDef telegram fill:#e8eaf6,stroke:#333
    classDef price fill:#e0f7fa,stroke:#333
    classDef ava fill:#fff3e0,stroke:#333
    classDef payment fill:#fbe9e7,stroke:#333
    classDef factories fill:#f9fbe7,stroke:#333
    classDef contracts fill:#fff8e1,stroke:#333
    classDef claude fill:#e8f5e9,stroke:#333
    classDef openai fill:#e1f5fe,stroke:#333

    click Chat "https://github.com/0xfreysa/agent/tree/main/app/home/components/Chat/"
    click FAQ "https://github.com/0xfreysa/agent/tree/main/app/faq/"
    click Terms "https://github.com/0xfreysa/agent/tree/main/app/terms/"
    click Lore "https://github.com/0xfreysa/agent/tree/main/app/lore/"
    click Web3Connect "https://github.com/0xfreysa/agent/blob/main/components/connect.tsx"
    click Claude "https://github.com/0xfreysa/agent/blob/main/services/llm/claude.ts"
    click OpenAI "https://github.com/0xfreysa/agent/blob/main/services/llm/openai.ts"
    click BlockchainService "https://github.com/0xfreysa/agent/blob/main/services/blockchain/ethereum/index.tsx"
    click Twitter "https://github.com/0xfreysa/agent/blob/main/services/twitter/postTweet.ts"
    click Telegram "https://github.com/0xfreysa/agent/blob/main/services/telegram/broadcastTelegram.ts"
    click PriceService "https://github.com/0xfreysa/agent/blob/main/services/price/price.ts"
    click AVAContract "https://github.com/0xfreysa/agent/blob/main/typechain-types/AVA.ts"
    click PaymentContract "https://github.com/0xfreysa/agent/blob/main/typechain-types/AvaPayment.ts"
    click ContractFactories "https://github.com/0xfreysa/agent/tree/main/typechain-types/factories/"
    click SmartContracts "https://github.com/0xfreysa/agent/tree/main/contracts/src/"
    click EthereumHooks "https://github.com/0xfreysa/agent/blob/main/app/hooks/ethereum.ts"
    click WagmiConfig "https://github.com/0xfreysa/agent/blob/main/app/wagmi.ts"
    click CoreUI "https://github.com/0xfreysa/agent/tree/main/components/ui/"
    click Animations "https://github.com/0xfreysa/agent/blob/main/components/animations.tsx"
    click Forms "https://github.com/0xfreysa/agent/blob/main/components/form.tsx"
    click Providers "https://github.com/0xfreysa/agent/blob/main/components/providers.tsx"
    click GameUI "https://github.com/0xfreysa/agent/blob/main/app/home/components/Chat/Chat.tsx"
```
