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

title Multi-tenant Email Admin Surface (After)

actor "Tenant Admin" as Admin

rectangle "Tenant Runtime (resolved by x-athena-tenant)" as Runtime #EAF2FF {
  component "AdminPlugin Email APIs" as AdminPlugin #D8E8FF
  component "Emails API\nlist/get/create/update/delete" as EmailCrud #D8E8FF
  component "Email Failure API\nlist/get/create/update/delete" as FailureCrud #FFE6D5
  component "Email template CRUD\n(create/list/update/delete)" as TemplateCrud #D8E8FF
  component "write_audit(...)" as Audit #E7F7E7
}

rectangle "Adapter layer" as Adapter #F6F6F6 {
  component "list_sent_emails_with_params\n(get/update/delete sent email)" as EmailAdapter #F4F4F4
  component "list/update/delete failure records" as FailureAdapter #FDEFE6
}

database "emails\n(flow + updated_at)" as EmailsTable #FFFFFF
database "email_send_failures\n(resolved + resolution_note + updated_at)" as FailuresTable #FFFFFF
database "email_templates" as TemplatesTable #FFFFFF
database "admin_audit_logs" as AdminAudit #FFFFFF

Admin --> EmailCrud
Admin --> FailureCrud
Admin --> TemplateCrud

EmailCrud --> EmailAdapter
FailureCrud --> FailureAdapter
TemplateCrud --> TemplatesTable

EmailAdapter --> EmailsTable
FailureAdapter --> FailuresTable

EmailCrud --> Audit
FailureCrud --> Audit
TemplateCrud --> Audit
Audit --> AdminAudit

note bottom
All operations stay tenant-safe because request dispatch selects one tenant runtime
before AdminPlugin executes; each CRUD path only hits that tenant schema.
end note
@enduml
