This document describes the global configuration system for the TEX Platform, which provides a flexible, provider-based architecture for managing various services and features.
The configuration system uses a single JSON configuration file to manage all application settings. The path to this file can be specified via the TEX_CONFIG_PATH environment variable. By default, it looks for ./config.json in the project root.
- Configuration Types (
types/config.ts) - TypeScript interfaces for all configuration options - Configuration Manager (
config/manager.ts) - Handles loading and validation, of configuration - Service Manager (
config/services.ts) - Manages service lifecycle - Configuration CLI (
scripts/config.ts) - Command-line tool for configuration management; start withbun run config:help
- BunFS - Local filesystem storage using Bun
- S3 - Amazon S3 or S3-compatible storage
- Console - Development email logging to console
- SMTP - Standard SMTP email sending
- PostgreSQL - Primary database
The configuration is organized into several main sections:
{
"app": {
"name": "TEX Platform API",
"version": "1.0.0",
"environment": "development",
"port": 3000
},
"database": { /* Database configuration */ },
"security": { /* Security settings */ },
"monitoring": { /* Logging and monitoring */ },
"providers": {
"filer": { /* File storage provider */ },
"email": { /* Email provider */ },
"auth": { /* Auth provider */ }
},
}The application looks for the TEX_CONFIG_PATH environment variable to determine which JSON configuration file to load. If not set, it defaults to ./config.json.
# Use default config.json in current directory
bun run start
# Use a specific configuration file
export TEX_CONFIG_PATH=./config.production.json
bun run start
# Or inline
TEX_CONFIG_PATH=./config.staging.json bun run startThe specified config file can be intiated with default values using the CLI:
# Initialize default configuration
bun run config:initEdit the JSON file directly to configure all aspects of the application. CLI commands can be used to get/set values without editing the file directly:
# Show current configuration
bun run config show
# Validate configuration
bun run config validate
# Test service connections
bun run config test
# Set configuration values
bun run config set app.port 8080
bun run config set providers.filer.basePath ./new-uploads
# Get configuration values
bun run config get providers.email.type
# Backup and restore
bun run config backup config.backup.json
bun run config restore config.backup.jsonBunFS (Local Filesystem)
{
"type": "bunfs",
"enabled": true,
"basePath": "./uploads",
"maxFileSize": 104857600,
"allowedMimeTypes": ["image/*", "application/pdf"]
}Amazon S3
{
"type": "s3",
"enabled": true,
"accessKeyId": "${AWS_ACCESS_KEY_ID}",
"secretAccessKey": "${AWS_SECRET_ACCESS_KEY}",
"region": "us-east-1",
"bucket": "my-tex-platform-files"
}SMTP
{
"type": "smtp",
"enabled": true,
"host": "smtp.gmail.com",
"port": 587,
"secure": false,
"auth": {
"user": "your-email@gmail.com",
"pass": "your-app-password"
},
"from": "noreply@tex-platform.com"
}Create different configuration files for different environments:
config.json- Default/developmentconfig.production.json- Productionconfig.staging.json- Stagingconfig.test.json- Testing
Load specific configurations by setting the TEX_CONFIG_PATH environment variable:
# Development (default)
bun run dev
# Production
TEX_CONFIG_PATH=./config.production.json bun run start
# Staging
TEX_CONFIG_PATH=./config.staging.json bun run start
# Testing
TEX_CONFIG_PATH=./config.test.json bun run testKeep configuration files out of version control for sensitive deployments. Use .gitignore:
config.production.json
config.*.local.json
You can also use environment variables for sensitive values and reference them in the configuration file using ${ENV_VAR_NAME} syntax.
The system validates configuration on startup. When exporting config using bun run config show, sensitive fields (passwords, secrets, API keys) are redacted by default to prevent accidental exposure. Use --no-sanitize to view full values when needed (keep secure).
The system provides built-in health checking:
# Test all services
bun run config test
# Check health endpoint
curl http://localhost:3000/healthHealth check response:
{
"status": "healthy",
"timestamp": "2025-01-15T10:30:00.000Z",
"services": {
"filer": true,
"email": true,
"auth": true,
"database": true
},
"version": "1.0.0"
}-
Initial Setup:
# Initialize default configuration bun run config:init -
Configure Services (edit
config.json):{ "database": { "host": "localhost", "port": 5432, "database": "tex", "username": "tex_user", "password": "tex_password" }, "providers": { "filer": { "type": "bunfs", "basePath": "./dev-uploads" }, "email": { "type": "mock" } } } -
Validate and Test:
bun run config:validate bun run config:test
-
Start Application:
bun run dev
-
Create Production Configuration:
# Start with example cp config.json config.production.json -
Edit Configuration File:
- Set
app.environmentto"production" - Configure database with production credentials
- Set up email provider
- Configure file storage
- Update security settings (CORS origins, etc.)
- Set
-
Validate Configuration:
TEX_CONFIG_PATH=./config.production.json bun run config:validate
-
Test Service Connections:
TEX_CONFIG_PATH=./config.production.json bun run config:test
-
Deploy:
# Set the configuration path export TEX_CONFIG_PATH=./config.production.json # Start application bun run start
-
Configuration Not Loading:
- Check that the
TEX_CONFIG_PATHenvironment variable is set correctly - Verify JSON syntax in the configuration file
- Check file permissions for the configuration file
- Ensure the file exists at the specified path
- Check that the
-
Service Connection Failures:
# Test all services bun run config:test # Check health endpoint curl http://localhost:3000/health
-
Invalid Configuration:
# Validate configuration bun run config:validate
Export current configuration for debugging:
# Sanitized (safe to share)
bun run config show
# With sensitive data (keep secure)
bun run config show --no-sanitizeAccess services in your application code:
import { getServiceManager } from './config/services';
// Get initialized services
const serviceManager = getServiceManager();
const services = await serviceManager.initialize();
// Use providers
const fileId = await services.filer.uploadFile(file);
await services.email.sendEmail(to, subject, body);
const token = await services.auth.generateAuthToken(userId);This configuration system can be extended to support additional providers as needed.