# jarrodwatts/ai-discord-agent architecture

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

- Interactive diagram: https://gitdiagram.com/jarrodwatts/ai-discord-agent
- Repository: https://github.com/jarrodwatts/ai-discord-agent

## Overview

##### Main Components

a) Client Layer:
- Discord Server/Client (represented as a user-facing interface)
- Voice Channel Component (for voice interactions)

b) Application Core:
- Discord Bot Service (main application entry point)
- Voice Handler System
- OpenAI Integration Module
- Blockchain Integration Module
- ElevenLabs Voice Service

c) External Services:
- Discord API
- OpenAI Services (Assistant API & Whisper API)
- ElevenLabs API
- Ethereum Blockchain

##### Component Relationships and Data Flow

- User → Discord Server → Discord Bot
- Voice Channel ↔ Voice Handler
- Voice Handler → OpenAI Whisper (Speech-to-Text)
- OpenAI Assistant → Tools Module
- Tools Module → Blockchain (via Viem)
- Bot Response → ElevenLabs (Text-to-Speech)

##### Specific Implementation Details

a) Core Services (src/):
- Discord Client (src/discord/discordClient.ts)
- Voice Handler (src/discord/VoiceHandler.ts)

b) OpenAI Integration (src/openai/):
- Assistant Creation
- Thread Management
- Run Execution
- Tool Calls Handler

c) Blockchain Tools (src/tools/):
- ERC20 Deployment
- Balance Checking
- Wallet Management

d) Configuration Layer:
- Contract Details
- Discord Settings
- ElevenLabs Config
- Custom Prompts

##### Technical Stack Indicators

A tech stack section showing:
- Node.js v22
- TypeScript
- Discord.js
- OpenAI API
- ElevenLabs API
- Viem (Ethereum interaction)

Create clear boundaries between:
- User Interface Layer (Discord)
- Application Layer (Bot Logic)
- Integration Layer (External Services)
- Blockchain Layer (Ethereum Interactions)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        DC[Discord Server]
        VC[Voice Channel]
    end

    subgraph "Application Core"
        DBS["Discord Bot Service"]:::core
        VH["Voice Handler"]:::core
        OAI["OpenAI Integration"]:::ai
        BCI["Blockchain Integration"]:::blockchain
        ELS["ElevenLabs Service"]:::voice
    end

    subgraph "External Services"
        direction TB
        DAPI[("Discord API")]:::external
        subgraph "OpenAI Services"
            OAAPI[("Assistant API")]:::external
            WHISPER[("Whisper API")]:::external
        end
        ELAPI[("ElevenLabs API")]:::external
        ETH[("Ethereum Blockchain")]:::external
    end

    subgraph "OpenAI Module"
        direction TB
        AC["Assistant Creation"]:::ai
        TM["Thread Management"]:::ai
        RE["Run Execution"]:::ai
        TCH["Tool Calls Handler"]:::ai
    end

    subgraph "Blockchain Tools"
        direction TB
        ED["ERC20 Deployment"]:::blockchain
        BC["Balance Checking"]:::blockchain
        WM["Wallet Management"]:::blockchain
        VC_CLIENT["Viem Client"]:::blockchain
    end

    subgraph "Configuration"
        direction TB
        CD["Contract Details"]:::config
        DS["Discord Settings"]:::config
        EC["ElevenLabs Config"]:::config
        CP["Custom Prompts"]:::config
    end

    %% Relationships
    DC <--> DAPI
    VC <--> VH
    VH --> WHISPER
    DBS --> OAI
    OAI --> OAAPI
    TCH --> BCI
    BCI --> ETH
    DBS --> ELS
    ELS --> ELAPI

    %% OpenAI Module Flow
    OAI --> AC
    OAI --> TM
    OAI --> RE
    RE --> TCH

    %% Blockchain Flow
    BCI --> ED
    BCI --> BC
    BCI --> WM
    BCI --> VC_CLIENT

    %% Configuration Dependencies
    CD --> BCI
    DS --> DBS
    EC --> ELS
    CP --> OAI

    %% Click Events
    click DBS "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/discord/discordClient.ts"
    click VH "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/discord/VoiceHandler.ts"
    click AC "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/openai/createAssistant.ts"
    click TM "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/openai/createThread.ts"
    click RE "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/openai/createRun.ts"
    click TCH "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/openai/handleRunToolCalls.ts"
    click ED "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/tools/deployErc20.ts"
    click BC "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/tools/getBalance.ts"
    click WM "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/tools/getWalletAddress.ts"
    click VC_CLIENT "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/viem/createViemPublicClient.ts"
    click CD "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/const/contractDetails.ts"
    click DS "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/const/discordDetails.ts"
    click EC "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/const/elevenLabs.ts"
    click CP "https://github.com/jarrodwatts/ai-discord-agent/blob/main/src/const/twocoats-prompt.ts"

    %% Styling
    classDef core fill:#2b6cb0,stroke:#1a4971,color:#fff
    classDef ai fill:#48bb78,stroke:#2f855a,color:#fff
    classDef blockchain fill:#ed8936,stroke:#c05621,color:#fff
    classDef voice fill:#805ad5,stroke:#553c9a,color:#fff
    classDef external fill:#718096,stroke:#4a5568,color:#fff
    classDef config fill:#a0aec0,stroke:#718096,color:#fff
```
