# yksen/harmony architecture

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

- Interactive diagram: https://gitdiagram.com/yksen/harmony
- Repository: https://github.com/yksen/harmony

## Overview

##### Main Components
- Discord Interface:
- The bot interacts with Discord’s API, listens for commands, and sends messages.
- Represents the entry point where the bot receives events (commands, guild messages, etc.).
- Command Module:
- The file "src/commands.rs" handles parsing and executing user commands.
- This module is essential for capturing and routing commands from Discord.
- Handlers Module:
- The file "src/handlers.rs" likely contains event handlers or processing logic for different types of bot events.
- Core Library:
- "src/lib.rs" defines the core logic and common functions shared among the various modules.
- Application Entrypoint:
- "src/main.rs" is where the application sets up its configuration (reading the environment via .env or variables like DISCORD_TOKEN), initializes services, and starts the bot.
- External Music and Video Handling:
- The README points to installing yt-dlp. This suggests the bot invokes system commands or libraries to download or stream media from YouTube.

##### Relationships and Interactions
- The Command Module then interacts with:
- The Handlers Module for performing event-specific actions.
- The Core Library which ties everything together.
- Once media is fetched and processed, the Music Playback logic (likely embedded within one of these modules) sends the audio back into the Discord channel.
- A configuration component that reads environmental variables (like the DISCORD_TOKEN) from a .env file, initializing the bot appropriately.

##### Architectural Patterns and Design Principles
- Modular design: Separation into distinct modules (commands, handlers, core library) improves maintainability.
- Event-driven architecture: The bot responds to Discord events, processes them through handlers, and triggers commands accordingly.
- Integration with external dependencies: Clear separation when calling tools like yt-dlp.
- Good configuration management: Use of environment variables and .env files for secrets and bot configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    extDiscord["Discord API"]:::external
    configEnv["Environment Configuration"]:::config
    cicd["CI/CD Process"]:::cicd

    %% Rust Application Subgraph
    subgraph "Rust Application"
        appInit["Discord Event Listener"]:::internal
        commands["Command Module"]:::internal
        handlers["Handlers Module"]:::internal
        core["Core Library"]:::internal
        media["Media Downloader (yt-dlp)"]:::internal
        playback["Music Playback"]:::internal
    end

    %% Connections
    configEnv --> appInit
    extDiscord --> appInit
    appInit -->|"commands"| commands
    appInit -->|"events"| handlers
    commands -->|"logic"| core
    commands -->|"fetch_media"| media
    media -->|"deliver_media"| playback
    cicd -->|"deploys"| appInit

    %% Click Events
    click appInit "https://github.com/yksen/harmony/blob/master/src/main.rs"
    click commands "https://github.com/yksen/harmony/blob/master/src/commands.rs"
    click handlers "https://github.com/yksen/harmony/blob/master/src/handlers.rs"
    click core "https://github.com/yksen/harmony/blob/master/src/lib.rs"
    click configEnv "https://github.com/yksen/harmony/blob/master/.env.example"
    click cicd "https://github.com/yksen/harmony/blob/master/.github/workflows/release.yml"

    %% Styles
    classDef external fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef internal fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef config fill:#ffe082,stroke:#333,stroke-width:2px;
    classDef cicd fill:#ef9a9a,stroke:#333,stroke-width:2px;
```
