Date: 2025-02-25
Status
Accepted
Context
Our ebook conversion system contains numerous hardcoded paths throughout the codebase, including:
- Build and output directories
- Content and asset directories
- External tool paths
- Format-specific output locations
This approach has led to several issues:
- Lack of flexibility: Paths cannot be easily changed without code modifications
- Environment inconsistency: Different environments (development, test, production) use the same paths
- Duplication: The same paths are defined in multiple places
- Maintenance burden: Path changes require updates in multiple files
- Testing complexity: Tests need to override paths or work with fixed locations
As we prepare for the Elixir migration, we need a more maintainable approach to path management that will simplify the transition and improve the system's flexibility.
Decision
We will implement a centralized path configuration system with the following components:
- Path Configuration Module: A dedicated
BookProcessing::Configuration::Pathsclass to manage path definitions - Environment-specific Configuration: YAML files for different environments (development, test, production)
- Default Paths: Sensible defaults for all required paths
- Path Resolution: Support for both absolute and relative paths
- Configuration Loading: Centralized configuration loading mechanism
The implementation will:
- Store all path definitions in environment-specific YAML files
- Provide a consistent API for accessing paths throughout the codebase
- Support path overrides for testing and special cases
- Handle path resolution relative to project root or other base paths
- Validate path configurations at startup
Consequences
Positive
- Improved flexibility: Paths can be changed without code modifications
- Environment support: Different environments can use appropriate paths
- Reduced duplication: Paths defined in a single location
- Easier maintenance: Path changes require updates in only one place
- Simplified testing: Tests can easily override paths
- Migration readiness: Clean separation of configuration from code will simplify Elixir migration
Negative
- Migration effort: Existing code must be updated to use the new configuration system
- Potential for confusion: Developers must learn to use the configuration system instead of hardcoding paths
- Indirection: Additional layer between code and filesystem
- Configuration management: Need to maintain multiple configuration files
Mitigation Strategies
- Comprehensive documentation: Document the path configuration system thoroughly
- Gradual migration: Update code incrementally to use the new system
- Default fallbacks: Provide sensible defaults for all paths
- Configuration validation: Validate configurations at startup to catch issues early
- Path helpers: Create helper methods for common path operations
Implementation Plan
- Create
BookProcessing::Configuration::Pathsclass - Create environment-specific YAML configuration files
- Update existing code to use the configuration system
- Add validation for path configurations
- Document the new approach
References
- Configuration management best practices
- Ruby configuration patterns
- Twelve-Factor App methodology (https://12factor.net/config)