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

title Athena Auth Email Templates (After)

rectangle "Tenant Runtime A" as TenantA #EAF2FF {
  component "Email plugins" as APlugins #D8E8FF
  component "AuthEmailTemplateResolver" as AResolver #CFE6D9
  database "tenant_a.email_event_types" as AEventTbl #E2F7EA
  database "tenant_a.email_templates" as ATbl #E8F5EA
}

rectangle "Tenant Runtime B" as TenantB #FFEEDB {
  component "Email plugins" as BPlugins #FFE3C4
  component "AuthEmailTemplateResolver" as BResolver #F7DCC9
  database "tenant_b.email_event_types" as BEventTbl #FFEBD7
  database "tenant_b.email_templates" as BTbl #FFF1DF
}

component "Built-in default templates" as Defaults #F4F4F4
component "EmailProvider (SMTP/API)" as Provider #E7F7E7

APlugins --> AResolver : render(event_type, template_key, vars)
BPlugins --> BResolver : render(event_type, template_key, vars)

AResolver --> ATbl : lookup active override\n(event_type + locale)
BResolver --> BTbl : lookup active override\n(event_type + locale)
AResolver --> ATbl : fallback lookup\n(template_key + locale)
BResolver --> BTbl : fallback lookup\n(template_key + locale)
AResolver --> AEventTbl : validate/catalog event_type
BResolver --> BEventTbl : validate/catalog event_type

AResolver --> Defaults : fallback when no override\nor query failure
BResolver --> Defaults : fallback when no override\nor query failure

AResolver --> Provider : send subject/html/text
BResolver --> Provider : send subject/html/text

note bottom
Each tenant runtime resolves templates + canonical event taxonomy from its own schema.
Overrides are event-type aware and still retain safe default fallback behavior.
end note
@enduml
