diff --git a/config/README.md b/config/README.md index b6942f3..8101e17 100644 --- a/config/README.md +++ b/config/README.md @@ -4,24 +4,23 @@ This directory contains the unified configuration system for the RxMinder applic ## Overview -The unified configuration system replaces the previous scattered approach of multiple `.env` files and environment-specific configurations with a centralized, type-safe, and environment-aware system. +The unified configuration system serves as the **single source of truth** for all application configuration. It reads from your `.env` file for environment-specific overrides and provides a centralized, type-safe, and environment-aware configuration system. ### Key Benefits -- 🎯 **Single Source of Truth**: All configuration in one place +- 🎯 **Single Source of Truth**: Unified config with `.env` file overrides - 🔒 **Type Safety**: Full TypeScript support with interfaces -- 🌍 **Environment Aware**: Automatic environment-specific overrides +- 🌍 **Environment Aware**: Reads from `.env` file for environment-specific settings - 🚀 **Auto-Generation**: Generates all necessary config files automatically -- 🔄 **Easy Migration**: Smooth transition from old config system -- 📝 **Self-Documenting**: Clear structure with validation +- 🔄 **Simplified Architecture**: Clean, maintainable configuration management +- 📝 **Self-Documenting**: Clear structure with validation and debugging tools ## File Structure ``` config/ ├── README.md # This documentation -├── unified.config.ts # Main unified configuration -├── app.config.ts # Legacy config (deprecated) +├── unified.config.ts # Single source of truth configuration └── generated/ # Auto-generated configs ├── development.config.ts ├── staging.config.ts @@ -49,20 +48,21 @@ if (featureFlags.enableOAuth) { } ``` -### 2. Environment Variables +### 2. Environment Variables (.env file) -The system reads from environment variables with fallbacks to sensible defaults: +The system reads from your `.env` file as the primary source for environment-specific overrides: ```bash -# Required variables -APP_NAME=RxMinder +# .env file - Primary configuration source +APP_NAME=rxminder NODE_ENV=production -VITE_COUCHDB_URL=http://couchdb:5984 +VITE_COUCHDB_URL=http://rxminder-couchdb-service:5984 +VITE_COUCHDB_USER=admin +VITE_COUCHDB_PASSWORD=your-secure-password -# Optional variables with defaults -APP_VERSION=1.0.0 -DEBUG_MODE=false -ENABLE_OAUTH=true +# Container configuration +CONTAINER_REGISTRY=your-registry.com +CONTAINER_REPOSITORY=your-org/app ``` ### 3. Generating Config Files @@ -278,23 +278,29 @@ bun scripts/generate-unified-config.ts production bun scripts/generate-unified-config.ts --dry-run ``` -## Migration from Old System +## Working with the Configuration System -If you're migrating from the old configuration system: +### 1. Basic Usage -### 1. Backup Current Configuration +Access configuration in your application: -```bash -bun scripts/generate-unified-config.ts production +```typescript +import { unifiedConfig } from './config/unified.config'; + +const appName = unifiedConfig.app.name; +const dbUrl = unifiedConfig.database.url; ``` -### 2. Run Migration +### 2. Environment Overrides + +Add variables to your `.env` file: ```bash -bun scripts/generate-unified-config.ts --all +APP_NAME=my-app +VITE_COUCHDB_URL=http://localhost:5984 ``` -### 3. Generate New Config Files +### 3. Generate Configs ```bash make generate-config @@ -402,10 +408,21 @@ make deploy-prod-quick For questions or issues with the unified configuration system: 1. Check this documentation first -2. Run diagnostic commands (`make config-debug`, `make validate-config`) +2. Run diagnostic commands: + - `make config-check` - Health check of entire config system + - `make config-debug` - Show current configuration values 3. Review generated configuration files -4. Check application logs for configuration-related errors +4. Check `.env` file for environment-specific overrides +5. Check application logs for configuration-related errors + +## Configuration Priority + +The unified config uses this priority order: + +1. **`.env` file** (highest priority) - Environment-specific overrides +2. **Environment configs** (medium priority) - Built-in environment defaults +3. **Default values** (lowest priority) - Fallback defaults in unified.config.ts --- -_This unified configuration system provides a robust, scalable, and maintainable approach to application configuration management._ +_The unified configuration system provides a robust, scalable, and maintainable approach to application configuration management with `.env` file integration._ diff --git a/docs/ARCHITECTURE_MIGRATION.md b/docs/ARCHITECTURE_MIGRATION.md index ee944d8..1570595 100644 --- a/docs/ARCHITECTURE_MIGRATION.md +++ b/docs/ARCHITECTURE_MIGRATION.md @@ -67,14 +67,14 @@ const dbUrl = process.env.VITE_COUCHDB_URL || 'http://localhost:5984'; #### New Pattern (Recommended) ```typescript -import { appConfig, CONFIG } from '../config/app.config'; +import { unifiedConfig } from '../config/unified.config'; // Type-safe, validated configuration -const baseUrl = appConfig.baseUrl; -const dbUrl = appConfig.database.url; +const baseUrl = unifiedConfig.app.baseUrl; +const dbUrl = unifiedConfig.database.url; -// Or use constants for common values -const isProduction = CONFIG.IS_PRODUCTION; +// Or use convenience exports +const isProduction = unifiedConfig.app.environment === 'production'; ``` ### Logging Migration @@ -117,7 +117,7 @@ services/ │ └── Logger.ts # Logger implementation config/ # ✅ Centralized configuration -└── app.config.ts # Main configuration with validation +└── unified.config.ts # Main configuration with validation ``` ## 🎯 Benefits Achieved diff --git a/docs/implementation/IMPLEMENTATION_SUMMARY.md b/docs/implementation/IMPLEMENTATION_SUMMARY.md index edfa05a..cc2c9e1 100644 --- a/docs/implementation/IMPLEMENTATION_SUMMARY.md +++ b/docs/implementation/IMPLEMENTATION_SUMMARY.md @@ -33,7 +33,7 @@ This report summarizes the major architectural improvements implemented to addre #### Files Created -- `config/app.config.ts` - Centralized configuration with validation +- `config/unified.config.ts` - Centralized configuration with validation #### Key Improvements