@startuml
title After: Generic Config Resolver with Env-Final Precedence
skinparam backgroundColor #FAFAFA
skinparam componentStyle rectangle
skinparam defaultFontName Consolas

package "Startup" #E8FFF0 {
  component "load_server_config_file()" as load
  component "ConfigResolver" as resolver
  component "collect_fields_from_value()" as fields
  component "resolve_env_template()\n${ENV} / ${ENV:-default}" as tmpl
  component "apply_env_override()\nATHENA_AUTH_CONFIG__..." as override
  component "serde_yaml::from_value -> ServerConfigFile" as parse
}

package "Override Sources" #E8F1FF {
  component "Canonical env key\nATHENA_AUTH_CONFIG__<PATH>" as canonical
  component "Legacy aliases\nBASE_URL/AUTH_BASE_PATH/TRUSTED_ORIGINS" as legacy
}

package "Runtime" #FFF4E6 {
  component "Resolved ServerConfigFile" as cfg
  component "load_config() env-final\n(base_url, base_path, trusted_origins)" as runtime
}

file "config.yaml" as yaml
database "Environment" as env

yaml --> load
load --> resolver
resolver --> fields
resolver --> tmpl
resolver --> override
override --> canonical
override --> legacy
env --> canonical
env --> legacy
resolver --> parse
parse --> cfg
cfg --> runtime

note bottom of resolver
Deterministic precedence:
1) resolve inline templates
2) apply env override by discovered config path
3) deserialize typed config
end note
@enduml
