# Configuration Reference ## Document Purpose This document provides a comprehensive reference for all configuration options in the Aniworld application. --- ## 1. Configuration Overview ### Configuration Sources Aniworld uses a layered configuration system with **explicit precedence rules**: 1. **Environment Variables** (highest priority) - Takes precedence over all other sources 2. **`.env` file** in project root - Loaded as environment variables 3. **`data/config.json`** file - Persistent file-based configuration 4. **Default values** (lowest priority) - Built-in fallback values ### Precedence Rules **Critical Principle**: `ENV VARS > config.json > defaults` - **Environment variables always win**: If a value is set via environment variable, it will NOT be overridden by config.json - **config.json as fallback**: If an ENV var is not set (or is empty/default), the value from config.json is used - **Defaults as last resort**: Built-in default values are used only if neither ENV var nor config.json provide a value ### Loading Mechanism Configuration is loaded at application startup in `src/server/fastapi_app.py`: 1. **Pydantic Settings** loads ENV vars and .env file with defaults 2. **config.json** is loaded via `ConfigService` 3. **Selective sync**: config.json values sync to settings **only if** ENV var not set 4. **Runtime access**: Code uses `settings` object (which has final merged values) **Example**: ```bash # If ENV var is set: ANIME_DIRECTORY=/env/path # This takes precedence # config.json has: {"other": {"anime_directory": "/config/path"}} # This is ignored # Result: settings.anime_directory = "/env/path" ``` **Source**: [src/config/settings.py](../src/config/settings.py#L1-L96), [src/server/fastapi_app.py](../src/server/fastapi_app.py#L139-L185) --- ## 2. Environment Variables ### Authentication Settings | Variable | Type | Default | Description | | ----------------------- | ------ | ---------------- | ------------------------------------------------------------------- | | `JWT_SECRET_KEY` | string | (random) | Secret key for JWT token signing. Auto-generated if not set. | | `PASSWORD_SALT` | string | `"default-salt"` | Salt for password hashing. | | `MASTER_PASSWORD_HASH` | string | (none) | Pre-hashed master password. Loaded from config.json if not set. | | `MASTER_PASSWORD` | string | (none) | **DEVELOPMENT ONLY** - Plaintext password. Never use in production. | | `SESSION_TIMEOUT_HOURS` | int | `24` | JWT token expiry time in hours. | Source: [src/config/settings.py](../src/config/settings.py#L13-L42) ### Server Settings | Variable | Type | Default | Description | | ----------------- | ------ | -------------------------------- | --------------------------------------------------------------------- | | `ANIME_DIRECTORY` | string | `""` | Path to anime library directory. | | `LOG_LEVEL` | string | `"INFO"` | Logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL. | | `DATABASE_URL` | string | `"sqlite:///./data/aniworld.db"` | Database connection string. | | `CORS_ORIGINS` | string | `"http://localhost:3000"` | Comma-separated allowed CORS origins. Use `*` for localhost defaults. | | `API_RATE_LIMIT` | int | `100` | Maximum API requests per minute. | Source: [src/config/settings.py](../src/config/settings.py#L43-L68) ### Provider Settings | Variable | Type | Default | Description | | ------------------ | ------ | --------------- | --------------------------------------------- | | `DEFAULT_PROVIDER` | string | `"aniworld.to"` | Default anime provider. | | `PROVIDER_TIMEOUT` | int | `30` | HTTP timeout for provider requests (seconds). | | `RETRY_ATTEMPTS` | int | `3` | Number of retry attempts for failed requests. | Source: [src/config/settings.py](../src/config/settings.py#L69-L79) ### NFO Settings | Variable | Type | Default | Description | | --------------------- | ------ | -------- | -------------------------------------------------- | | `TMDB_API_KEY` | string | `""` | The Movie Database (TMDB) API key for metadata. | | `NFO_AUTO_CREATE` | bool | `true` | Automatically create NFO files during downloads. | | `NFO_UPDATE_ON_SCAN` | bool | `false` | Update existing NFO files when scanning library. | | `NFO_DOWNLOAD_POSTER` | bool | `true` | Download poster images along with NFO files. | | `NFO_DOWNLOAD_LOGO` | bool | `false` | Download logo images along with NFO files. | | `NFO_DOWNLOAD_FANART` | bool | `false` | Download fanart images along with NFO files. | | `NFO_IMAGE_SIZE` | string | `"w500"` | Image size for TMDB images (w500, w780, original). | Source: [src/server/models/config.py](../src/server/models/config.py#L109-L132) --- ## 3. Configuration File (config.json) Location: `data/config.json` ### File Structure ```json { "name": "Aniworld", "data_dir": "data", "scheduler": { "enabled": true, "interval_minutes": 60, "schedule_time": "03:00", "schedule_days": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], "auto_download_after_rescan": false, "folder_scan_enabled": false }, "logging": { "level": "INFO", "file": null, "max_bytes": null, "backup_count": 3 }, "backup": { "enabled": false, "path": "data/backups", "keep_days": 30 }, "nfo": { "tmdb_api_key": "", "auto_create": true, "update_on_scan": false, "download_poster": true, "download_logo": false, "download_fanart": false, "image_size": "w500" }, "other": { "master_password_hash": "$pbkdf2-sha256$...", "anime_directory": "/path/to/anime" }, "version": "1.0.1" } ``` Source: [data/config.json](../data/config.json) --- ## 4. Configuration Sections ### 4.1 General Settings | Field | Type | Default | Description | | ---------- | ------ | ------------ | ------------------------------ | | `name` | string | `"Aniworld"` | Application name. | | `data_dir` | string | `"data"` | Base directory for data files. | Source: [src/server/models/config.py](../src/server/models/config.py#L62-L66) ### 4.2 Scheduler Settings Controls automatic cron-based library rescanning (powered by APScheduler). | Field | Type | Default | Description | | -------------------------------------- | ------------ | --------------------------------------------- | -------------------------------------------------------------------- | | `scheduler.enabled` | bool | `true` | Enable/disable automatic scans. | | `scheduler.interval_minutes` | int | `60` | Legacy field kept for backward compatibility. Minimum: 1. | | `scheduler.schedule_time` | string | `"03:00"` | Daily run time in 24-h `HH:MM` format. | | `scheduler.schedule_days` | list[string] | `["mon","tue","wed","thu","fri","sat","sun"]` | Days of the week to run the scan. Empty list disables the cron job. | | `scheduler.auto_download_after_rescan` | bool | `false` | Automatically queue missing episodes for download after each rescan. | | `scheduler.folder_scan_enabled` | bool | `false` | Run folder maintenance (NFO repair, folder renaming, poster checks) during scheduled runs. **When enabled, series folders are automatically renamed to match the `