# valehk08/adabot architecture

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

- Interactive diagram: https://gitdiagram.com/valehk08/adabot
- Repository: https://github.com/valehk08/adabot

## Overview

##### Project Type & Purpose
ADABot is a Python-based, modular Discord bot built with discord.py. It uses Google Gemini AI and a host of external APIs to deliver conversational AI, summarization, image generation, news, finance data, weather, translation, polls, and fun social interactions—while persisting context in an SQLite database.

##### File Structure Analysis
- bot.py
- Initializes the Discord client, loads .env/config, and registers all Cogs.
- config.py
- Reads environment variables and exposes configuration (tokens, API keys).
- cogs/
- database.py – Manages SQLite connection and context storage (users/messages).
- main_commands.py – Core AI commands (`!chat`, `!tone`, `!translate`, etc.).
- extra_commands.py – Summarization (`!summarize`), AI image generation (`!generate`).
- utility.py – Helper commands (`!info`, reminders, polls).
- uis.py – Discord UI components (menus, buttons, selects).
- .env
- Stores DISCORD_TOKEN, OPENROUTER_API_KEY, etc.
- requirements.txt
- Lists external dependencies.

##### Main Components & Relationships
a. User & Discord Gateway (discord.py)
– Receives user messages/events and delivers bot responses.
b. Bot Core (bot.py + config.py)
– Single Discord client instance; loads and wires up all Cogs.
c. Cogs Layer
– Each Cog is a plugin handling a group of commands or events.
– database.py Cog provides read/write context for other Cogs.
d. Domain Services
– Wrappers around external APIs:
- Google Gemini (chat, summarization, image gen, historical facts)
- NewsAPI, yfinance (stock data), Open-Meteo, Horoscope API
- Imgflip & OpenRouter (memes), translation, polls logic
e. Persistence Layer
– SQLite (`DataBase.db`) storing user join dates and recent messages for context.
f. External APIs
– Multiple third-party services; called via HTTP libraries (requests, newsapi, yfinance).

##### Architectural Patterns & Design Principles
- Plugin Architecture: discord.py Cogs isolate command sets.
- Layered Architecture:
1. Presentation – Discord Gateway
2. Application – Bot Core + Cogs
3. Domain – Service wrappers (AI, data fetchers)
4. Persistence – SQLite database
5. Integration – External APIs
- Single Responsibility: Each Cog/Service has a focused role
- Configuration via DI: config.py abstracts environment/secrets

- “Discord Gateway” (external system)
- “Bot Core” (bot.py + config)
- DatabaseCog
- MainCommandsCog
- ExtraCommandsCog
- UtilityCog
- UIsCog
- User → Discord Gateway → Bot Core → appropriate Cog → Domain Service → External API / DB → back through the same path → User
- DB Cog → SQLite DB for both read (context fetch) and write (persist messages/users)
- Blue rectangles: Discord Gateway & External APIs
- Green rectangles: Bot Core & Cogs
- Yellow rectangles: Domain Services

## Diagram (Mermaid)

```mermaid
flowchart TB
    User["User"]:::user
    subgraph "Discord Layer"
        DiscordGateway["Discord Gateway"]:::external
    end
    subgraph "Application Layer"
        BotCore["Bot Core"]:::core
        Config["Config Module"]:::core
        Env[".env"]:::core
        Requirements["requirements.txt"]:::core
    end
    subgraph "Cogs Layer"
        DatabaseCog["DatabaseCog"]:::cog
        MainCommandsCog["MainCommandsCog"]:::cog
        ExtraCommandsCog["ExtraCommandsCog"]:::cog
        UtilityCog["UtilityCog"]:::cog
        UIsCog["UIsCog"]:::cog
    end
    subgraph "Domain Services"
        Gemini["Google Gemini"]:::service
        NewsAPI["NewsAPI"]:::service
        YFinance["yfinance"]:::service
        OpenMeteo["Open-Meteo"]:::service
        Imgflip["Imgflip"]:::service
        Horoscope["Horoscope API"]:::service
    end
    SQLiteDB["SQLite DB\n(users, messages)"]:::db

    User -->|"command event"| DiscordGateway
    DiscordGateway -->|"dispatch event"| BotCore
    Env -->|"load vars"| BotCore
    Requirements -->|"load dependencies"| BotCore
    BotCore -->|"register Cogs"| DatabaseCog
    BotCore --> MainCommandsCog
    BotCore --> ExtraCommandsCog
    BotCore --> UtilityCog
    BotCore --> UIsCog

    DatabaseCog -->|"DB read/write"| SQLiteDB
    MainCommandsCog -->|"DB read/write"| SQLiteDB
    MainCommandsCog -->|"API request"| Gemini
    MainCommandsCog -->|"API request"| NewsAPI
    ExtraCommandsCog -->|"API request"| Gemini
    ExtraCommandsCog -->|"API request"| Imgflip
    UtilityCog -->|"API request"| Horoscope
    UtilityCog -->|"API request"| OpenMeteo
    UtilityCog -->|"API request"| NewsAPI
    UIsCog -->|"render UI"| DiscordGateway

    Gemini -->|"response"| MainCommandsCog
    NewsAPI -->|"response"| UtilityCog
    Imgflip -->|"response"| ExtraCommandsCog
    OpenMeteo -->|"response"| UtilityCog
    Horoscope -->|"response"| UtilityCog
    SQLiteDB -->|"data response"| DatabaseCog

    DatabaseCog -->|"response message"| DiscordGateway
    MainCommandsCog -->|"response message"| DiscordGateway
    ExtraCommandsCog -->|"response message"| DiscordGateway
    UtilityCog -->|"response message"| DiscordGateway
    UIsCog -->|"response message"| DiscordGateway

    subgraph "Legend"
        L1["Blue: External Systems"]:::legendExt
        L2["Green: Bot Core & Cogs"]:::legendCore
        L3["Yellow: Domain Services"]:::legendService
        L4["Brown: Database"]:::legendDB
    end

    classDef user fill:#EEEEEE,stroke:#333,stroke-width:1px
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef cog fill:#90EE90,stroke:#333,stroke-width:1px
    classDef service fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef db fill:#D2B48C,stroke:#333,stroke-width:1px
    classDef legendExt fill:#ADD8E6,stroke-width:0px
    classDef legendCore fill:#90EE90,stroke-width:0px
    classDef legendService fill:#FFFF99,stroke-width:0px
    classDef legendDB fill:#D2B48C,stroke-width:0px

    click BotCore "https://github.com/valehk08/adabot/blob/main/bot.py"
    click Config "https://github.com/valehk08/adabot/blob/main/config.py"
    click DatabaseCog "https://github.com/valehk08/adabot/blob/main/cogs/database.py"
    click MainCommandsCog "https://github.com/valehk08/adabot/blob/main/cogs/main_commands.py"
    click ExtraCommandsCog "https://github.com/valehk08/adabot/blob/main/cogs/extra_commands.py"
    click UtilityCog "https://github.com/valehk08/adabot/blob/main/cogs/utility.py"
    click UIsCog "https://github.com/valehk08/adabot/blob/main/cogs/uis.py"
    click Env "https://github.com/valehk08/adabot/blob/main/.env"
    click Requirements "https://github.com/valehk08/adabot/blob/main/requirements.txt"
```
