Configuration Management
Relevant source files
The following files were used as context for generating this wiki page:
Configuration Management in TrackerBot is a centralized system designed to validate environment variables, derive application-wide constants, and ensure that both the Discord bot and the web server have the necessary credentials and identifiers to operate. The system relies on .env files for local development and direct environment variables in production, managed primarily through the src/config/ directory.
The architecture emphasizes "failing fast" by validating required variables at boot time before services like the Discord client or Express server are initialized. This prevents runtime errors related to missing configurations, such as authentication failures or undefined channel references.
Sources: AGENTS.md:21-25, bot.js:1-10, README.md:38-50
Environment Validation Logic
The project uses a two-tier validation approach. Essential variables for the Discord bot are validated in src/config/env.js, while variables specific to the GitHub issue intake portal are validated within webserver.js.
Validation Workflow
The validation process is triggered immediately upon execution of the entry point files. In bot.js, the ensureEnvVars() function is called before the Discord client is created. This function iterates through a predefined list of required keys and throws an error if any are missing or empty.
The diagram shows the parallel validation paths for the two primary services.
Sources: bot.js:10, webserver.js:19-33, src/config/env.js:11-23
Required Environment Variables
The following variables are mandatory for the application to function:
| Variable | Scope | Description |
|---|---|---|
DISCORD_TOKEN | Bot | Authentication token for the Discord Bot API. |
WELCOME_CHANNEL_ID | Bot | Channel ID where automated welcome messages are sent. |
AUTO_ROLE_ID_1 to _4 | Bot | Role IDs automatically assigned to new members. |
ADMIN_ROLE_ID | Bot | Comma-separated IDs for administrators. |
GITHUB_TOKEN | Web | PAT used to create issues on GitHub. |
REPO_DEV | Web | Repository for website/app bug reports. |
REPO_DATA_REPORT | Web | Repository for data-specific issues. |
Sources: src/config/env.js:1-10, webserver.js:21, README.md:41-50
Derived Constants and Role Management
TrackerBot translates raw environment strings into usable data structures (like Sets and Maps) within src/config/constants.js. This module serves as a translation layer between the environment and the business logic of the bot.
Role Derivation
Permissions are managed by parsing comma-separated strings from the environment into Set objects for O(1) lookup during interaction handling.
- Allowed Command Roles: Determined by
ALLOWED_COMMAND_ROLE_IDS. If unset, it defaults to a hardcoded ID1433391726051197020. - Admin Roles: Determined by
ADMIN_ROLE_ID. These roles grant access to destructive commands like/wipeand/nuke.
The relationship between environment validation and constant derivation.
Sources: src/config/constants.js:1-20, src/config/env.js:1-10
Reaction Role Configuration
The bot uses a static configuration for its reaction-role buttons, mapped to role names that the bot manages in the Discord guild.
| Custom ID | Emoji | Label | Role Name |
|---|---|---|---|
role_site | š | Site | site |
role_monitor | š„ļø | Monitor | monitor |
role_polls | š | Polls | polls |
role_news | š° | News | news |
role_notifs | š | Notifs | notifs |
Sources: src/config/constants.js:26-32
Web Server Configuration
The webserver.js component manages its own configuration for security and routing. This includes rate limiting, CORS-like origin validation, and GitHub API headers.
Security Configurations
- Trust Proxy: The server is configured with
app.set("trust proxy", 1)to correctly identify client IPs behind reverse proxies (e.g., Nginx) for accurate rate limiting. - Origin Allowlist: The
ALLOWED_ORIGINSenvironment variable is parsed into aSet. ThecheckOriginmiddleware performs exact matches or boundary checks (e.g.,origin.startsWith(${o}/)) to prevent suffix attacks. - Field Limits: The server enforces strict length caps on incoming report data (e.g.,
MAX_TITLE: 200,MAX_DESCRIPTION: 8000) to prevent payload injection or buffer issues.
Sources: webserver.js:41-43, webserver.js:56-61, webserver.js:77-94
GitHub Integration
The web server configures a standard header object for all outgoing requests to the GitHub API, ensuring the GITHUB_TOKEN is used securely and masked in logs.
const GITHUB_HEADERS = {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
Accept: "application/vnd.github+json",
"User-Agent": "tarkovtracker-webserver"
};
Sources: webserver.js:46-50, webserver.js:207-211
Testing and Verification
Configuration logic is verified using the Node.js native test runner. Tests in test/env.test.js ensure that the validation logic correctly identifies missing variables and properly retrieves existing ones.
- Cache Busting: Tests use dynamic imports with a timestamp query parameter (e.g.,
import(url + "?t=" + Date.now())) to ensure a fresh state of the configuration modules for every test case. - Validation Checks: Tests confirm that
ensureEnvVars()throws specific errors when mandatory keys likeDISCORD_TOKENare deleted fromprocess.env.
Sources: test/env.test.js:10-13, test/env.test.js:44-53, AGENTS.md:38-40
Summary
TrackerBot's configuration management is a robust system centered on early validation and centralized constant derivation. By separating environment parsing from application logic, the project ensures that deployment issues (like missing role IDs or tokens) are caught at the start of the process, while providing a clean interface for the bot's handlers to check permissions and settings.