# underctrl-io/welcomer-bot architecture

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

- Interactive diagram: https://gitdiagram.com/underctrl-io/welcomer-bot
- Repository: https://github.com/underctrl-io/welcomer-bot

## Overview

##### Main Components
- API Component:
- Built with Express, using TypeScript.
- Manages authentication (JWT) and makes use of MongoDB (with Mongoose) for persistent data and Redis (via ioredis) for caching.
- Contains middleware, models, utility functions (like the Discord API helper), and is structured with clear separation (e.g., routes, lib, and middleware directories).
- Bot Component:
- Uses Discord.js and CommandKit.
- Handles event listeners (like guildMemberAdd and ready) and processes commands (organized under commands/ folders).
- Makes HTTP requests to the API (using Axios) for operations that require backend support.
- Dashboard Component:
- A React-based frontend built with Vite, styled using Tailwind CSS and DaisyUI.
- Implements state management (Jotai) and data fetching (TanStack Query), and uses React Router for client-side routing.
- Provides a user-friendly interface for configuration and management, interfacing with the API via HTTP (Axios).

##### Displaying Relationships and Interactions
- The Dashboard sending REST API requests to the API.
- The Bot interacting with the API to fetch or update information.
- Possibly token-based or session-based authentication in the API, impacting both the Bot and Dashboard interactions.
- Communication channels (HTTP/HTTPS for Dashboard and Bot) and show that both use Axios for making network requests.

##### Important Architectural Patterns & Design Principles
- Component Separation: Each major section (API, Bot, Dashboard) is decoupled so each can be developed and deployed independently.
- Modular Structure: Within the API, separate modules (routes, middleware, models, utilities) indicate a modular architecture.
- Use of Standard Technologies: Emphasize use of Express, Mongoose, ioredis, Discord.js, React, and Vite as the backbone frameworks/libraries.
- Full-Stack Integration: The design should highlight that while each service is independent, they all converge to serve the Discord bot’s functionality and developer’s needs.

##### Final Touches
- To capture the overarching flow that begins with user or bot events, proceeding through the API, and reflected in the Dashboard.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Component
    subgraph "API Component"
        A1["API Server (Express, TypeScript)"]:::backend
        A2["Routes Module"]:::backend
        A3["Middleware Module"]:::backend
        A4["Lib Module (DB&Cache)"]:::backend
        A5["Models (Guild,User)"]:::backend
        A6["Discord API Utility"]:::backend
        A1 --> A2
        A1 --> A3
        A1 --> A4
        A1 --> A5
        A1 --> A6
    end

    %% Bot Component
    subgraph "Bot Component"
        B1["Bot Server (Discord.js,CommandKit)"]:::backend
        B2["Event Listeners"]:::backend
        B3["Command Handlers"]:::backend
        B4["API Helper (Axios)"]:::backend
        B1 --> B2
        B1 --> B3
        B1 --> B4
    end

    %% Dashboard Component
    subgraph "Dashboard Component"
        D1["Dashboard Core (React,Vite)"]:::frontend
        D2["Index HTML"]:::frontend
        D3["App Script"]:::frontend
        D4["React UI Components"]:::frontend
        D5["Pages&Routing"]:::frontend
        D6["Data Handling"]:::frontend
        D7["Vite Config"]:::frontend
        D1 --> D2
        D1 --> D3
        D1 --> D4
        D1 --> D5
        D1 --> D6
        D1 --> D7
    end

    %% External/Database Components
    M1["MongoDB (Mongoose)"]:::database
    R1["Redis (ioredis)"]:::database
    E1["Discord"]:::external

    %% Connections between components
    A1 -->|"DBConnection"| M1
    A1 -->|"Cache"| R1
    B1 -->|"EventMessage"| E1
    B4 -->|"HTTPRequest"| A1
    D1 -->|"HTTPRequest"| A1

    %% Click Events for API Component
    click A1 "https://github.com/underctrl-io/welcomer-bot/blob/main/api/src/index.ts"
    click A2 "https://github.com/underctrl-io/welcomer-bot/tree/main/api/src/routes/"
    click A3 "https://github.com/underctrl-io/welcomer-bot/tree/main/api/src/middleware/"
    click A4 "https://github.com/underctrl-io/welcomer-bot/tree/main/api/src/lib/"
    click A5 "https://github.com/underctrl-io/welcomer-bot/tree/main/api/src/models/"
    click A6 "https://github.com/underctrl-io/welcomer-bot/blob/main/api/src/utils/discord-api.ts"

    %% Click Events for Bot Component
    click B1 "https://github.com/underctrl-io/welcomer-bot/blob/main/bot/src/index.ts"
    click B2 "https://github.com/underctrl-io/welcomer-bot/tree/main/bot/src/events/"
    click B3 "https://github.com/underctrl-io/welcomer-bot/tree/main/bot/src/commands/"
    click B4 "https://github.com/underctrl-io/welcomer-bot/blob/main/bot/src/utils/api.ts"

    %% Click Events for Dashboard Component
    click D1 "https://github.com/underctrl-io/welcomer-bot/tree/main/dashboard/src/"
    click D2 "https://github.com/underctrl-io/welcomer-bot/blob/main/dashboard/index.html"
    click D3 "https://github.com/underctrl-io/welcomer-bot/blob/main/dashboard/app.js"
    click D4 "https://github.com/underctrl-io/welcomer-bot/tree/main/dashboard/src/components/"
    click D5 "https://github.com/underctrl-io/welcomer-bot/tree/main/dashboard/src/pages/"
    click D6 "https://github.com/underctrl-io/welcomer-bot/tree/main/dashboard/src/data/"
    click D7 "https://github.com/underctrl-io/welcomer-bot/blob/main/dashboard/vite.config.ts"

    %% Styles
    classDef backend fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef database fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
