Closes #173#305
Open
p3ris0n wants to merge 3 commits into
Open
Conversation
|
@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! 🚀 |
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.