Skip to content

Configuration

PolitikTok loads its configuration from environment variables at server startup using dotenvy. A .env file in the project root is automatically loaded.

Environment Variables Reference

Application

VariableRequiredDefaultDescription
APP_URLYes--Public URL of the application (e.g., http://localhost:8080)
ENCRYPTION_KEYYes--Key used for encrypting sensitive data at rest
AUTH_SECRETYes--Secret for signing session cookies

Database

VariableRequiredDefaultDescription
DATABASE_URLYes--PostgreSQL connection string (e.g., postgresql://politiktok:politiktok@localhost:5433/politiktok)

The database connection pool is configured with a maximum of 20 connections. Migrations in the ./migrations directory are applied automatically on startup.

LLM (Text Generation)

VariableRequiredDefaultDescription
LLM_BASE_URLYes--Base URL for the OpenAI-compatible API (e.g., http://localhost:11434/v1)
LLM_MODELYes--Model name to use for generation (e.g., llama3.1:8b)
LLM_TIMEOUT_SECSNo120Request timeout in seconds
LLM_MAX_RETRIESNo3Number of retry attempts with exponential backoff

The LLM client uses the /chat/completions endpoint and supports both streaming (SSE) and non-streaming responses. Any OpenAI-compatible API can be used -- Ollama, vLLM, llama.cpp, or a hosted provider.

Embedding

VariableRequiredDefaultDescription
EMBEDDING_BASE_URLYes--Base URL for the embedding API (e.g., http://localhost:11434/v1)
EMBEDDING_MODELYes--Embedding model name (e.g., nomic-embed-text)

The embedding client calls the /embeddings endpoint. Embeddings are used by the RAG pipeline in the Policy Chatbot (F02) and Knowledge Base (F25) modules.

Vector Store (Qdrant)

VariableRequiredDefaultDescription
VECTOR_STORE_URLYes--Qdrant HTTP API URL (e.g., http://localhost:6335)

Collections are created automatically when documents are first ingested. The default vector dimension is 1536 (matching OpenAI-compatible embedding models), but it adapts to the actual embedding size returned by the model.

Keycloak (Authentication)

VariableRequiredDefaultDescription
KEYCLOAK_URLYes--Keycloak server URL (e.g., http://localhost:8081)
KEYCLOAK_REALMYes--Realm name (e.g., politiktok)
KEYCLOAK_CLIENT_IDYes--OIDC client ID (e.g., politiktok-app)
KEYCLOAK_CLIENT_SECRETNo""Client secret (empty for public clients using PKCE)
VariableRequiredDefaultDescription
SEARXNG_URLNo--SearXNG instance URL for web search features

External APIs (Optional)

VariableRequiredDefaultDescription
MASTODON_INSTANCE_URLNo--Mastodon instance for social media monitoring
MASTODON_ACCESS_TOKENNo--Mastodon API token
REDDIT_CLIENT_IDNo--Reddit API client ID
REDDIT_CLIENT_SECRETNo--Reddit API client secret

Example .env File

bash
# Database
DATABASE_URL=postgresql://politiktok:politiktok@localhost:5433/politiktok

# LLM Configuration
LLM_BASE_URL=http://localhost:11434/v1
LLM_MODEL=llama3.1:8b
LLM_TIMEOUT_SECS=120
LLM_MAX_RETRIES=3

# Embedding
EMBEDDING_BASE_URL=http://localhost:11434/v1
EMBEDDING_MODEL=nomic-embed-text

# Vector Store (Qdrant)
VECTOR_STORE_URL=http://localhost:6335

# Keycloak
KEYCLOAK_URL=http://localhost:8081
KEYCLOAK_REALM=politiktok
KEYCLOAK_CLIENT_ID=politiktok-app
KEYCLOAK_CLIENT_SECRET=

# Application
APP_URL=http://localhost:8080
ENCRYPTION_KEY=changeme-generate-a-real-key
AUTH_SECRET=changeme-generate-a-real-secret

# SearXNG
SEARXNG_URL=http://localhost:8889

Configuration Loading

Configuration is loaded in src/infrastructure/config.rs through five config structs:

  • AppConfig -- application URL and secrets
  • KeycloakConfig -- OIDC endpoints and client credentials
  • LlmConfig -- text generation settings
  • EmbeddingConfig -- embedding API settings
  • VectorStoreConfig -- Qdrant connection

Each struct is loaded from environment variables at startup and leaked into 'static references for zero-cost access throughout the application lifetime. Missing required variables cause the server to exit immediately with a descriptive error message.

Security Notes

  • Never commit .env to version control. The .gitignore should exclude it.
  • Use strong, randomly generated values for ENCRYPTION_KEY and AUTH_SECRET in production.
  • When using Keycloak with a public client (PKCE flow), KEYCLOAK_CLIENT_SECRET can remain empty.
  • The DATABASE_URL contains credentials -- treat it as a secret.