# zero6992/chatgpt-discord-bot architecture

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

- Interactive diagram: https://gitdiagram.com/zero6992/chatgpt-discord-bot
- Repository: https://github.com/zero6992/chatgpt-discord-bot

## Overview

##### Project Type Analysis
This is a Discord bot integration project that connects multiple AI services (ChatGPT, Gemini, Bing) with Discord, featuring both chat and image generation capabilities.

##### Main Components

A. Client Layer:
- Discord Bot Client (represented by src/bot.py)
- Auto Login Component (auto_login directory)

B. Core Services:
- Chat Service Handler
- Image Generation Service Handler
- Persona Management System (src/personas.py)

C. External API Integration:
- Discord API
- OpenAI API (ChatGPT)
- Google Gemini API
- Bing Image Generation API

D. Utility Components:
- Message Handler (utils/message_utils.py)
- Logging System (src/log.py)
- Configuration Management (.env)

**[Client Layer]**
- ↓
**[Core Services Layer]**
- ↓
**[External APIs Layer]**

##### Specific Elements

**[Discord Bot Client] ←→ [Message Handler]**
- ↓
**[Core Service Router]**
- ↙     ↓     ↘
**[Chat] [Image Gen] [Persona Manager]**
- ↓        ↓
**[External API Integrations]**

##### Key Interactions to Highlight

- Command Processing Flow:
- Discord messages → Bot Client → Message Handler → Appropriate Service
- Service → External API → Response → Discord

- Configuration Flow:
- Environment Variables → Service Configuration
- System Prompt → Chat Service

##### Technical Details

- Environment configuration dependencies
- Logging system integration
- Authentication flow for various APIs

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        DC[Discord Bot Client]
        AL[Auto Login Component]
    end

    subgraph Core
        MH[Message Handler]
        MC[Mode Controller]
        
        subgraph Services
            CS[Chat Service]
            IS[Image Service]
            PS[Persona Manager]
        end
    end

    subgraph External
        DA[Discord API]
        
        subgraph AI_APIs
            OAI[OpenAI API]
            GEM[Google Gemini]
            BING[Bing API]
        end
    end

    subgraph Config
        ENV[Environment Config]
        SP[System Prompt]
        LOG[Logging System]
        DOC[Docker Container]
    end

    %% Core relationships
    DC --> MH
    AL --> DC
    MH --> MC
    MC --> CS & IS & PS
    CS --> OAI & GEM
    IS --> BING
    DC --> DA

    %% Config relationships
    ENV -.-> DC
    ENV -.-> CS
    ENV -.-> IS
    SP -.-> CS
    LOG -.-> DC
    DOC -.-> DC

    %% Styling
    classDef client fill:#a8d1ff
    classDef service fill:#90EE90
    classDef external fill:#d3d3d3
    classDef config fill:#FFE5B4
    classDef container stroke-dasharray: 5 5

    class DC,AL client
    class CS,IS,PS,MH,MC service
    class DA,OAI,GEM,BING external
    class ENV,SP,LOG,DOC config
    class DOC container

    %% Click events
    click DC "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/src/bot.py"
    click AL "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/auto_login/AutoLogin.py"
    click IS "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/src/art.py"
    click PS "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/src/personas.py"
    click MH "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/utils/message_utils.py"
    click LOG "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/src/log.py"
    click ENV "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/.env.example"
    click SP "https://github.com/Zero6992/chatGPT-discord-bot/blob/main/system_prompt.txt"
    click DOC "https://github.com/Zero6992/chatGPT-discord-bot/tree/main/Dockerfile"

    %% Legend
    subgraph Legend
        L1[Client Components]:::client
        L2[Service Components]:::service
        L3[External APIs]:::external
        L4[Configuration]:::config
        L5[Direct Connection]
        L6[Config Dependency]
    end
```
