Skip to content

Closes #173#305

Open
p3ris0n wants to merge 3 commits into
benelabs:mainfrom
p3ris0n:feat/p3ris0n-crucible
Open

Closes #173#305
p3ris0n wants to merge 3 commits into
benelabs:mainfrom
p3ris0n:feat/p3ris0n-crucible

Conversation

@p3ris0n
Copy link
Copy Markdown
Contributor

@p3ris0n p3ris0n commented May 27, 2026

Closes #173

This PR transitions the backend configuration from flat, duplicated dotenvy-based structures to a robust, environment-aware layered approach using the config crate (Option A). This allows for safe defaults bundled directly into the binary, while securely injecting infrastructure overrides via runtime environment variables.

Furthermore, this PR eliminates significant architectural rot and file duplication inside src/main.rs and src/config/mod.rs stemming from older incomplete refactors.

Changes Made
Centralized Configuration Registry: Created AppConfig with strictly typed sub-configurations (ServerConfig, DatabaseConfig, RedisConfig, ObservabilityConfig).
Layered Resolution: Integrated config to layer default .toml files with environment-specific overrides (e.g., development.toml, production.toml).
Binary Embedding: Used include_str! for TOML defaults to guarantee fallback values exist without needing disk-level file mounts in Docker deployments.
Validation: Added a .validate() phase that strictly enforces critical invariants on load (e.g., TLS requirement in production, non-zero connection pools).
Security Features: Prevented accidental credential leakage by tagging sensitive tokens (DB URLs, TLS keys) with #[serde(skip_serializing)] and heavily customized Debug bounds that emit "[REDACTED]".
System Cleanup:
Purged 3 conflicting duplicates of the main function in src/main.rs and consolidated the entry point around the new AppConfig mapping.
Eliminated conflicting configurations spanning src/lib.rs and Cargo.toml.
Upgraded the hot-reloader (src/config/reload.rs) to swap global ArcSwap pointers dynamically via API endpoints without relying on local .json file reads.
Testing: Added config::tests integrating temp-env for zero-race-condition assertions on overrides and strict validation trapping.
Documentation: Appended full deployment and override instructions to backend/README.md.
Testing
Config correctly fails initialization in production if TLS keys are omitted.
Env-vars (e.g. APP_DATABASE__URL) successfully override bundled .toml defaults.
Sensitive fields yield [REDACTED] when the config is formatted to Debug.
Cargo dependencies correctly parsed.
Note on Windows Compilation: As tracked in WINDOWS_TOOLCHAIN_FIX.md, CI/local cargo check runs on Windows might fail targeting the windows-sys dependency without a GNU toolchain (dlltool.exe) present. This PR's logic is fully cross-platform and will successfully compile under Linux, WSL, or correctly provisioned MinGW setups.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@p3ris0n Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

p3ris0n and others added 2 commits May 28, 2026 22:11
- Cargo.toml: merged OpenTelemetry 0.31 from main with SQLx 0.8/Redis 0.27 from feat branch

- README.md: deduplicated and consolidated documentation from both branches

- main.rs: kept feat branch routing, removed non-existent error_analytics_routes

- lib.rs: kept pub mod utils (exists), removed pub mod workers (doesn't exist)

- config/mod.rs: kept layered config crate approach from feat branch

- config/reload.rs: kept ArcSwap ConfigManager, removed legacy ConfigWatcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] 10.4 Add Environment-Specific Configurations

1 participant