A modern, type-safe configuration management library for Rust
β¨ Features β’ π Quick Start β’ π Documentation β’ π» Examples β’ π€ Contributing
Confers provides a declarative approach to configuration management with:
| β¨ Type Safety | π Auto Reload | π AES-256 Encryption | π Remote Sources |
|---|---|---|---|
| Compile-time checks | Hot reload support | Sensitive data protection | etcd, Consul, HTTP |
use confers::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Config)]
#[config(validate)]
pub struct AppConfig {
pub name: String,
pub port: u16,
pub debug: bool,
}
// Configuration loads automatically from files, env vars, and CLI args
let config = AppConfig::load()?;π Table of Contents (Click to expand)
| π― Core Features | β‘ Optional Features |
|---|---|
| Always available | Enable as needed |
|
|
| Preset | Features | Use Case |
|---|---|---|
| minimal | derive |
Minimal config loading (no validation, no CLI) |
| recommended | derive, validation |
Recommended for most applications |
| dev | derive, validation, cli, schema, audit, monitoring, tracing |
Development with all tools |
| production | derive, validation, watch, encryption, remote, monitoring, tracing |
Production-ready configuration |
| full | All features | Complete feature set |
Note: The cli feature automatically includes derive, validation, and encryption dependencies.
graph LR
A[<b>Configuration Sources</b><br/>π Files β’ π Env β’ π» CLI] --> B[<b>ConfigLoader</b><br/>π§ Core Engine]
B --> C[<b>Validation</b><br/>β
Type & Business Rules]
B --> D[<b>Schema</b><br/>π JSON Schema Gen]
B --> E[<b>Encryption</b><br/>π AES-256-GCM]
B --> F[<b>Audit</b><br/>π Access Logs]
B --> G[<b>Monitoring</b><br/>π Memory Watch]
C --> H[<b>Application Config</b><br/>π Ready to Use]
D --> H
E --> H
F --> H
G --> H
style A fill:#DBEAFE,stroke:#1E40AF,stroke-width:2px
style B fill:#FEF3C7,stroke:#92400E,stroke-width:2px
style H fill:#DCFCE7,stroke:#166534,stroke-width:2px
Individual Features:
Note: The |
Required Features: derive, validation (use: features = ["recommended"])
|
Step 1: Define Config Structure use confers::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Config)]
#[config(validate)]
#[config(env_prefix = "APP_")]
pub struct AppConfig {
pub name: String,
pub port: u16,
pub debug: bool,
} |
Step 2: Create Config File # config.toml
name = "my-app"
port = 8080
debug = true |
|
Step 3: Load Config fn main() -> anyhow::Result<()> {
let config = AppConfig::load()?;
println!("β
Loaded: {:?}", config);
Ok(())
} |
Step 4: Environment Override # Environment variables automatically override
export APP_PORT=9090
export APP_DEBUG=true |
π Complete Working Example
use confers::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Config)]
#[config(validate)]
#[config(env_prefix = "APP_")]
pub struct AppConfig {
pub name: String,
pub port: u16,
pub debug: bool,
}
fn main() -> anyhow::Result<()> {
// Create config file
let config_content = r#"
name = "my-app"
port = 8080
debug = true
"#;
std::fs::write("config.toml", config_content)?;
// Load configuration
let config = AppConfig::load()?;
// Print configuration
println!("π Configuration loaded successfully!");
println!("π Name: {}", config.name);
println!("π Port: {}", config.port);
println!("π Debug: {}", config.debug);
Ok(())
}Confers provides three flexible usage patterns to suit different needs:
Perfect for most applications with minimal boilerplate:
use confers::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Config)]
#[config(validate)]
pub struct AppConfig {
pub name: String,
pub port: u16,
pub debug: bool,
}
// One-line configuration loading
let config = AppConfig::load()?;For more control over configuration sources:
use confers::core::ConfersConfigBuilder;
let config = ConfersConfigBuilder::new()
.with_file("config.toml")
.with_file("local.toml") // Higher priority
.with_env_prefix("APP_")
.build()?;
let name = config.get_string("app.name");
let port = config.get_int("app.port");For integration into frameworks and runtime flexibility:
use std::sync::Arc;
use confers::core::{ConfersConfig, FileConfersConfig};
// Use trait object for dependency injection
let shared_config: Arc<dyn ConfersConfig> = Arc::new(
FileConfersConfig::new("config.toml")?
);
// Can be swapped at runtime
let service = MyService::new(shared_config);|
User Guide Complete usage guide |
API Reference Complete API docs |
Examples Code examples |
| Resource | Description |
|---|---|
| β FAQ | Frequently asked questions |
| π Contributing Guide | Code contribution guidelines |
| π API Reference | Complete API documentation |
| ποΈ Architecture Decisions | ADR documentation |
| π Library Integration Guide | How to integrate confers CLI into your projects |
Confers provides a unified ConfersCli API for easy integration into other Rust projects.
[dependencies]
confers = { version = "0.2.2", features = ["cli"] }use confers::ConfersCli;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate configuration template
ConfersCli::generate(Some("config.toml"), "full")?;
// Validate configuration
ConfersCli::validate("config.toml", "full")?;
// Compare configurations
ConfersCli::diff("config1.toml", "config2.toml", Some("unified"))?;
// Encrypt values
let encrypted = ConfersCli::encrypt("secret", None)?;
Ok(())
}| Method | Description | Example |
|---|---|---|
generate(output, level) |
Generate config templates | ConfersCli::generate(Some("app.toml"), "minimal")? |
validate(config, level) |
Validate config files | ConfersCli::validate("app.toml", "full")? |
diff(file1, file2, format) |
Compare configs | ConfersCli::diff("old.toml", "new.toml", Some("side-by-side"))? |
encrypt(value, key) |
Encrypt values | ConfersCli::encrypt("secret", None)? |
wizard(non_interactive) |
Interactive setup | ConfersCli::wizard(false)? |
completions(shell) |
Generate completions | ConfersCli::completions("bash")? |
key(subcommand) |
Key management | ConfersCli::key(&KeySubcommand::Generate)? |
schema(struct_name, output) |
Generate JSON Schema | ConfersCli::schema("AppConfig", Some("schema.json"))? |
π Complete Integration Guide β
use confers::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Config)]
#[config(validate)]
pub struct BasicConfig {
pub name: String,
pub port: u16,
}
fn basic_example() -> anyhow::Result<()> {
let config = BasicConfig::load()?;
println!("β
Name: {}, Port: {}", config.name, config.port);
Ok(())
}View Output |
use confers::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Config)]
#[config(validate)]
#[config(env_prefix = "MYAPP_")]
pub struct AdvancedConfig {
#[config(description = "Server port number")]
pub port: u16,
#[config(default = "localhost")]
pub host: String,
#[config(sensitive = true)]
pub api_key: String,
}
fn advanced_example() -> anyhow::Result<()> {
let config = AdvancedConfig::load()?;
println!("π Server: {}:{}", config.host, config.port);
Ok(())
}View Output |
graph TB
subgraph Sources ["π₯ Configuration Sources"]
A[π Local Files<br/>TOML, JSON, YAML, INI]
B[π Environment Variables]
C[π» CLI Arguments]
D[βοΈ Remote Sources<br/>etcd, Consul, HTTP]
end
subgraph Core ["π§ Core Engine"]
E[β‘ ConfigLoader<br/>Multi-source Merge]
end
subgraph Processing ["π¨ Processing Layer"]
F[β
Validation<br/>Type & Business Rules]
G[π Schema Generation]
H[π Encryption<br/>AES-256-GCM]
I[π Audit Logging]
J[ποΈ File Watching]
K[π Memory Monitoring]
end
subgraph Output ["π€ Application"]
L[π Application Configuration<br/>Type-Safe & Validated]
end
Sources --> Core
Core --> Processing
Processing --> Output
style Sources fill:#DBEAFE,stroke:#1E40AF
style Core fill:#FEF3C7,stroke:#92400E
style Processing fill:#EDE9FE,stroke:#5B21B6
style Output fill:#DCFCE7,stroke:#166534
| Component | Description | Status |
|---|---|---|
| ConfigLoader | Core loader with multi-source support | β Stable |
| Configuration Validation | Built-in validator integration | β Stable |
| Schema Generation | Auto-generate JSON Schema | β Stable |
| File Watching | Real-time monitoring with hot reload | β Stable |
| Remote Configuration | etcd, Consul, HTTP support | π§ Beta |
| Audit Logging | Record access and change history | β Stable |
| Encrypted Storage | AES-256 encrypted storage | β Stable |
| Configuration Diff | Multiple output formats | β Stable |
| Interactive Wizard | Template generation | β Stable |
|
Basic Configuration [project]
name = "my-app"
version = "1.0.0"
[server]
host = "localhost"
port = 8080
[features]
debug = true
logging = true |
Advanced Configuration [project]
name = "my-app"
version = "1.0.0"
[server]
host = "0.0.0.0"
port = 8080
workers = 4
[database]
url = "postgres://localhost/db"
pool_size = 10
[performance]
cache_size = 1000 |
π§ All Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
name |
String | - | Project name |
version |
String | "1.0.0" | Version number |
host |
String | "localhost" | Server host |
port |
u16 | 8080 | Server port |
debug |
Boolean | false | Enable debug mode |
workers |
usize | 4 | Number of worker threads |
cache_size |
usize | 1000 | Cache size in MB |
# π§ͺ Run all tests
cargo test --all-features
# π Generate coverage report
cargo tarpaulin --out Html
# β‘ Run benchmarks
cargo bench
# π― Run specific test
cargo test test_nameπ Test Statistics
| Category | Test Count | Coverage |
|---|---|---|
| π§ͺ Unit Tests | 50+ | 85% |
| π Integration Tests | 20+ | 80% |
| β‘ Performance Tests | 10+ | 75% |
| π Total | 80+ | 80% |
|
π Throughput
|
β±οΈ Latency
|
π Detailed Benchmarks
# Run benchmarks
cargo bench
# Sample output:
test bench_config_load ... bench: 1,000 ns/iter (+/- 50)
test bench_validate ... bench: 2,000 ns/iter (+/- 100)
test bench_schema_gen ... bench: 500 ns/iter (+/- 25)|
Memory Safety Zero-copy & secure cleanup |
Audited Regular security audits |
Privacy No data collection |
Compliance Industry standards |
π Security Details
| Measure | Description | API Reference |
|---|---|---|
| β Memory Protection | Automatic secure cleanup with zeroization | SecureString, zeroize crate |
| β Side-channel Protection | Constant-time cryptographic operations | AES-256-GCM encryption |
| β Input Validation | Comprehensive input sanitization | ConfigValidator, InputValidator |
| β Audit Logging | Full operation tracking | AuditConfig, audit trails |
| β SSRF Protection | Server-Side Request Forgery prevention | validate_remote_url() |
| β Sensitive Data Detection | Automatic detection of sensitive fields | SensitiveDataDetector |
| β Error Sanitization | Remove sensitive info from error messages | ErrorSanitizer, SecureLogger |
| β Nonce Reuse Detection | Prevent cryptographic nonce reuse | Built into encryption module |
// Secure string handling
use confers::security::{SecureString, SensitivityLevel};
let secure_str = SecureString::new("sensitive_data", SensitivityLevel::High);
// Input validation
use confers::security::ConfigValidator;
let validator = ConfigValidator::new();
let result = validator.validate_input(user_input);
// Error sanitization
use confers::security::ErrorSanitizer;
let sanitizer = ErrorSanitizer::default();
let safe_error = sanitizer.sanitize(&error_message);
// Audit logging
#[cfg(feature = "audit")]
use confers::audit::AuditConfig;
let audit = AuditConfig::new().enable_sensitive_field_tracking();- Use SecureString for sensitive data: Automatically zeroizes memory
- Enable audit logging: Track all configuration access and changes
- Validate all inputs: Use built-in validators for user inputs
- Use encryption: Enable
encryptionfeature for sensitive configs - Follow principle of least privilege: Minimize sensitive data exposure
Please report security vulnerabilities to: security@confers.example
gantt
title Confers Development Roadmap
dateFormat YYYY-MM
section Core Features β
Type-safe Configuration :done, 2024-01, 2024-06
Multi-format Support :done, 2024-02, 2024-06
Environment Variable Override :done, 2024-03, 2024-06
section Validation System β
Basic Validation Integration :done, 2024-04, 2024-07
Parallel Validation Support :done, 2024-05, 2024-08
section Advanced Features π§
Schema Generation :active, 2024-06, 2024-09
File Watching Hot Reload :done, 2024-07, 2024-09
Remote Configuration Support :active, 2024-08, 2024-12
Audit Logging :done, 2024-08, 2024-10
|
|
|
Found an issue? |
Have a great idea? |
Want to contribute code? |
π Contribution Guidelines
- Fork this repository
- Clone your fork:
git clone https://github.com/yourusername/confers.git - Create a branch:
git checkout -b feature/amazing-feature - Make your changes
- Test your changes:
cargo test --all-features - Commit your changes:
git commit -m 'feat: Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Create a Pull Request
- β Follow Rust standard coding conventions
- β Write comprehensive tests
- β Update documentation
- β Add examples for new features
- β
Pass
cargo clippy -- -D warnings
|
Rust |
GitHub |
| Category | Description |
|---|---|
| π Dependency Projects | serde - Serialization framework |
| figment - Configuration management | |
| validator - Validation library | |
| π₯ Contributors | Thanks to all contributors! |
| π¬ Community | Special thanks to community members |
|
Issues Report bugs & issues |
Discussions Ask questions & share ideas |
GitHub View source code |
If you find this project useful, please consider giving it a βοΈ!
Built with β€οΈ by Kirky.X
Β© 2026 Kirky.X. All rights reserved.