# techthrives/discordbots architecture

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

- Interactive diagram: https://gitdiagram.com/techthrives/discordbots
- Repository: https://github.com/techthrives/discordbots

## Overview

##### Project type and purpose
- This is a Node.js “monorepo” hosting two independent Discord bots (“astris-ai” and “muzer”) managed together (turbo.json, root package.json).
- “astris-ai” provides AI-powered text and image commands (uses OpenAI APIs).
- “muzer” provides music playback and playlist management (uses Discord voice API, MongoDB for persistence).

##### File structure
- Top-level:
- package.json / package-lock.json – root dependencies and scripts (likely for monorepo tooling).
- turbo.json – indicates use of Turborepo for task orchestration.
- bots/astris-ai – one microservice.
- bots/muzer – another microservice.
- Each bot:
- index.js – entry point.
- config.js – environment/config loader.
- commands/ – modular slash‐command handlers.
- events/ – Discord event listeners (ready, interactionCreate, messageCreate).
- helpers/utils – domain logic (OpenAI calls, text/image gen, common utilities).
- deploy-commands.js (.astris-ai) – CLI to register commands with Discord.
- muzer adds mongodb.js, player.js, languages/, ui/ – for persistence, audio pipeline, localization, UI embed styling.

##### README
- No architectural description (429 error), but file structure and filenames imply the stacks:
- Node.js + Discord.js for both.
- OpenAI API integration in astris-ai.
- MongoDB for muzer.

a. Main components
- Root Monorepo (Turborepo)
- Astris-AI Bot Service
- Muzer Bot Service
- External Services: Discord Gateway & REST API, OpenAI API, MongoDB Cluster, Audio Stream Sources (e.g., YouTube)
b. Relationships and interactions
1. User sends a slash-command or message → Discord Gateway
2. Gateway forwards event → Bot Service (astris-ai or muzer)
3. Event handler dispatches to appropriate Command Module
4. Command Module:
- astris-ai may call helper.textGeneration or helper.imgGeneration → OpenAI API
- muzer may call player.js (audio pipeline) and/or mongodb.js → MongoDB
5. Bot Service sends response (text, embed, image, voice) → Discord API → User
c. Architectural patterns
- Microservices (two independent bots) within one repo
- Event-driven: Discord events trigger handlers
- Modular command pattern (each command is a separate file)
- Helper/utility layering for domain logic separation
d. Key technologies
- Node.js, Discord.js
- Turborepo (mono-repo tooling)
- OpenAI SDK / REST calls (astris-ai)
- MongoDB Node driver (muzer)
- Discord Voice API (muzer)

