Architecture: Config struct has 40+ fields — should be split into sub-configs #120

Open
opened 2026-05-11 23:08:59 +00:00 by thabeta · 0 comments
Owner

Severity: Medium

Location

crates/hero_aibroker_lib/src/config/mod.rsConfig struct

Finding

The Config struct has 40+ fields covering unrelated concerns:

  • Provider API keys (5 separate Vec fields)
  • Rate limiting (2 fields)
  • Auth (3 fields)
  • CORS (1 field)
  • MCP config (1 field)
  • Model registry (1 field)
  • Request logging (1 field)
  • OpenRouter attribution (2 fields)
  • Catalog refresh (1 field)
  • Mother brokers (1 field, via skip)
  • Priority overrides (1 field, via skip)
  • Host/port (2 fields)
  • And more...

Impact

  • Hard to understand what config is needed for what feature
  • No validation of related fields together
  • Default impl is 30+ lines of unrelated defaults
  • Adding a new config field requires modifying a god struct

Recommendation

  • Split into sub-configs: ProviderConfig, AuthConfig, ServerConfig, McpConfig, CascadeConfig, CatalogConfig
  • Each sub-config validates itself
  • Use composition: Config { providers: ProviderConfig, auth: AuthConfig, ... }
## Severity: Medium ## Location `crates/hero_aibroker_lib/src/config/mod.rs` — `Config` struct ## Finding The Config struct has 40+ fields covering unrelated concerns: - Provider API keys (5 separate Vec fields) - Rate limiting (2 fields) - Auth (3 fields) - CORS (1 field) - MCP config (1 field) - Model registry (1 field) - Request logging (1 field) - OpenRouter attribution (2 fields) - Catalog refresh (1 field) - Mother brokers (1 field, via skip) - Priority overrides (1 field, via skip) - Host/port (2 fields) - And more... ## Impact - Hard to understand what config is needed for what feature - No validation of related fields together - Default impl is 30+ lines of unrelated defaults - Adding a new config field requires modifying a god struct ## Recommendation - Split into sub-configs: `ProviderConfig`, `AuthConfig`, `ServerConfig`, `McpConfig`, `CascadeConfig`, `CatalogConfig` - Each sub-config validates itself - Use composition: `Config { providers: ProviderConfig, auth: AuthConfig, ... }`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_aibroker#120
No description provided.