> ## Documentation Index
> Fetch the complete documentation index at: https://anniemei.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Configure Annie Mei for production deployment

## Overview

Annie Mei requires configuration through environment variables for Discord integration, database access, caching, external APIs, and monitoring. This guide covers the essential configuration steps for deploying the bot to production.

If you want full self-hosted feature parity, deploy the auth service alongside the bot service. Use [Self-hosting architecture](/self-hosting/architecture) and [Auth service](/self-hosting/auth-service) before you finalize production config.

## Prerequisites

Before configuring Annie Mei, ensure you have:

* A Discord bot token from the [Discord Developer Portal](https://discord.com/developers/applications)
* PostgreSQL database
* Redis cache
* Spotify API credentials
* MyAnimeList API credentials
* Sentry account for error tracking

## Configuration Methods

### Environment Variables

Annie Mei reads all configuration from environment variables. You can set them:

1. **Locally**: Using a `.env` file (not committed to git)
2. **Production**: Using your preferred secrets workflow or manager
3. **CI/CD**: Using GitHub Actions secrets

### Example: using Doppler

If you already use Doppler, this is one way to inject secrets:

```bash theme={}
# Install Doppler CLI
curl -Ls https://cli.doppler.com/install.sh | sh

# Login and setup
doppler login
doppler setup

# Run the bot with Doppler
doppler run -- ./annie-mei
```

## Required Configuration

See the [Environment Variables](/deployment/environment-variables) page for a complete list of all required and optional environment variables.

## Environment-Specific Settings

### Development

```bash theme={}
ENV=development
SENTRY_TRACES_SAMPLE_RATE=0.0  # Disable tracing in dev
RUST_LOG=debug,serenity=warn   # Verbose logging
```

### Production

```bash theme={}
ENV=production
SENTRY_TRACES_SAMPLE_RATE=0.1  # 10% trace sampling
RUST_LOG=info,serenity=warn    # Standard logging
```

## Discord Configuration

### Creating a Discord Bot

1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
2. Click "New Application" and name it "Annie Mei"
3. Navigate to the "Bot" section
4. Click "Add Bot"
5. Under "Token", click "Reset Token" and copy the value
6. Set as `DISCORD_TOKEN` environment variable

### Required Intents

Annie Mei requires these Gateway Intents (configured in the Discord Developer Portal):

* Guild Messages
* Direct Messages
* Guild Presences
* Guilds

### Inviting the Bot

Generate an invite URL with these scopes and permissions:

* **Scopes**: `bot`, `applications.commands`
* **Permissions**: `Send Messages`, `Embed Links`, `Use Slash Commands`

## API Configuration

### Spotify API

1. Go to [Spotify for Developers](https://developer.spotify.com/dashboard)
2. Create a new app
3. Copy the Client ID and Client Secret
4. Set `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET`

### MyAnimeList API

1. Go to [MyAnimeList API](https://myanimelist.net/apiconfig)
2. Create a new API client
3. Copy the Client ID
4. Set `MAL_CLIENT_ID`

## Database Setup

See [Infrastructure](/deployment/infrastructure) for detailed PostgreSQL setup instructions.

Once your database is provisioned, set the `DATABASE_URL`:

```bash theme={}
DATABASE_URL=postgres://user:password@host:5432/database?sslmode=require
```

### Running Migrations

The bot expects the database schema to already be in place. The auth service owns and runs the OAuth schema migrations on startup. Use the auth service repo's SQLx migrations when setting up or modifying the shared OAuth schema.

## Cache Setup

See [Infrastructure](/deployment/infrastructure) for detailed Redis setup instructions.

Set the `REDIS_URL` with your Redis connection string:

```bash theme={}
REDIS_URL=redis://default:password@host:port
```

For Redis with TLS:

```bash theme={}
REDIS_URL=rediss://default:password@host:port
```

## Monitoring & Error Tracking

### Sentry Configuration

1. Create a project in [Sentry](https://sentry.io)
2. Copy the DSN from project settings
3. Set `SENTRY_DSN` environment variable
4. Configure trace sampling with `SENTRY_TRACES_SAMPLE_RATE` (0.0 to 1.0)

### Privacy Settings

Annie Mei implements privacy-focused monitoring:

* User IDs are hashed using `USERID_HASH_SALT` before sending to Sentry
* Database credentials in URLs are automatically redacted from error logs
* See `src/main.rs:146` for URL credential redaction logic

### Hash Lookup Utility

To look up a user's hashed ID in Sentry logs:

```bash theme={}
./annie-mei hash <discord_user_id>
```

## Server Configuration

### HTTP Health and Readiness

The Discord bot does not expose an HTTP listener. Operational health checks should target the auth service instead:

* `GET /healthz` - process liveness, no dependency checks
* `GET /readyz` - readiness, including PostgreSQL connectivity

**Response (ready)**:

```json theme={}
{
  "status": "healthy",
  "version": "1.2.0",
  "services": {
    "database": "up"
  }
}
```

**HTTP Status Codes**:

* `200 OK` - The auth service is live or ready, depending on endpoint
* `503 Service Unavailable` - The readiness dependency check failed

Use these endpoints for load balancer checks, monitoring, alerting, and deployment verification.

Defined in: `auth/src/routes/healthz.rs`

## Validation

Before deploying, validate your configuration:

```bash theme={}
# Start the bot with your production-style environment
RUST_LOG=debug ./annie-mei

# Check auth service liveness/readiness after startup
curl http://127.0.0.1:8000/healthz
curl http://127.0.0.1:8000/readyz

# Verify the hash helper still works
./annie-mei hash 123456789012345678
```

## Next Steps

* Review [Environment Variables](/deployment/environment-variables) for complete reference
* Set up [Infrastructure](/deployment/infrastructure) for production deployment
* Configure monitoring and alerts in Sentry
