@startuml

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

HIDE_STEREOTYPE()

title Component diagram for Weather Forecast System - API Application

Container(web_app, "Web Application", "C#, ASP.NET Core Minimal Api, YARP Reverse Proxy", "Delivers the static content, the WFS SPA, and proxy SPA requests back to the api application.")
Container(authz, "Authorization Service", "ASP.NET Core Minimal Api", "Provides permission authorizations to the API service")

System_Ext(identity, "Duende IdentityServer", "User Auhentication and Token Issuer")
System_Ext(loki, "Grafana Loki", "Log aggregation system to store and query logs")

Container_Boundary(api, "API Application") {
    Component(log, "Logging Middleware", "Serilog Logging", "Structured logging for all requests using Serilog.")
    Component(auth, "JWT Bearer Authentication Middleware", "ASP.NET Core Middleware", "performs authentication by extracting and validating a JWT token from the Authorization request header.")
    Component(authz_com, "Authorization Component", "", "Validates user permissions")
    Component(mediatr, "MediatR Pipeline", "", "In process messaging supports request/response, commands, queries, notifications and events.")
    Component(weather_ep, "Weather Endpoints", "ASP.NET Core Minimal Api", "Provide weather forecast management endpoints.")
    Component(data, "Infrastructure Data Component", "EF Core", "Provide database access and O/RM functionality.")
    Component(commands, "Commands Component", "MediatR Request", "Execute write commands through the MediatR pipeline.")
    Component(queries, "Queries Component", "MediatR Request", "Execute read queries through the MediatR pipeline.")
}

Rel(weather_ep, mediatr, "Send Request")
Rel_R(mediatr, commands, "Execute")
Rel(mediatr, queries, "Execute")
Rel(commands, data, "Uses")
Rel_R(queries, data, "Uses")

Rel(authz_com, authz, "Authorize", "JSON/HTTPS")
Rel(auth, identity, "Validate Token", "HTTPS")
Rel_R(authz_com, weather_ep, "/weather")
Rel(auth, authz_com, "Forward Request")
Rel_L(web_app, log, "Proxy", "JSON/HTTPS")
Rel_L(log, auth, "Forward Request")

Rel(log, loki, "Send Logs", "HTTPS")

Lay_R(mediatr, commands)
Lay_U(mediatr, queries)

@enduml