Config module provides a declarative, type-safe way to load and validate configuration from various sources. It integrates seamlessly with the Schema module for runtime validation.
Overview
AConfig<T> describes how to read and validate a value of type T from a ConfigProvider. Configs can be composed, transformed, and used directly as Effects.
Mental Model
- Config<T>: A recipe for extracting a typed value from a ConfigProvider
- ConfigProvider: The backing data source (environment variables, JSON files, etc.)
- ConfigError: Wraps either a SourceError (I/O failure) or SchemaError (validation failure)
- Yieldable: Every Config can be yielded inside Effect.gen
Reading Configuration
Basic Types
Using Configs in Effects
Structured Configuration
Default Values and Optional Configs
With Default
Optional Configuration
Specialized Config Types
Duration
URL
Redacted (for secrets)
Date
Transforming Configs
Map
MapOrFail
Combining Configs
Using Config.all
Sequential Composition
Error Handling
OrElse
Catching Errors
Config Providers
From Environment Variables
From JSON Object
Nested Configuration
Integration with Layers
Best Practices
- Validate at startup: Load and validate all configuration at application startup
- Use Schema for complex configs: Leverage Schema.Struct for structured configuration
- Provide defaults: Use withDefault for non-critical configuration
- Keep secrets redacted: Use Config.redacted for sensitive values
- Group related configs: Use Config.all or Schema.Struct to group related settings
- Use layers for config services: Wrap configuration in layers for dependency injection