@startuml
skinparam backgroundColor #FFFFFF
skinparam defaultFontColor #000000
skinparam ArrowColor #000000
skinparam componentBorderColor #000000
skinparam databaseBorderColor #000000
skinparam shadowing false
left to right direction

title Email Event Taxonomy Assignment (After)

component "Admin Email Template API\n/admin/email-template/*" as AdminApi #DDEBFF
component "Admin Event Type API\n/admin/email-event-type/list" as EventApi #E3F2FD
component "AuthEmailTemplateResolver" as Resolver #D8F3DC
database "email_event_types\n(event_type PK, category,\nrequired/optional variables, ...)" as EventTable #E8F7E9
database "email_templates\n(template_key, event_type FK, locale, ...)" as TemplateTable #FFF4D6
component "Built-in template defaults" as Defaults #F3F4F6

AdminApi --> TemplateTable : assign template rows\nto canonical eventType
EventApi --> EventTable : list/filter seeded taxonomy
TemplateTable --> EventTable : FK event_type -> event_type

Resolver --> TemplateTable : lookup active template\nby eventType + locale
Resolver --> TemplateTable : fallback lookup\nby templateKey + locale
Resolver --> Defaults : final fallback

note bottom
Runtime precedence is now:
1) eventType mapping
2) templateKey mapping
3) built-in defaults.
Catalog rows are queryable and documented for current + future email flows.
end note
@enduml
