Skip to main content
Annie Mei is a Rust Discord bot that fetches anime and manga data from AniList and theme songs from MyAnimeList and Spotify. Users interact via Discord slash commands. This page focuses on the bot service codebase. For the self-hosted service layout, including the separate AniList OAuth companion service, see Self-hosting architecture.

Technology Stack

Annie Mei uses modern Rust ecosystem tools for building a reliable and performant Discord bot:

Project Layout

The codebase follows a modular structure organized by functionality:

Commands Directory

Each command is organized as a module in src/commands/. Example structure:

Models Directory

Data structures for API responses and database models:

Utils Directory

Shared functionality and external integrations:

Database access

Annie Mei uses SQLx for PostgreSQL queries. The bot shares a database with the auth service, reads from the auth-service-owned oauth_credentials table, and owns settings tables under the annie_mei schema.
The bot previously used Diesel ORM. The current bot uses SQLx migrations at startup for annie_mei.user_settings and annie_mei.guild_settings. OAuth schema migrations still live in the companion auth service repo and run during auth-service startup.

Entry Points

The bot’s execution flow starts in src/main.rs:
  1. Initialization (main.rs)
    • Parse CLI arguments (including a hash subcommand)
    • Install Rustls crypto provider
    • Initialize Sentry error tracking
    • Set up tracing/logging
    • Create SQLx connection pool
    • Run bot-owned SQLx migrations
    • Create Discord client with data (pool, LLM client, OAuth config)
  2. Event Handler (main.rs)
    • interaction_create - Routes slash commands to handlers
    • ready - Registers slash commands with Discord
  3. Command Routing (main.rs)
    • Matches command names to handler functions
    • Configures tracing spans for observability
    • Commands: ping, help, songs, manga, anime, search, recommend, character, register, unregister, whoami, settings

Environment Configuration

The bot requires these environment variables to run: See src/utils/statics.rs for constant definitions.