# polowiper/dokkanwtbot architecture

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

- Interactive diagram: https://gitdiagram.com/polowiper/dokkanwtbot
- Repository: https://github.com/polowiper/dokkanwtbot

## Overview

##### Main Components
- Discord Bot Client: Represented by main.py, which is the entry point that connects to Discord. It loads the command “cogs” (e.g., bulk.py, compare.py, help.py, etc.) to handle various bot commands.
- Command Modules (“Cogs”): The cogs/ directory consists of separate Python files that encapsulate specific commands or features (like leaderboard, ranking, etc.). They are modular pieces helping maintain the bot’s functionality.
- API Integration & Data Acquisition: Scripts like api.py and fetch_and_save.py are responsible for connecting to the external Dokkan Battle API. They fetch and update data from the API source.
- Data Management & Storage: The final_data folder contains subdirectories (by usernames/identifiers) that appear to store processed user data. Scripts such as update_data.py and update_db.py are likely used to refresh or handle this data.
- Configuration & Utilities: Files like config.py, config.json, and dependencies.txt store configuration settings (like BOT_TOKEN, API_TOKEN, and other parameters), while other utility scripts (like cli_main.py, manual_update.py, render.py, and final_render.py) help in bot operations and potentially rendering outputs.
- External Data Source: Although not part of the repository, the external Dokkan APi (via T6) is a key element in the system as it supplies the dynamic data the bot uses.

##### Relationships and Interactions
- Data Flow: Start with an external data source (Dokkan Battle API) that provides game data. The fetch_and_save.py script pulls data, and the update_data.py/update_db.py scripts process and update this data into the stored files in final_data.
- Command Execution: The main.py loads various cogs. When a Discord user issues a command, the appropriate cog (command module) is activated, and it uses the stored data (or possibly fresh API data) to serve responses (e.g., leaderboard, user comparisons).
- Configuration: config.py (and config.json) provide settings and credentials for both the Discord bot and API interactions. These settings are used across the client and data-fetching processes.

##### Architectural Patterns & Design Principles
- Modularity: The use of a “cogs” directory clearly indicates a modular design where each command is separated into its own file for better maintainability.
- Separation of Concerns: Different scripts handle distinct functionalities (e.g., data fetching vs. bot command handling vs. configuration).
- Data Persistence: The directory structure under final_data shows that user data is persisted in a structured file system layout rather than a dedicated database.
- Config-driven Behavior: Configuration files (config.py, config.json, dependencies.txt) drive runtime behavior, ensuring flexibility in deployment and operation.

##### Relevant Technologies & Frameworks
- Python for the overall application.
- Discord API libraries (such as discord.py, if used) to manage bot connections and interactions.
- External API integration for Dokkan Battle data (via the T6 API).
- Pip for dependency management.
- File-based data storage (using the final_data folder structure).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source
    subgraph "External Data Source"
        ext1["Dokkan Battle API"]:::external
    end

    %% Data Acquisition & Processing
    subgraph "Data Acquisition & Processing"
        api["API Integration (api.py)"]:::processor
        fetcher["Data Fetcher (fetch_and_save.py)"]:::processor
        updater1["Data Updater (update_data.py)"]:::processor
        updater2["Data Updater (update_db.py)"]:::processor
        ext1 -->|"provides"| api
        ext1 -->|"provides"| fetcher
        api -->|"processes"| updater1
        fetcher -->|"processes"| updater2
    end

    %% Data Management & Storage
    subgraph "Data Management & Storage"
        ds["Data Storage (final_data/)"]:::storage
        updater1 -->|"updates"| ds
        updater2 -->|"updates"| ds
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        cfg["Configuration (config.py)"]:::config
        cfgjson["Config JSON (config.json)"]:::config
        deps["Dependencies (dependencies.txt)"]:::config
        cli["CLI (cli_main.py)"]:::config
        manual["Manual Update (manual_update.py)"]:::config
        render["Render (render.py)"]:::config
        finalrender["Final Render (final_render.py)"]:::config
    end

    %% Discord Bot Core
    subgraph "Discord Bot Core"
        client["Discord Bot Client (main.py)"]:::bot
    end

    %% Command Modules
    subgraph "Command Modules"
        cogs["Command Modules (cogs/)"]:::bot
    end

    %% Interconnections
    client -->|"loads"| cogs
    client -->|"accesses"| ds
    client -->|"uses"| cfg
    client -->|"uses"| cfgjson
    client -->|"uses"| deps
    client -->|"uses"| cli
    client -->|"uses"| manual
    client -->|"uses"| render
    client -->|"uses"| finalrender
    api ---|"config via"| cfg

    %% Click Events
    click client "https://github.com/polowiper/dokkanwtbot/blob/main/main.py"
    click cogs "https://github.com/polowiper/dokkanwtbot/tree/main/cogs/"
    click api "https://github.com/polowiper/dokkanwtbot/blob/main/api.py"
    click fetcher "https://github.com/polowiper/dokkanwtbot/blob/main/fetch_and_save.py"
    click updater1 "https://github.com/polowiper/dokkanwtbot/blob/main/update_data.py"
    click updater2 "https://github.com/polowiper/dokkanwtbot/blob/main/update_db.py"
    click ds "https://github.com/polowiper/dokkanwtbot/tree/main/final_data/"
    click cfg "https://github.com/polowiper/dokkanwtbot/blob/main/config.py"
    click cfgjson "https://github.com/polowiper/dokkanwtbot/blob/main/config.json"
    click deps "https://github.com/polowiper/dokkanwtbot/blob/main/dependencies.txt"
    click cli "https://github.com/polowiper/dokkanwtbot/blob/main/cli_main.py"
    click manual "https://github.com/polowiper/dokkanwtbot/blob/main/manual_update.py"
    click render "https://github.com/polowiper/dokkanwtbot/blob/main/render.py"
    click finalrender "https://github.com/polowiper/dokkanwtbot/blob/main/final_render.py"

    %% Styles
    classDef external fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef processor fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef storage fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef bot fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef config fill:#d1ecf1,stroke:#333,stroke-width:2px;
```
