Configuration Layer¶
The Configuration Layer manages application settings, dependency injection, and module registration.
Configuration Components¶
Settings¶
Settings ¶
Application settings manager with singleton pattern.
Loads configuration from YAML file and provides access to settings throughout the application. Only one instance exists per application.
Attributes:
| Name | Type | Description |
|---|---|---|
config_file | Path | Path to configuration YAML file |
_settings | Dict[str, Any] | Loaded settings dictionary |
Methods:
| Name | Description |
|---|---|
get | Get setting value by dot-notation key |
set | Set setting value by dot-notation key |
get_section | Get entire settings section |
reload | Reload settings from file |
save | Save current settings to YAML file |
get_all | Get all settings |
Initialize settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file | Optional[Path] | Path to YAML configuration file. Defaults to 'config/settings.yaml'. | None |
Source code in src/infrastructure/config/settings.py
Functions¶
__new__ ¶
Singleton implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file | Optional[Path] | Path to config file. Only used on first instantiation. | None |
Source code in src/infrastructure/config/settings.py
get ¶
Get setting value by dot-notation key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Setting key in dot notation (e.g., 'cache.max_size') | required |
default | Any | Default value if key not found | None |
Returns:
| Type | Description |
|---|---|
Any | Setting value or default |
Source code in src/infrastructure/config/settings.py
set ¶
Set setting value by dot-notation key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Setting key in dot notation | required |
value | Any | Value to set | required |
Source code in src/infrastructure/config/settings.py
get_section ¶
Get entire settings section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section | str | Section name (e.g., 'cache') | required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | Section dictionary or empty dict if not found |
Source code in src/infrastructure/config/settings.py
reload ¶
save ¶
Save current settings to YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file | Optional[Path] | Output file path. If None, uses original config_file. | None |
Source code in src/infrastructure/config/settings.py
get_all ¶
Get all settings.
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | Complete settings dictionary. |
DIContainer¶
DIContainer ¶
Dependency injection container.
Manages singleton and factory registrations for application dependencies. Supports lazy initialization and dependency resolution.
Attributes:
| Name | Type | Description |
|---|---|---|
_singletons | Dict[str, Any] | Registered singleton instances |
_factories | Dict[str, Callable[[], Any]] | Registered factory functions |
_types | Dict[str, Type] | Registered types for lazy instantiation |
Methods:
| Name | Description |
|---|---|
register_singleton | Register a singleton instance |
register_factory | Register a factory function |
register_type | Register a type for lazy instantiation |
resolve | Resolve dependency by name |
is_registered | Check if dependency is registered |
get_registered_names | Get list of registered dependency names |
clear | Clear all registrations |
unregister | Unregister a dependency |
Initialize DI container.
Source code in src/infrastructure/config/dependency_injection.py
Functions¶
register_singleton ¶
Register a singleton instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Dependency name | required |
instance | Any | Instance to register | required |
Source code in src/infrastructure/config/dependency_injection.py
register_factory ¶
Register a factory function.
Factory is called each time dependency is resolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Dependency name | required |
factory | Callable[[], Any] | Factory function that creates instances | required |
Source code in src/infrastructure/config/dependency_injection.py
register_type ¶
Register a type for lazy instantiation.
Type is instantiated (with no-arg constructor) when first resolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Dependency name | required |
cls | Type | Class to instantiate | required |
Source code in src/infrastructure/config/dependency_injection.py
resolve ¶
Resolve dependency by name.
Resolution order: singleton, factory, type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Dependency name | required |
Returns:
| Type | Description |
|---|---|
Any | Resolved dependency instance |
Raises:
| Type | Description |
|---|---|
ValueError | If dependency not found |
Source code in src/infrastructure/config/dependency_injection.py
is_registered ¶
Check if dependency is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Dependency name. | required |
Returns:
| Type | Description |
|---|---|
bool | True if registered. |
Source code in src/infrastructure/config/dependency_injection.py
get_registered_names ¶
Get list of registered dependency names.
Returns:
| Type | Description |
|---|---|
list[str] | List of dependency names. |
Source code in src/infrastructure/config/dependency_injection.py
clear ¶
Clear all registrations.
Source code in src/infrastructure/config/dependency_injection.py
unregister ¶
Unregister a dependency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Dependency name. | required |
Returns:
| Type | Description |
|---|---|
bool | True if unregistered, False if not found. |
Source code in src/infrastructure/config/dependency_injection.py
AnalysisRegistry¶
AnalysisRegistry ¶
Registry for analysis configurations.
Loads analysis definitions from JSON files and provides access to analysis metadata, parameters, and settings.
Attributes:
| Name | Type | Description |
|---|---|---|
analyses_dir | Path | Directory containing analysis JSON files |
_analyses | Dict[str, Dict[str, Any]] | Loaded analysis configurations |
Methods:
| Name | Description |
|---|---|
get_analysis | Get analysis configuration by ID |
get_all_analyses | Get all registered analyses |
get_analyses_by_use_case | Get all analyses for a specific Use Case |
get_analysis_ids | Get list of all analysis IDs |
get_use_cases | Get list of unique Use Cases |
analysis_exists | Check if analysis exists |
get_analysis_plot_type | Get plot type for analysis |
reload | Reload all analysis configurations |
get_stats | Get registry statistics |
Initialize analysis registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analyses_dir | Optional[Path] | Directory containing analysis JSON files. Defaults to 'config/analyses/'. | None |
Source code in src/infrastructure/config/analysis_registry.py
Functions¶
get_analysis ¶
Get analysis configuration by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_id | str | Analysis identifier (e.g., 'UC1_1') | required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]] | Analysis configuration or None if not found |
Source code in src/infrastructure/config/analysis_registry.py
get_all_analyses ¶
Get all registered analyses.
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]] | Dictionary mapping analysis IDs to configurations. |
Source code in src/infrastructure/config/analysis_registry.py
get_analyses_by_use_case ¶
Get all analyses for a specific Use Case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_case | str | Use Case identifier (e.g., 'UC1') | required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]] | List of analysis configurations |
Source code in src/infrastructure/config/analysis_registry.py
get_analysis_ids ¶
Get list of all analysis IDs.
Returns:
| Type | Description |
|---|---|
List[str] | List of analysis identifiers. |
get_use_cases ¶
Get list of unique Use Cases.
Returns:
| Type | Description |
|---|---|
List[str] | List of Use Case identifiers |
Source code in src/infrastructure/config/analysis_registry.py
analysis_exists ¶
Check if analysis exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_id | str | Analysis identifier. | required |
Returns:
| Type | Description |
|---|---|
bool | True if analysis is registered. |
Source code in src/infrastructure/config/analysis_registry.py
get_analysis_plot_type ¶
Get plot type for analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_id | str | Analysis identifier | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Plot type (e.g., 'heatmap', 'bar_chart') or None |
Source code in src/infrastructure/config/analysis_registry.py
reload ¶
Reload all analysis configurations from files.
get_stats ¶
Get registry statistics.
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | Statistics including total analyses, use cases, etc. |
Source code in src/infrastructure/config/analysis_registry.py
DatabaseConfig¶
DatabaseConfig ¶
Database configuration manager.
Manages paths and settings for all four databases: BioRemPP, KEGG, HADEG, and ToxCSM.
Attributes:
| Name | Type | Description |
|---|---|---|
config_file | Path | Path to database config YAML file |
_config | Dict[str, Dict[str, str]] | Loaded database configurations |
Methods:
| Name | Description |
|---|---|
get_database_path | Get database file path |
get_database_encoding | Get database file encoding |
get_database_separator | Get database CSV separator |
get_all_database_paths | Get all database paths |
validate_paths | Validate that all database files exist |
get_database_info | Get complete database configuration |
get_available_databases | Get list of available database names |
Initialize database configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file | Optional[Path] | Path to database config YAML file. Defaults to 'config/databases.yaml'. | None |
Source code in src/infrastructure/config/database_config.py
Functions¶
get_database_path ¶
Get database file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_name | str | Database name ('biorempp', 'kegg', 'hadeg', 'toxcsm') | required |
Returns:
| Type | Description |
|---|---|
Path | Path to database file |
Raises:
| Type | Description |
|---|---|
ValueError | If database name is unknown |
Source code in src/infrastructure/config/database_config.py
get_database_encoding ¶
Get database file encoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_name | str | Database name. | required |
default | str | Default encoding if not specified. | 'utf-8' |
Returns:
| Type | Description |
|---|---|
str | File encoding. |
Source code in src/infrastructure/config/database_config.py
get_database_separator ¶
Get database CSV separator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_name | str | Database name. | required |
default | str | Default separator if not specified. | ';' |
Returns:
| Type | Description |
|---|---|
str | CSV separator. |
Source code in src/infrastructure/config/database_config.py
get_all_database_paths ¶
Get all database paths.
Returns:
| Type | Description |
|---|---|
Dict[str, Path] | Dictionary mapping database names to paths |
Source code in src/infrastructure/config/database_config.py
validate_paths ¶
Validate that all database files exist.
Returns:
| Type | Description |
|---|---|
Dict[str, bool] | Dictionary mapping database names to existence status |
Source code in src/infrastructure/config/database_config.py
get_database_info ¶
Get complete database configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_name | str | Database name. | required |
Returns:
| Type | Description |
|---|---|
Dict[str, str] | Database configuration dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError | If database name is unknown. |
Source code in src/infrastructure/config/database_config.py
get_available_databases ¶
Get list of available database names.
Returns:
| Type | Description |
|---|---|
list[str] | List of database names. |