Skip to content

Architecture

Arborescence du projet

igb-bot/
  prisma/
    schema.prisma              # Schema de la base de donnees
    migrations/                # Migrations Prisma
  src/
    app/
      bootstrap.ts             # Point d'entree principal
      register-commands.ts     # Chargement et deploiement des commandes
    config/
      constants.ts             # Constantes (XP, CRON schedules, etc.)
      env.ts                   # Validation des variables d'environnement (Zod)
      logger.ts                # Configuration Pino
    core/
      client.ts                # Instance du client Discord (BotClient)
      intents.ts               # Intents Discord
      permissions.ts           # isOwner, isAdmin, isModerator
    infrastructure/
      discord/
        notifier.ts            # notifyAdminChannel, notifyModerationChannel
      http/
        health-server.ts       # Serveur HTTP /health
      scheduler/
        cron.ts                # registerCron wrapper
    shared/
      db/
        prisma.ts              # Instance Prisma singleton
      errors/
        AppError.ts            # Classe d'erreur personnalisee
      services/
        audit-log.service.ts   # AuditLog DB
        system-log.service.ts  # SystemLog DB
      types/
        command.ts             # Interface SlashCommand
    modules/
      admin/                   # Setup (init, view, channels, level-roles)
      birthdays/               # Anniversaires
      chat/                    # IA Nekobot (Groq)
      clips/                   # Clips gaming
      countdown/               # Countdowns
      events/                  # Soiree du jeudi
      fun/                     # Coinflip, roll, poll, bet, bug
      gamification/            # XP, rank, leaderboard
      health/                  # Health check command
      help/                    # Guide des commandes
      maintenance/             # Cache purge
      moderation/              # Warn, kick, ban, modhistory
      riot/                    # Riot Games TFT
      stats-channels/          # Salons statistiques
      suggestions/             # Suggestions
      updater/                 # Admin commands, update checker
      valorant/                # Valorant stats (HenrikDev)
  tests/
    setup.ts                   # Mocks globaux
    unit/                      # Tests unitaires par module
  docs/                        # Documentation VitePress
  .github/
    workflows/
      ci.yml                   # CI (typecheck + test + build)
      release.yml              # Release sur tag
      docs.yml                 # Deploy docs GitHub Pages
    dependabot.yml             # Dependabot config
  ecosystem.config.cjs         # pm2 configuration
  docker-compose.yml           # PostgreSQL + Adminer
  vitest.config.ts             # Configuration tests

Flux de donnees

Commande slash

Utilisateur
  -> Discord API (gateway)
    -> interactionCreate (bootstrap.ts)
      -> Cooldown check (5s par user)
        -> command.execute(interaction, client)
          -> service.method()
            -> repository.query()
              -> Prisma -> PostgreSQL
          -> interaction.reply() / editReply()
      -> En cas d'erreur :
        -> interaction.followUp() avec message generique
        -> notifyAdminChannel()

Event handler

Evenement Discord (message, voice, etc.)
  -> client.on('event')
    -> Filtres (guild, bot)
      -> Logique du handler
        -> service.method() si besoin
      -> En cas d'erreur :
        -> log.error()
        -> notifyAdminChannel()

Cron job

node-cron (schedule)
  -> registerCron wrapper
    -> log.info('Job started')
    -> job.fn()
      -> service/repository/API calls
    -> log.info('Job completed', durationMs)
    -> En cas d'erreur :
      -> log.error()
      -> notifyAdminChannel()

Relations Prisma

GuildConfig (1 par serveur)

UserProfile (1 par utilisateur)
  ├── Birthday (1:1)
  ├── UserXp (1:1)
  ├── VoiceSession (1:N)
  ├── MessageStatDaily (1:N)
  ├── WeeklyEventResponse (1:N)
  ├── ModerationAction as target (1:N)
  ├── ModerationAction as moderator (1:N)
  ├── GameAccountLink (1:N)
  │     └── GamePerformanceSnapshot (1:N)
  └── AuditLog (1:N)

ValorantProfile (1 par utilisateur)
  └── ValorantTrackerCache (1:1 via unique composite)

Countdown (standalone, lie a guildId)
SystemLog (standalone)

Toutes les relations avec UserProfile utilisent onDelete: Cascade sauf ModerationAction (pas de cascade pour preserver l'historique).