- Phase 7: Config Consolidation - CONTEXT.md: Defines scope, decisions, and requirements - PLAN.md: 18-task implementation plan with detailed acceptance criteria - Centralize all configs into config/ folder - Update deploy scripts, backend loading, and documentation - Maintain backward compatibility with inventory.env Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
18 KiB
wave, depends_on, files_modified, autonomous
| wave | depends_on | files_modified | autonomous | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 |
|
true |
Phase 7: Config Consolidation - Implementation Plan
Objective: Establish a centralized config/ folder structure, migrate all configurations from root level to config/, and update all scripts and code to use the new structure while maintaining backward compatibility.
Success Criteria:
- Config folder exists with all required configuration files
- All scripts reference config folder instead of root-level env files
- Docker deployment works with new config structure
- Standalone deployment works with new config structure
- Backward compatibility: old inventory.env still loads if needed
- All documentation updated
- Root directory cleaned of unnecessary files
Task 1: Create Config Folder Structure
Read First:
- Current project root layout (understand what we're migrating from)
- Current inventory.env and variants
- PROJECT_ARCHITECTURE.md (reference tech stack and requirements)
Action:
- Create
config/folder in project root:mkdir -p config - Create
config/README.mdwith documentation of all config files and their purposes - Ensure config/ is tracked in git (add to .gitignore if needed, or ensure it's not in .gitignore)
Acceptance Criteria:
config/directory exists in project rootconfig/README.mdexists and documents the purpose of each config fileconfig/appears in git status (is tracked)
Task 2: Create backend.env Configuration File
Read First:
- Current
inventory.envcontent and structure backend/config_loader.pyto understand what variables are expectedbackend/config_manager.pyto understand all used environment variablesbackend/main.pyto see what environment variables are loaded
Action:
- Read existing
inventory.envfile - Extract backend-specific environment variables (database, AI keys, auth settings, JWT secrets)
- Create
config/backend.envwith all backend-specific variables from inventory.env - Include meaningful comments explaining each variable
- Use same values as inventory.env to maintain current functionality
- Ensure format matches python-dotenv expectations
Acceptance Criteria:
config/backend.envexists and contains all backend-specific variables- File format is valid for python-dotenv (KEY=VALUE format with comments)
- Contains at least: JWT_SECRET_KEY, GEMINI_API_KEY, LDAP settings, database config
- All values match original inventory.env
Task 3: Create network.env Configuration File
Read First:
- Current
inventory.envfile run_standalone.shto see what network variables it usesdeploy.shto see what network variables it referencesdocker-compose.ymlto understand port and network configuration
Action:
- Extract network/deployment-specific variables from inventory.env (ports, server IPs, SSL config, CORS settings)
- Create
config/network.envwith these variables - Include meaningful comments for each variable
- Ensure variables match what deploy.sh and run_standalone.sh expect
- Include default values for development
Acceptance Criteria:
config/network.envexists with network-specific variables- Contains at least: BACKEND_PORT, BACKEND_SSL_PORT, FRONTEND_PORT, FRONTEND_SSL_PORT, SERVER_IP, SSL_ENABLED
- All values match original inventory.env
- Format is bash-sourceable (KEY=VALUE)
Task 4: Create docker.env Configuration File
Read First:
- Current
docker-compose.ymlfile inventory.envfile for current values- Dockerfile files (backend/Dockerfile, frontend/Dockerfile)
Action:
- Create
config/docker.envwith variables specifically for docker-compose - Include variables that docker-compose.yml references in its environment sections
- These may overlap with network.env but are docker-compose specific
- Add comments explaining docker-specific context
- Include any build arguments and docker-specific settings
Acceptance Criteria:
config/docker.envexists- Contains Docker-specific environment variables
- Format is valid for docker-compose (KEY=VALUE)
- All required docker-compose.yml variables are present
Task 5: Create frontend.env Configuration File
Read First:
frontend/package.jsonto see if environment variables are usedfrontend/next.config.mjsto understand what env vars are neededfrontend/entrypoint.shto see how frontend loads configuration- Any frontend environment setup in current codebase
Action:
- Create
config/frontend.envwith frontend-specific variables - Include API endpoint configuration, feature flags, service worker settings, etc.
- Add comments explaining each variable's purpose
- If frontend doesn't currently use env files, create minimal defaults for future use
- Ensure Next.js compatible format
Acceptance Criteria:
config/frontend.envexists- Contains frontend-specific variables (API_BASE_URL, feature flags, etc.)
- Format is valid for frontend configuration
- Documented with clear comments
Task 6: Update backend/config_loader.py
Read First:
- Current
backend/config_loader.pyimplementation - Current
backend/config_manager.pyimplementation backend/main.pyto see how config_loader is used- Current load order and fallback logic
Action:
- Update
config_loader.pyto change config loading order:- Priority 1: System environment variables (already set by Docker/deployment)
- Priority 2:
config/backend.env(new centralized location) - Priority 3:
inventory.env(backward compatibility) - Priority 4:
backend/.env(legacy location) - Priority 5: Hardcoded defaults
- Update file paths to look in config/ folder first
- Update log messages to indicate which config file is being loaded
- Ensure backward compatibility: if config/backend.env doesn't exist, fall back to inventory.env
- Test that load_dotenv() calls work correctly with new paths
Acceptance Criteria:
config_loader.pycontains logic to load fromconfig/backend.envfirst- Falls back to
inventory.envifconfig/backend.envnot found - Load order matches: env vars > config/backend.env > inventory.env > backend/.env
- Log messages indicate which config file was loaded
- All environment variables are still accessible to rest of backend
- File contains comment explaining the new config structure
Task 7: Update backend/config_manager.py
Read First:
- Current
backend/config_manager.pyimplementation - Look for any file paths that hardcode inventory.env
- Understand how config updates are written back to disk
Action:
- Update file paths to use
config/backend.envinstead of rootinventory.env - Ensure write operations go to
config/backend.env - Update comments to reflect new path
- Verify get_config_path() returns path to config/backend.env
- Ensure file operations handle non-existent config/ folder gracefully
Acceptance Criteria:
config_manager.pyreferencesconfig/backend.envinstead ofinventory.env- get_config_path() returns correct path to config/backend.env
- Config updates are written to config/backend.env
- Error handling works if config/ folder doesn't exist
Task 8: Update backend/entrypoint.sh
Read First:
- Current
backend/entrypoint.shcontent - How environment variables are sourced
- Docker ENTRYPOINT and CMD configuration
Action:
- Update entrypoint.sh to source from
config/backend.envinstead of root location - Update path references to point to /app/config/backend.env (inside Docker container)
- Maintain backward compatibility: try config/backend.env first, fall back to inventory.env
- Add logging to show which config was loaded
- Ensure entrypoint handles missing config gracefully
Acceptance Criteria:
entrypoint.shsources fromconfig/backend.env- Falls back to
inventory.envif config/backend.env not found - Inside Docker, path is /app/config/backend.env
- Script logs which config file was loaded
- Script doesn't fail if config files don't exist
Task 9: Update deploy.sh Script
Read First:
- Current
deploy.shimplementation - How environment variables are currently sourced
- Lines that reference inventory.env
Action:
- Update script to load from
config/network.envandconfig/docker.envinstead ofinventory.env - Change:
export $(grep -v '^#' "inventory.env" | xargs)toexport $(grep -v '^#' "config/network.env" | xargs) - Add fallback: if config/network.env doesn't exist, use inventory.env
- Update docker-compose calls to use config/docker.env via environment variable sourcing
- Add validation: check that config/ folder exists before sourcing
- Add helpful error message if config files are missing
Acceptance Criteria:
deploy.shsources fromconfig/network.envinstead ofinventory.env- Includes fallback to
inventory.envif config/network.env not found - Validates config folder exists with helpful error message
- Docker-compose gets correct environment variables from config files
- Script still functions with new structure
Task 10: Update run_standalone.sh Script
Read First:
- Current
run_standalone.shimplementation - Lines that reference CONFIG_PATH or inventory.env
- How network configuration is loaded
- Backend and frontend startup logic
Action:
- Update CONFIG_PATH to point to
config/network.env - Change line:
CONFIG_PATH="$(cd "$(dirname "$0")" && pwd)/inventory.env"to reference config/network.env - Add fallback: if config/network.env not found, try inventory.env
- Update comment to reflect new config location
- Ensure backend environment loading also uses config/backend.env (via PYTHONPATH or direct sourcing)
- Add logging showing which config files are being used
Acceptance Criteria:
run_standalone.shloads fromconfig/network.env- Falls back to
inventory.envif config files not found - Backend loads from
config/backend.envvia config_loader.py - Script logs which config files are loaded
- Standalone mode works with new config structure
Task 11: Update export_prod.sh Script
Read First:
- Current
export_prod.shimplementation - How it uses environment variables
- What configuration it needs
Action:
- Identify all environment variables used by export_prod.sh
- Update script to source from
config/backend.envandconfig/network.env - Add fallback to inventory.env for backward compatibility
- Update comments to reflect new config loading
- Ensure export functionality works with new config structure
Acceptance Criteria:
export_prod.shsources correct config files from config/ folder- Falls back to
inventory.envif needed - All required environment variables are available to the script
- Script functions correctly with new configuration structure
Task 12: Update install_service.sh Script
Read First:
- Current
install_service.shimplementation - How it references configuration
- What paths it sets in systemd service files
Action:
- Update script to reference config/ folder in environment file paths
- Update systemd service file generation to point to config/backend.env
- If service uses EnvironmentFile, ensure it points to config/backend.env or both config/backend.env and config/network.env
- Add validation that config/ folder exists
- Update comments to explain new config structure
Acceptance Criteria:
install_service.shreferences config/backend.env in service configuration- Systemd service file has correct EnvironmentFile paths
- Service can load all required environment variables
- Script validates config folder exists
Task 13: Update docker-compose.yml
Read First:
- Current
docker-compose.ymlfile - All env_file and environment references
- How inventory.env is currently used
Action:
- Update env_file directives to reference config/docker.env instead of inventory.env
- Update any hardcoded environment variable references to use config/ equivalents
- For services using env_file:
env_file: config/docker.env - Ensure Docker build arguments reference correct config location
- Add validation or comment explaining config folder requirement
- Test that docker-compose can still read all needed variables
Acceptance Criteria:
docker-compose.ymlreferencesconfig/docker.envin env_file- All services get correct environment variables
- Docker-compose validates successfully
- Docker services can access all required configuration
Task 14: Update DEPLOYMENT.md
Read First:
- Current
DEPLOYMENT.mdcontent - Current documentation structure
- Instructions for setting up configuration
Action:
- Add new section explaining config folder structure and purpose
- Document each config file (backend.env, frontend.env, network.env, docker.env)
- Explain which variables go in each config file
- Update deployment instructions to reference config/ instead of inventory.env
- Document backward compatibility behavior (still reads inventory.env if config/ not found)
- Add troubleshooting section for common config issues
- Update any examples to use new config paths
Acceptance Criteria:
- DEPLOYMENT.md has section explaining config folder structure
- All four config files are documented with their purpose
- Deployment instructions reference config/ folder
- Backward compatibility is explained
- Examples use new config paths
Task 15: Update README.md
Read First:
- Current
README.mdcontent - Setup/quickstart section
Action:
- Add or update configuration setup section
- Explain that config/ folder is where all configuration lives
- For quick start, show example of creating config/backend.env
- Link to DEPLOYMENT.md for detailed configuration reference
- Keep it concise - detailed docs go in DEPLOYMENT.md
Acceptance Criteria:
- README.md mentions config/ folder
- Setup section references config/ not inventory.env
- Configuration setup is clear for new users
Task 16: Verify Backward Compatibility and Test All Deployment Methods
Read First:
- Current DEPLOYMENT.md
- All scripts that were updated
- Docker Compose setup
- Standalone setup requirements
Action:
- Ensure all scripts still function if inventory.env exists but config/ doesn't (backward compatibility)
- Test Docker deployment:
./deploy.sh production- Verify: services start, environment variables are loaded correctly
- Check logs: which config file was loaded
- Test Standalone deployment:
./run_standalone.sh- Verify: backend and frontend start correctly
- Verify: all environment variables available
- Verify: correct ports from config/network.env
- Test environment variable override: set env var on command line, verify it takes precedence
- Verify config/backend.env is loaded by backend: grep logs for config path message
Acceptance Criteria:
- Docker deployment works with config/ structure
- Standalone deployment works with config/ structure
- Backward compatibility works: scripts still read inventory.env if config/ doesn't exist
- Environment variable precedence works: system env > config files
- All tests pass
- Logs show correct config file was loaded
Task 17: Audit and Clean Up Root Directory
Read First:
- All files in project root directory
- Understand what each script does
- Current .gitignore
Action:
- Review all *.sh scripts in root: deploy.sh, run_standalone.sh, export_prod.sh, install_service.sh, __push_ALL_to_remote.sh
- For each script, determine:
- Is it still used? (check git history, comments, references)
- Can it be archived/removed?
- Does it need updating for config folder?
- For scripts that are truly obsolete:
- Move to dev_docs/ARCHIVE_LOGS.md or note in comment
- Do NOT delete without understanding purpose
- Review inventory.env* files:
- Are inventory.env.example and inventory.env.template still needed?
- Update .gitignore to exclude inventory.env (old) but track config/ structure
- Create summary of what's obsolete and what's actively used
Acceptance Criteria:
- Review completed for all root-level scripts
- Documented which scripts are obsolete (if any)
- Confirmed which scripts are still actively used
- .gitignore updated if needed
- Summary created of root directory cleanup
Task 18: Final Validation and Documentation
Read First:
- Updated DEPLOYMENT.md
- Updated README.md
- Updated scripts
- config/README.md
Action:
- Create comprehensive test checklist:
- Docker deployment test
- Standalone deployment test
- Environment variable override test
- Backward compatibility test
- Config file format validation
- Run all tests and document results
- Verify all config files exist and are properly formatted
- Verify all scripts source from correct locations
- Verify backend loads from config/backend.env
- Create deployment.md section summarizing changes
- Add entry to dev_docs/PLAN.md documenting completion
Acceptance Criteria:
- All deployment methods tested and working
- Config files exist and are properly formatted
- Documentation updated and clear
- No errors in script execution
- Environment variables load from config/ as expected
- Phase marked complete in documentation
Notes
Backward Compatibility:
- All scripts include fallback logic: try config/ first, then fall back to inventory.env
- This allows gradual migration without breaking existing deployments
- Eventually, old inventory.env files can be deprecated after migration period
Configuration Priority (from highest to lowest):
- System environment variables (set by Docker, deployment platform)
- config/backend.env (new centralized backend config)
- inventory.env (legacy, for backward compatibility)
- backend/.env (legacy backend-specific)
- Hardcoded defaults in code
Docker Deployment Flow:
- docker-compose.yml loads config/docker.env
- Services get environment variables from docker-compose.yml
- Backend entrypoint sources config/backend.env for additional variables
- System env vars override everything
Standalone Deployment Flow:
- run_standalone.sh sources config/network.env
- Backend activation sources config/backend.env via config_loader.py
- All environment variables available to both backend and frontend