# luuccaaaa/gittrack-discord-bot architecture

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

- Interactive diagram: https://gitdiagram.com/luuccaaaa/gittrack-discord-bot
- Repository: https://github.com/luuccaaaa/gittrack-discord-bot

## Overview

##### Project type and purpose
- GitTrack is an open-source backend service (a Discord bot) that listens for GitHub webhooks, processes events, and sends notifications to Discord servers via slash commands and real-time messages. It is not a traditional “full-stack” web app with a user GUI, but rather a message-oriented integration service.

##### File structure
- Top-level folders:
- config/ – configuration files (e.g., nodemon settings)
- docker/ – Dockerfiles and Compose files for dev and prod
- docs/ – contributing docs and internal design notes
- prisma/ – database schema definition and migrations
- scripts/ – deployment scripts (deploy.sh, deploy-prod.sh)
- src/
– bot.js: initializes the Discord.js client and registers slash commands
– index.js: application entry point, sets up the HTTP server and webhook route
– commands/: handlers for each Discord slash command (setup, link, unlink, status, etc.)
– handlers/: GitHub webhook event processors (checks, PR, milestone, workflow, generic)
– functions/: reusable utilities (branch matching, limit checking, permission checking)
- Configuration files (.env.example, docker-compose, Prisma schema) control environment variables, database connections, and deployment settings.

##### README for additional insights
- The “🏗️ Architecture” section already outlines major modules: Discord Bot, Webhook Handler, Limit Checker, Database Layer (Prisma + PostgreSQL).
- Tech stack: Node.js 18+, Discord.js 14, Prisma ORM, PostgreSQL, Docker.

