# caiocs97/dolinho-bot architecture

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

- Interactive diagram: https://gitdiagram.com/caiocs97/dolinho-bot
- Repository: https://github.com/caiocs97/dolinho-bot

## Overview

##### Project type and purpose
- This is an Nx-powered monorepo whose primary “app” is a Discord bot (apps/bot).
- The bot leverages several in-house libraries (under libs/) for database access (Prisma), command‐slashing logic, TradingView integration, payment remessa‐online integration, and shared utilities.
- Purpose: respond to Discord events, execute slash commands, interact with external services (TradingView, Remessa Online), and persist data via Prisma.

##### File structure
Top level
- apps/bot – the Discord bot service
– src/instances: singletons for Discord client, API wrappers, Prisma client, slasher
– src/events: event handlers for guild, channel, member, message events
– src/commands: modules for exchanges simulation and trading‐view symbol management
- libs/
– database: Prisma schema, migrations, TS library exposing a repo layer
– slash: common slash‐command registration and handling utilities
– tradig-view: wrappers for TradingView API
– remessa-online: wrappers for Remessa Online payment API
– utils: shared helpers (e.g., Discord embed builders, logging)
- config files: Nx workspace (nx.json, tsconfig.base.json), Jest, ESLint, Prettier

##### README
- Boilerplate Nx README; confirms a multi‐project workspace.
- No further architecture docs, so we infer structure is event‐driven, modular.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "External Services"
    direction TB
    Discord["Discord Gateway & REST API"]:::external
    TradingViewAPI["TradingView API"]:::external
    RemessaAPI["Remessa Online API"]:::external
  end

  subgraph "Data Store"
    direction TB
    Postgres[(PostgreSQL)]:::db
  end

  subgraph "DolinhoBot Service"
    direction TB
    main["Main Entry Point\napps/bot/src/main.ts"]:::internal

    subgraph Instances
      direction TB
      client["DiscordClient Instance"]:::internal
      apiWrapper["API Wrapper Instances\n(TradingViewClient, RemessaOnlineClient)"]:::internal
      prismaClient["Prisma Database Client"]:::internal
      slasher["Slash Command Registration\n(Slasher)"]:::internal
    end

    subgraph EventProcessor
      direction TB
      e1["channel-delete\napps/bot/src/events/channel-delete.ts"]:::internal
      e2["guild-available\napps/bot/src/events/guild-available.ts"]:::internal
      e3["guild-create\napps/bot/src/events/guild-create.ts"]:::internal
      e4["guild-delete\napps/bot/src/events/guild-delete.ts"]:::internal
      e5["guild-member-add\napps/bot/src/events/guild-member-add.ts"]:::internal
      e6["welcome-message\napps/bot/src/events/messages/welcome-message.ts"]:::internal
    end

    subgraph CommandProcessor
      direction TB
      c1["simulate\napps/bot/src/commands/exchanges/simulate.ts"]:::internal
      c2["add-symbol\napps/bot/src/commands/trading-view/add-symbol.ts"]:::internal
      c3["view-symbol\napps/bot/src/commands/trading-view/view-symbol.ts"]:::internal
    end

    subgraph Libraries
      direction TB
      libDb["libs/database"]:::internal
      libSlash["libs/slash"]:::internal
      libTV["libs/tradig-view"]:::internal
      libRemessa["libs/remessa-online"]:::internal
      libUtils["libs/utils"]:::internal
    end
  end

  %% Interactions
  Discord -->|"slash command payload"| client
  client -->|"emit event"| EventProcessor
  EventProcessor -->|"use slasher"| slasher
  slasher -->|"invoke command"| CommandProcessor
  CommandProcessor -->|"query/update"| prismaClient
  prismaClient -->|"SQL query"| Postgres
  CommandProcessor -->|"call API"| apiWrapper
  apiWrapper --> TradingViewAPI
  apiWrapper --> RemessaAPI
  CommandProcessor -->|"format/log"| libUtils
  CommandProcessor -->|"db module"| libDb
  slasher --> libSlash
  apiWrapper --> libTV
  apiWrapper --> libRemessa
  client -->|"send response"| Discord

  %% Click Events
  click client "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/instances/client.ts"
  click apiWrapper "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/instances/api.ts"
  click prismaClient "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/instances/prisma.ts"
  click slasher "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/instances/slasher.ts"
  click main "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/main.ts"
  click e1 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/events/channel-delete.ts"
  click e2 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/events/guild-available.ts"
  click e3 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/events/guild-create.ts"
  click e4 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/events/guild-delete.ts"
  click e5 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/events/guild-member-add.ts"
  click e6 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/events/messages/welcome-message.ts"
  click c1 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/commands/exchanges/simulate.ts"
  click c2 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/commands/trading-view/add-symbol.ts"
  click c3 "https://github.com/caiocs97/dolinho-bot/blob/main/apps/bot/src/commands/trading-view/view-symbol.ts"
  click libDb "https://github.com/caiocs97/dolinho-bot/tree/main/libs/database"
  click libSlash "https://github.com/caiocs97/dolinho-bot/blob/main/libs/slash/src/index.ts"
  click libTV "https://github.com/caiocs97/dolinho-bot/blob/main/libs/tradig-view/src/index.ts"
  click libRemessa "https://github.com/caiocs97/dolinho-bot/blob/main/libs/remessa-online/src/index.ts"
  click libUtils "https://github.com/caiocs97/dolinho-bot/blob/main/libs/utils/src/index.ts"

  %% Styles
  classDef external fill:#FFD580,stroke:#333,stroke-width:2px
  classDef db fill:#FFB3B3,stroke:#333,stroke-width:2px
  classDef internal fill:#B3E6B3,stroke:#333,stroke-width:2px
```
