Skip to content

Configuration

All application configuration is managed through the central getConfig() function in src/lib/core/config.ts. Environment variables are the default source, but the abstraction supports swapping to database-backed configuration.

Rule: Never read process.env directly in application code. Always use getConfig().

Environment Variables Reference

Required

VariableDescriptionDefault
JWT_SECRETSecret for JWT signing (min 32 chars)

Database

VariableDescriptionDefault
DB_PROVIDERDatabase backend: sqlite or mongodbsqlite
SQLITE_DATA_DIRData directory for SQLite files./data
MONGODB_URIMongoDB connection string (required when DB_PROVIDER=mongodb)
MAIN_DB_NAMEMain database nameconsole_main
MONGODB_MIN_POOL_SIZEMin connection pool size2
MONGODB_MAX_POOL_SIZEMax connection pool size10
MONGODB_CONNECT_TIMEOUT_MSConnection timeout10000
MONGODB_SOCKET_TIMEOUT_MSSocket timeout45000
MONGODB_SERVER_SELECTION_TIMEOUT_MSServer selection timeout30000

Authentication

VariableDescriptionDefault
JWT_EXPIRES_INJWT token expiry7d
PROVIDER_ENCRYPTION_SECRETEncryption key for provider credentialsFalls back to JWT_SECRET

Gateway (Resilience)

VariableDescriptionDefault
GATEWAY_REQUEST_TIMEOUT_MSRequest timeout for provider calls120000
GATEWAY_RETRY_ENABLEDEnable automatic retriestrue
GATEWAY_RETRY_MAX_ATTEMPTSMaximum retry attempts3
GATEWAY_RETRY_INITIAL_DELAY_MSInitial retry delay (exponential)200
GATEWAY_CIRCUIT_BREAKER_ENABLEDEnable circuit breakertrue
GATEWAY_CIRCUIT_BREAKER_THRESHOLDFailures before opening circuit5
GATEWAY_CIRCUIT_BREAKER_RESET_MSTime before half-open test30000

Cache

VariableDescriptionDefault
CACHE_PROVIDERCache backend: none, memory, redismemory
CACHE_TTL_SECONDSDefault cache TTL300
REDIS_URLRedis connection URL (required when provider=redis)
REDIS_KEY_PREFIXKey prefix for Redis cacheconsole:

Rate Limiting

VariableDescriptionDefault
RATE_LIMIT_PROVIDERProvider: mongodb, memory, redismongodb
RATE_LIMIT_SYNC_INTERVAL_MSSync interval for distributed counters5000

Logging

VariableDescriptionDefault
LOG_LEVELLog level: error, warn, info, debugdebug (dev) / info (prod)
LOG_FORMATOutput format: json, prettypretty (dev) / json (prod)
LOG_REQUEST_BODYLog request bodiesfalse
LOG_RESPONSE_BODYLog response bodiesfalse

CORS

VariableDescriptionDefault
CORS_ENABLEDEnable CORS for client APIfalse
CORS_ALLOWED_ORIGINSComma-separated allowed origins
CORS_MAX_AGEPreflight cache duration (seconds)86400

SMTP (Email)

VariableDescriptionDefault
SMTP_HOSTSMTP server hostsmtp.gmail.com
SMTP_PORTSMTP server port587
SMTP_SECUREUse TLSfalse
SMTP_USERSMTP username
SMTP_PASSSMTP password
SMTP_FROMFrom addressFalls back to SMTP_USER

Application

VariableDescriptionDefault
NEXT_PUBLIC_APP_URLPublic application URLhttp://localhost:3000
SHUTDOWN_TIMEOUT_MSGraceful shutdown timeout15000
TRACING_MAX_BODY_SIZE_MBMax tracing payload size10
HEALTH_ENDPOINT_ENABLEDEnable health endpointstrue
PROVIDER_RUNTIME_CACHE_TTL_SECONDSRuntime pool entry TTL300

Config Source Abstraction

The config module uses a ConfigSource interface, making it easy to swap between ENV-based and database-backed configuration:

typescript
interface ConfigSource {
  readonly name: string;
  get(key: string): string | undefined;
}

The default EnvConfigSource reads from process.env. You can replace it:

typescript
import { setConfigSource } from '@/lib/core/config';

setConfigSource(myDatabaseConfigSource);

Validation

At startup, critical configuration is validated:

typescript
const cfg = getConfig();
const errors = validateConfig(cfg);
// Checks: MONGODB_URI required, JWT_SECRET required,
// REDIS_URL required when CACHE_PROVIDER=redis, etc.

Validation errors are logged but do not crash the server — this allows K8s secrets to be injected after initial startup.

Example .env.local

SQLite mode (default, zero dependencies)

bash
# Required
JWT_SECRET=your-secret-key-must-be-at-least-32-chars

# Database (SQLite is the default — no MongoDB needed)
# DB_PROVIDER=sqlite
# SQLITE_DATA_DIR=./data

# Cache
CACHE_PROVIDER=memory

# Logging
LOG_LEVEL=debug
LOG_FORMAT=pretty

# CORS (for client SDKs)
CORS_ENABLED=true
CORS_ALLOWED_ORIGINS=http://localhost:3001,http://localhost:5173

MongoDB mode

bash
# Required
JWT_SECRET=your-secret-key-must-be-at-least-32-chars

# Database
DB_PROVIDER=mongodb
MONGODB_URI=mongodb://localhost:27017

# Cache
CACHE_PROVIDER=memory
# REDIS_URL=redis://localhost:6379

# Logging
LOG_LEVEL=debug
LOG_FORMAT=pretty

# CORS (for client SDKs)
CORS_ENABLED=true
CORS_ALLOWED_ORIGINS=http://localhost:3001,http://localhost:5173

# SMTP (optional)
# SMTP_HOST=smtp.gmail.com
# SMTP_USER=your@email.com
# SMTP_PASS=your-app-password

Community edition is AGPL-3.0. Commercial licensing and support are available separately.