##### Detail without overthinking
- Environment/configuration as side notes (ENV vars, Docker Compose).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Services
    subgraph "External Services"
        direction TB
        GitHub["GitHub Webhooks"]:::external
        DiscordAPI["Discord API"]:::external
    end

    %% Application Layer
    subgraph "Bot Application" 
        direction TB
        DiscordClient["Discord Client (src/bot.js)"]:::appComp
        HTTPServer["HTTP Server / Webhook Receiver (src/index.js)"]:::appComp

        subgraph "Command Processing"
            direction TB
            SetupCmd["setup.js"]:::appComp
            LinkCmd["link.js"]:::appComp
            UnlinkCmd["unlink.js"]:::appComp
            StatusCmd["status.js"]:::appComp
            PingCmd["ping.js"]:::appComp
            HelpCmd["help.js"]:::appComp
            ResetCmd["reset.js"]:::appComp
            RemoveRepoCmd["remove-repo.js"]:::appComp
            SetDefaultChannelCmd["set-default-channel.js"]:::appComp
            SetEventChannelCmd["set-event-channel.js"]:::appComp
            RemoveEventChannelCmd["remove-event-channel.js"]:::appComp
            EditEventCmd["edit-event.js"]:::appComp
        end

        subgraph "Event Handlers"
            direction TB
            WebhookHandler["webhookHandler.js"]:::appComp
            PRHandler["pullRequestHandlers.js"]:::appComp
            ChecksHandler["checksHandlers.js"]:::appComp
            MilestoneWorkflowHandler["milestoneAndWorkflowHandlers.js"]:::appComp
        end

        subgraph "Utility Functions"
            direction TB
            BranchMatcher["branchMatcher.js"]:::appComp
            LimitChecker["limitChecker.js"]:::appComp
            PermissionChecker["permissionChecker.js"]:::appComp
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        PrismaORM["Prisma ORM (prisma/schema.prisma)"]:::dbComp
        PostgreSQL["PostgreSQL"]:::dbComp
    end

    %% Deployment Configuration
    subgraph "Deployment"
        direction TB
        ConfigNodemon["nodemon.json"]:::configComp
        DockerfileDev["docker-compose.dev.yml"]:::configComp
        DockerfileProd["docker-compose.prod.yml"]:::configComp
        DeployScriptDev["deploy.sh"]:::configComp
        DeployScriptProd["deploy-prod.sh"]:::configComp
    end

    %% Relationships
    GitHub -->|"WebhookPayload"| HTTPServer
    HTTPServer -->|"Signature Verification"| WebhookHandler
    WebhookHandler -->|"Dispatch Event"| PRHandler
    WebhookHandler -->|"Dispatch Event"| ChecksHandler
    WebhookHandler -->|"Dispatch Event"| MilestoneWorkflowHandler

    PRHandler -->|"calls"| BranchMatcher
    PRHandler -->|"calls"| LimitChecker
    PRHandler -->|"calls"| PermissionChecker

    ChecksHandler -->|"calls"| LimitChecker
    MilestoneWorkflowHandler -->|"calls"| PermissionChecker

    PRHandler -->|"Query/Write"| PrismaORM
    ChecksHandler -->|"Query/Write"| PrismaORM
    MilestoneWorkflowHandler -->|"Query/Write"| PrismaORM

    SetupCmd -->|"SlashCommandInteraction"| BranchMatcher
    LinkCmd -->|"SlashCommandInteraction"| PermissionChecker
    StatusCmd -->|"SlashCommandInteraction"| PrismaORM
    PingCmd -->|"SlashCommandInteraction"| PrismaORM
    HelpCmd -->|"SlashCommandInteraction"| PrismaORM
    ResetCmd -->|"SlashCommandInteraction"| PrismaORM
    RemoveRepoCmd -->|"SlashCommandInteraction"| PrismaORM
    SetDefaultChannelCmd -->|"SlashCommandInteraction"| PrismaORM
    SetEventChannelCmd -->|"SlashCommandInteraction"| PrismaORM
    RemoveEventChannelCmd -->|"SlashCommandInteraction"| PrismaORM
    EditEventCmd -->|"SlashCommandInteraction"| PrismaORM

    PrismaORM -->|"SQL Queries"| PostgreSQL

    DiscordClient -->|"Registers Commands"| DiscordAPI
    SetupCmd -->|"Responds"| DiscordAPI
    LinkCmd -->|"Responds"| DiscordAPI
    UnlinkCmd -->|"Responds"| DiscordAPI
    StatusCmd -->|"Responds"| DiscordAPI
    PingCmd -->|"Responds"| DiscordAPI
    HelpCmd -->|"Responds"| DiscordAPI
    ResetCmd -->|"Responds"| DiscordAPI
    RemoveRepoCmd -->|"Responds"| DiscordAPI
    SetDefaultChannelCmd -->|"Responds"| DiscordAPI
    SetEventChannelCmd -->|"Responds"| DiscordAPI
    RemoveEventChannelCmd -->|"Responds"| DiscordAPI
    EditEventCmd -->|"Responds"| DiscordAPI

    PRHandler -->|"Sends Notification"| DiscordAPI
    ChecksHandler -->|"Sends Notification"| DiscordAPI
    MilestoneWorkflowHandler -->|"Sends Notification"| DiscordAPI

    %% Click Events
    click DiscordClient "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/bot.js"
    click HTTPServer "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/index.js"
    click WebhookHandler "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/handlers/webhookHandler.js"
    click PRHandler "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/handlers/pullRequestHandlers.js"
    click ChecksHandler "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/handlers/checksHandlers.js"
    click MilestoneWorkflowHandler "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/handlers/milestoneAndWorkflowHandlers.js"
    click SetupCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/setup.js"
    click LinkCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/link.js"
    click UnlinkCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/unlink.js"
    click StatusCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/status.js"
    click PingCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/ping.js"
    click HelpCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/help.js"
    click ResetCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/reset.js"
    click RemoveRepoCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/remove-repo.js"
    click SetDefaultChannelCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/set-default-channel.js"
    click SetEventChannelCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/set-event-channel.js"
    click RemoveEventChannelCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/remove-event-channel.js"
    click EditEventCmd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/commands/edit-event.js"
    click BranchMatcher "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/functions/branchMatcher.js"
    click LimitChecker "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/functions/limitChecker.js"
    click PermissionChecker "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/src/functions/permissionChecker.js"
    click PrismaORM "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/prisma/schema.prisma"
    click ConfigNodemon "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/config/nodemon.json"
    click DockerfileDev "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/docker/docker-compose.dev.yml"
    click DockerfileProd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/docker/docker-compose.prod.yml"
    click DeployScriptDev "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/scripts/deploy.sh"
    click DeployScriptProd "https://github.com/luuccaaaa/gittrack-discord-bot/blob/main/scripts/deploy-prod.sh"

    %% Styles
    classDef external fill:#cce5ff,stroke:#3399ff,color:#004085
    classDef appComp fill:#d4edda,stroke:#28a745,color:#155724
    classDef dbComp fill:#fff3cd,stroke:#ffc107,color:#856404
    classDef configComp fill:#e2e3e5,stroke:#6c757d,color:#383d41
```
