# garimatus/anti-hate-discord-app architecture

> Architecture diagram of the GitHub repository garimatus/anti-hate-discord-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/garimatus/anti-hate-discord-app
- Repository: https://github.com/garimatus/anti-hate-discord-app

## Overview

##### Project type and purpose
- This is a single‐service, bot‐style backend application written in TypeScript that connects to the Discord Gateway, uses Ollama (a local LLM inference service) to detect hate speech in chat messages in real time, and persists data in a Cassandra database.

##### File structure
- Top‐level: Dockerfile, docker-compose.yaml, scripts/, src/, tsconfig.json
- src/index.ts: application entry point
- src/commands & src/events: Discord command modules and event handlers (follows a plugin pattern for extensibility)
- src/ollama: LLM‐integration layer that initializes sessions and constructs prompts
- src/database: Cassandra client, query definitions, mapper, and utility collectors
- src/configuration/i18n & src/locales: internationalization support
- src/utils: shared helpers (logger, command‐setter, event‐setter)
- src/api: HTTP client wrappers (e.g., Ollama API calls)
- Scripts and Docker compose orchestrate the Bot service, the Ollama container, and Cassandra

##### README for additional insights
- Describes environment variables for Discord OAuth2, Cassandra, Ollama
- Instructs to run Ollama separately (WIP) and Cassandra via Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Bot Service
    subgraph "Bot Service (Node.js / TypeScript)"
        direction TB
        Entry["Entry Point\nsrc/index.ts"]:::internal
        subgraph "Plugin Layers"
            direction TB
            CommandHandler["Command Handler\nsrc/commands"]:::internal
            HandlerUtil["handler.ts"]:::internal
            CollecterCMD["collecter.ts"]:::internal
            Deployer["deployer.ts"]:::internal
            EventListener["Event Listener\nsrc/events"]:::internal
            ListenerUtil["listener.ts"]:::internal
            CollecterEV["collecter.ts"]:::internal
        end
        subgraph "Configuration Manager"
            direction TB
            ConfigLoader["Config Loader\nsrc/configuration/index.ts"]:::internal
            I18nCore["ConfigurableI18n.ts"]:::internal
            I18nDefs["module.d.ts"]:::internal
            LocaleEN["en.json"]:::internal
            LocaleES["es.json"]:::internal
        end
        subgraph "LLM Integration Layer"
            direction TB
            LLMCore["Ollama API\nsrc/ollama/index.ts"]:::internal
            SessionInit["initialize-ollama-session.ts"]:::internal
            PromptDefs["prompts/"]:::internal
        end
        subgraph "Database Access Layer"
            direction TB
            DBIndex["index.ts"]:::internal
            DBClient["client.ts"]:::internal
            DBMapper["mapper.ts"]:::internal
            Queries["queries/"]:::internal
            DBUtils["utils/"]:::internal
        end
        subgraph "HTTP API Wrappers"
            HTTPAPI["API Wrappers\nsrc/api/index.ts"]:::internal
        end
        subgraph "Shared Utilities & Logger"
            Logger["logger.ts"]:::internal
            CmdSetter["command-setter.ts"]:::internal
            EvSetter["event-setter.ts"]:::internal
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        DiscordGateway["Discord Gateway API"]:::external
        OllamaAPI["Ollama API Service"]:::external
        CassandraDB["Cassandra Database Cluster"]:::external
    end

    %% Infrastructure
    subgraph "Infrastructure & Orchestration"
        direction TB
        DockerCompose["docker-compose.yaml"]:::infra
        DockerfileNode["Dockerfile"]:::infra
        ScriptStart["start.sh"]:::infra
        ScriptBuild["build.sh"]:::infra
        BotContainer["Bot Container"]:::infra
        OllamaContainer["Ollama Container"]:::infra
        CassandraContainer["Cassandra Container"]:::infra
    end

    %% Data Flows
    DiscordGateway -->|connect| Entry
    Entry -->|load config| ConfigLoader
    Entry -->|wire plugins| HandlerUtil
    Entry -->|wire plugins| ListenerUtil
    Entry -->|init LLM| SessionInit
    Entry -->|init DB| DBClient

    DiscordGateway -->|on MESSAGE_CREATE| EventListener
    EventListener -->|"invoke moderation"| CommandHandler
    CommandHandler -->|"classify message"| LLMCore
    LLMCore -->|send request| OllamaAPI
    OllamaAPI -->|classification| LLMCore
    CommandHandler -->|store record| DBIndex
    DBIndex -->|CQL queries| CassandraDB

    DockerCompose --> BotContainer
    DockerCompose --> OllamaContainer
    DockerCompose --> CassandraContainer
    BotContainer -->|runs| Entry
    OllamaContainer -->|provides| OllamaAPI
    CassandraContainer -->|hosts| CassandraDB

    %% Click Events
    click Entry "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/index.ts"
    click CommandHandler "https://github.com/garimatus/anti-hate-discord-app/tree/main/src/commands"
    click HandlerUtil "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/commands/utils/handler.ts"
    click CollecterCMD "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/commands/utils/collecter.ts"
    click Deployer "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/commands/utils/deployer.ts"
    click EventListener "https://github.com/garimatus/anti-hate-discord-app/tree/main/src/events"
    click ListenerUtil "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/events/utils/listener.ts"
    click CollecterEV "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/events/utils/collecter.ts"
    click ConfigLoader "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/configuration/index.ts"
    click I18nCore "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/configuration/i18n/ConfigurableI18n.ts"
    click I18nDefs "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/configuration/i18n/module.d.ts"
    click LocaleEN "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/locales/en.json"
    click LocaleES "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/locales/es.json"
    click LLMCore "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/ollama/index.ts"
    click SessionInit "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/ollama/initialize-ollama-session.ts"
    click PromptDefs "https://github.com/garimatus/anti-hate-discord-app/tree/main/src/ollama/prompts/"
    click DBClient "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/database/client.ts"
    click DBMapper "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/database/mapper.ts"
    click DBIndex "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/database/index.ts"
    click Queries "https://github.com/garimatus/anti-hate-discord-app/tree/main/src/database/queries/"
    click DBUtils "https://github.com/garimatus/anti-hate-discord-app/tree/main/src/database/utils/"
    click HTTPAPI "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/api/index.ts"
    click Logger "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/utils/logger.ts"
    click CmdSetter "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/utils/command-setter.ts"
    click EvSetter "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/utils/event-setter.ts"
    click DockerCompose "https://github.com/garimatus/anti-hate-discord-app/blob/main/docker-compose.yaml"
    click DockerfileNode "https://github.com/garimatus/anti-hate-discord-app/tree/main/Dockerfile"
    click ScriptStart "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/scripts/start.sh"
    click ScriptBuild "https://github.com/garimatus/anti-hate-discord-app/blob/main/src/scripts/build.sh"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef external fill:#A9DFBF,stroke:#1D8348,color:#0B5345
    classDef infra fill:#F5CBA7,stroke:#B9770E,color:#6E2C00
```
