@startuml C4_Container
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml

title Container diagram for Meldestelle

Person(eventOrganizer, "Event Organizer", "Organizes and manages equestrian events")
Person(administrator, "Administrator", "Manages system configuration and master data")
Person(member, "Member", "Registers for events and manages personal information")
Person(horseOwner, "Horse Owner", "Registers and manages horse information")

System_Boundary(meldestelle, "Meldestelle") {
    Container(desktopApp, "Desktop Application", "Kotlin, Compose Multiplatform", "Provides a rich UI for administrators and event organizers")
    Container(webApp, "Web Application", "Kotlin, Compose Multiplatform", "Provides a web interface for members and horse owners")

    Container(apiGateway, "API Gateway", "Kotlin, Ktor", "Routes requests to appropriate services, handles authentication and authorization")

    Container(masterdataService, "Masterdata Service", "Kotlin, Spring Boot", "Manages master data such as locations, disciplines, etc.")
    Container(membersService, "Members Service", "Kotlin, Spring Boot", "Manages member registration and profiles")
    Container(horsesService, "Horses Service", "Kotlin, Spring Boot", "Manages horse registration and information")
    Container(eventsService, "Events Service", "Kotlin, Spring Boot", "Manages event creation, scheduling, and registrations")

    ContainerDb(postgresql, "PostgreSQL", "Database", "Stores all persistent data")
    ContainerDb(redis, "Redis", "Cache", "Provides caching for frequently accessed data")
    Container(kafka, "Kafka", "Message Broker", "Handles event-driven communication between services")
    Container(keycloak, "Keycloak", "Authentication Server", "Manages user authentication and authorization")

    Container(monitoring, "Monitoring", "Prometheus, Grafana, Zipkin", "Provides monitoring, metrics, and distributed tracing")
}

System_Ext(paymentProvider, "Payment Provider", "Processes payments for event registrations")
System_Ext(emailSystem, "Email System", "Sends notifications and confirmations")
System_Ext(federationSystem, "Equestrian Federation System", "Provides validation of memberships and horses")

Rel(eventOrganizer, desktopApp, "Uses")
Rel(administrator, desktopApp, "Uses")
Rel(member, webApp, "Uses")
Rel(horseOwner, webApp, "Uses")

Rel(desktopApp, apiGateway, "Makes API calls to", "HTTPS/JSON")
Rel(webApp, apiGateway, "Makes API calls to", "HTTPS/JSON")

Rel(apiGateway, masterdataService, "Routes requests to", "HTTPS/JSON")
Rel(apiGateway, membersService, "Routes requests to", "HTTPS/JSON")
Rel(apiGateway, horsesService, "Routes requests to", "HTTPS/JSON")
Rel(apiGateway, eventsService, "Routes requests to", "HTTPS/JSON")
Rel(apiGateway, keycloak, "Authenticates with", "HTTPS/JSON")

Rel(masterdataService, postgresql, "Reads from and writes to")
Rel(membersService, postgresql, "Reads from and writes to")
Rel(horsesService, postgresql, "Reads from and writes to")
Rel(eventsService, postgresql, "Reads from and writes to")

Rel(masterdataService, redis, "Caches data in")
Rel(membersService, redis, "Caches data in")
Rel(horsesService, redis, "Caches data in")
Rel(eventsService, redis, "Caches data in")

Rel(masterdataService, kafka, "Publishes and subscribes to events")
Rel(membersService, kafka, "Publishes and subscribes to events")
Rel(horsesService, kafka, "Publishes and subscribes to events")
Rel(eventsService, kafka, "Publishes and subscribes to events")

Rel(masterdataService, monitoring, "Sends metrics and traces to")
Rel(membersService, monitoring, "Sends metrics and traces to")
Rel(horsesService, monitoring, "Sends metrics and traces to")
Rel(eventsService, monitoring, "Sends metrics and traces to")
Rel(apiGateway, monitoring, "Sends metrics and traces to")

Rel(eventsService, paymentProvider, "Processes payments through", "HTTPS/JSON")
Rel(membersService, emailSystem, "Sends notifications via", "SMTP")
Rel(eventsService, emailSystem, "Sends notifications via", "SMTP")
Rel(membersService, federationSystem, "Validates memberships with", "HTTPS/JSON")
Rel(horsesService, federationSystem, "Validates horses with", "HTTPS/JSON")

@enduml
