# daniellwdb/roka architecture

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

- Interactive diagram: https://gitdiagram.com/daniellwdb/roka
- Repository: https://github.com/daniellwdb/roka

## Overview

##### Project Type & Purpose
- This is a specialized bot system that automates game management tasks (including title management and DKP tracking) linked to Discord channels.
- It includes integration with external applications (e.g., BlueStacks for automating the game emulator), image recognition via OpenCV, and has a database layer managed with Prisma. There is also a Next.js-based website offering a UI/landing page.

##### Main Components
a. Discord Bot Core:
- Commands: Found under src/commands, these include a rich set of commands (like cancel, config, mod, queue, scan, etc.) that define the bot’s behavior.
- Event Handlers: Under src/events, these include modules to handle Discord interactions (message-create, interaction-create, ready, etc.), forming the event-driven aspect of the bot.

b. Database Layer:

c. Worker Scripts (Automation & Image Processing):
- Worker Scripts: Located in both dependencies/worker-script and a separate worker-script directory, these scripts include utilities (e.g., image processing, arrayBufferToBase64, etc.), constants, and node-specific functions to interact with underlying systems (e.g., BlueStacks and OpenCV bindings).
- External Dependencies: Include external tools (e.g., clipboard_x86_64.exe, OpenCV node module, patches for clipboardy and tesseract.js) as additional sub-components since these are crucial for the bot’s automation capabilities.

d. External Services & Dependencies:
- BlueStacks: The README details how to configure BlueStacks (including CPU, memory, display settings) which indicates integration with the bot. Represent BlueStacks as an external service that the worker scripts interact with.
- OpenCV & Microsoft Visual C++ Redistributable: These are prerequisites for handling image processing tasks; note these as external dependency components.

e. Website (Front-end Component):
- Next.js Project: The website folder contains a complete Next.js application (with pages, components, styles, testing configurations, etc.). Label a component “Website (UI/Next.js)” that provides a visual interface, possibly for monitoring bot status or providing user-facing documentation.

f. Configuration & Installer:
- Configuration Files: Include config.yml.example (copied to config.yml) and other config files (config.ts) that define runtime settings.
- Installer and Release Packaging: The presence of installer.nsi and NSIS instructions for production implies a packaged release flow. Represent an “Installer/Release” component that handles deployment, packaging, and updates.

##### Relationships & Interactions
- Data Flow:
- The Discord bot (via command and event modules) receives inputs from users on Discord, processes them, and may update or query the database.
- The worker scripts perform background automation tasks (e.g., image recognition, state restoration) and interact with external executables (BlueStacks, OpenCV).
- The website component may display reports or allow configuration updates, interacting with the same database or possibly a REST/GraphQL API if that is exposed (not explicitly detailed but hinted by the presence of GraphQL fragments in the website source).

- Dependencies:
- The core bot logic directly depends on the configuration settings and database operations.
- Worker scripts and automation flows depend on native modules and external assets (binaries, patch files).
- The installer component packages all these parts for an end-user production release.

##### Architectural Patterns & Design Principles
- Modular Design: The project is separated into distinct modules – bot commands, event handling, worker scripts, and website – each residing in separate directories.
- Event-Driven Architecture: Particularly in the Discord bot where commands and events trigger different automation and state management actions.
- ORM-Based Data Management: Using Prisma to manage migrations and schema, indicating a decoupled persistence layer.
- Integration with External Systems: Through BlueStacks and OpenCV, emphasizing external automation and image processing capabilities.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Configuration & Installer Layer
    Config["Configuration (config.yml.example)"]:::config
    Installer["Installer/Release"]:::installer
    Config --> Installer

    %% Discord Bot Core Layer
    subgraph "Discord Bot Core"
        Commands["Commands"]:::bot
        Events["Event Handlers"]:::bot
    end
    Config --> Commands
    Config --> Events

    %% Database (Prisma) Layer
    subgraph "Database (Prisma)"
        PrismaMain["Prisma (prisma)"]:::database
        PrismaDep["Prisma Dependencies"]:::database
    end
    Commands -->|"CRUD"| PrismaMain
    Events -->|"CRUD"| PrismaMain

    %% Worker Scripts & Automation Layer
    subgraph "Worker Scripts & Automation"
        Worker1["Worker Scripts (dependencies/worker-script)"]:::worker
        Worker2["Worker Scripts (worker-script)"]:::worker
    end
    Events -->|"trigger"| Worker1
    Config --> Worker1
    Config --> Worker2

    %% External Tools Layer
    subgraph "External Tools"
        BlueStacks["BlueStacks"]:::external
        ClipboardAsset["Clipboard Exec (assets)"]:::external
        ClipboardDep["Clipboard Exec (dependencies)"]:::external
        OpenCVModule["OpenCV Node Module"]:::external
        Patches["Patches (clipboardy/tesseract.js)"]:::external
    end
    Worker1 -->|"automation"| BlueStacks
    Worker1 -->|"automation"| ClipboardAsset
    Worker1 -->|"automation"| ClipboardDep
    Worker2 -->|"automation"| OpenCVModule
    Worker2 -->|"automation"| Patches

    %% Website (UI/Next.js) Layer
    subgraph "Website (UI/Next.js)"
        Website["Next.js Website"]:::website
    end
    Config --> Website
    PrismaMain -->|"data"| Website

    %% Styles
    classDef config fill:#f9c,stroke:#333,stroke-width:2px;
    classDef installer fill:#faa,stroke:#333,stroke-width:2px;
    classDef bot fill:#ccf,stroke:#333,stroke-width:2px;
    classDef database fill:#cfc,stroke:#333,stroke-width:2px;
    classDef worker fill:#fcf,stroke:#333,stroke-width:2px;
    classDef external fill:#ff9,stroke:#333,stroke-width:2px;
    classDef website fill:#9cf,stroke:#333,stroke-width:2px;

    %% Click Events
    click Commands "https://github.com/daniellwdb/roka/tree/main/src/commands"
    click Events "https://github.com/daniellwdb/roka/tree/main/src/events"
    click PrismaMain "https://github.com/daniellwdb/roka/tree/main/prisma"
    click PrismaDep "https://github.com/daniellwdb/roka/tree/main/dependencies/prisma"
    click Worker1 "https://github.com/daniellwdb/roka/tree/main/dependencies/worker-script"
    click Worker2 "https://github.com/daniellwdb/roka/tree/main/worker-script"
    click ClipboardAsset "https://github.com/daniellwdb/roka/blob/main/assets/clipboard_x86_64.exe"
    click ClipboardDep "https://github.com/daniellwdb/roka/blob/main/dependencies/clipboard_x86_64.exe"
    click OpenCVModule "https://github.com/daniellwdb/roka/blob/main/dependencies/build/Release/opencv4nodejs.node"
    click Patches "https://github.com/daniellwdb/roka/tree/main/patches"
    click Website "https://github.com/daniellwdb/roka/tree/main/website"
    click Config "https://github.com/daniellwdb/roka/blob/main/config.yml.example"
    click Installer "https://github.com/daniellwdb/roka/blob/main/installer.nsi"
```