##### Detail
- Folder’s role.
- Data flow for a sample command (e.g., “/summarize” → OpenAI).
- Asynchronous event-driven nature.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Discord
    subgraph "User Interaction"
        User["User"]:::user
        Discord["Discord Gateway & REST API"]:::external
    end
    User --> Discord

    %% Root Monorepo
    subgraph "Root Monorepo (Turborepo)"
        Turbo["turbo.json"]:::monorepo
        RootPkg["package.json"]:::monorepo
    end
    Turbo --> AstrisService
    RootPkg --> AstrisService
    Turbo --> MuzerService
    RootPkg --> MuzerService

    %% Astris-AI Service
    subgraph "Astris-AI Service" 
        AEntry["index.js"]:::entry
        AConfig["config.js"]:::config
        ADeploy["deploy-commands.js"]:::deploy
        subgraph Commands
            AHelp["help.js"]:::cmd
            AInvite["invite.js"]:::cmd
            ASetup["setup-info.js"]:::cmd
            AFlux["flux.js"]:::cmd
            AImg["img.js"]:::cmd
            AReimg["reimg.js"]:::cmd
            AClear["clear.js"]:::cmd
            ASum["summarize.js"]:::cmd
            AAvatar["avatar.js"]:::cmd
            APing["ping.js"]:::cmd
            AServerInfo["serverinfo.js"]:::cmd
            AUserInfo["userinfo.js"]:::cmd
        end
        subgraph Events
            AReady["ready.js"]:::event
            AInteraction["interactionCreate.js"]:::event
            AMessage["messageCreate.js"]:::event
        end
        subgraph Helpers
            ATextGen["textGeneration.js"]:::helper
            AImgGen["imgGeneration.js"]:::helper
        end
        subgraph Utils
            ACommon["common.js"]:::util
            ATextHandler["textHandler.js"]:::util
        end
        AEntry --> AConfig
        AEntry --> Events
        Events --> Commands
        Commands --> Helpers
        Helpers -->|"calls"| OpenAI["OpenAI API"]:::external
        Utils --> AEntry
        ADeploy -->|"registers commands with"| Discord
    end
    Discord --> AstrisService

    %% Muzer Service
    subgraph "Muzer Service"
        MEntry["index.js"]:::entry
        MAltEntry["bot.js"]:::entry
        MConfig["config.js"]:::config
        subgraph Commands_M
            MCommands["commands/*.js"]:::cmd
        end
        subgraph Events_M
            MReady["ready.js"]:::event
            MInteraction["interactionCreate.js"]:::event
        end
        MPersist["mongodb.js"]:::database
        MPlayer["player.js"]:::service
        MLang["languages/*.js"]:::config
        MUI["ui/"]:::ui
        MEntry --> MConfig
        MAltEntry --> MConfig
        MEntry --> Events_M
        Events_M --> Commands_M
        Commands_M --> MPersist
        Commands_M --> MPlayer
        MPlayer -->|"streams from"| AudioSource["Audio Stream Sources"]:::external
        MPersist -->|"stores data in"| MongoDB["MongoDB Cluster"]:::database
        MUI --> Commands_M
    end
    Discord --> MuzerService

    %% Styles
    classDef user fill:#f9f,stroke:#333,stroke-width:2px
    classDef external fill:#bbf,stroke:#333,stroke-width:2px
    classDef monorepo fill:#ffd,stroke:#333,stroke-width:2px
    classDef service fill:#dfd,stroke:#333,stroke-width:2px
    classDef entry fill:#afa,stroke:#333,stroke-width:2px
    classDef config fill:#fea,stroke:#333,stroke-width:2px
    classDef deploy fill:#ffa,stroke:#333,stroke-width:2px
    classDef cmd fill:#fda,stroke:#333,stroke-width:2px
    classDef event fill:#def,stroke:#333,stroke-width:2px
    classDef helper fill:#cdf,stroke:#333,stroke-width:2px
    classDef util fill:#ecc,stroke:#333,stroke-width:2px
    classDef database fill:#ace,stroke:#333,stroke-width:2px
    classDef ui fill:#cfc,stroke:#333,stroke-width:2px

    %% Click Events
    click Turbo "https://github.com/techthrives/discordbots/blob/main/turbo.json"
    click RootPkg "https://github.com/techthrives/discordbots/blob/main/package.json"
    click AEntry "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/index.js"
    click AConfig "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/config.js"
    click ADeploy "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/deploy-commands.js"
    click AHelp "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/help.js"
    click AInvite "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/invite.js"
    click ASetup "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/setup-info.js"
    click AFlux "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/flux.js"
    click AImg "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/img.js"
    click AReimg "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/reimg.js"
    click AClear "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/clear.js"
    click ASum "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/summarize.js"
    click AAvatar "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/avatar.js"
    click APing "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/ping.js"
    click AServerInfo "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/serverinfo.js"
    click AUserInfo "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/commands/userinfo.js"
    click AReady "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/events/ready.js"
    click AInteraction "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/events/interactionCreate.js"
    click AMessage "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/events/messageCreate.js"
    click ATextGen "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/helper/textGeneration.js"
    click AImgGen "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/helper/imgGeneration.js"
    click ACommon "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/utils/common.js"
    click ATextHandler "https://github.com/techthrives/discordbots/blob/main/bots/astris-ai/utils/textHandler.js"
    click MEntry "https://github.com/techthrives/discordbots/blob/main/bots/muzer/index.js"
    click MAltEntry "https://github.com/techthrives/discordbots/blob/main/bots/muzer/bot.js"
    click MConfig "https://github.com/techthrives/discordbots/blob/main/bots/muzer/config.js"
    click MCommands "https://github.com/techthrives/discordbots/tree/main/bots/muzer/commands"
    click MReady "https://github.com/techthrives/discordbots/blob/main/bots/muzer/events/ready.js"
    click MInteraction "https://github.com/techthrives/discordbots/blob/main/bots/muzer/events/interactionCreate.js"
    click MPersist "https://github.com/techthrives/discordbots/blob/main/bots/muzer/mongodb.js"
    click MPlayer "https://github.com/techthrives/discordbots/blob/main/bots/muzer/player.js"
    click MLang "https://github.com/techthrives/discordbots/tree/main/bots/muzer/languages"
    click MUI "https://github.com/techthrives/discordbots/tree/main/bots/muzer/ui"
```
