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

LAYOUT_WITH_LEGEND()

title Financial Analysis - Component Diagram

Person(owner, "Business Owner", "Reviews financial performance, profitability, and forecasts")
Person(staff, "Operations Staff", "Runs reports, reviews trends, and supports analysis activities")

ContainerDb(txdb, "Transaction Database", "Database", "Stores orders, transactions, costs, products, and operational records")
Container(auth, "Authentication Service", "Shared Service", "Provides authentication and identity controls")
Container(datarepo, "Shared Data Repository", "Shared Service", "Provides access to shared business entities and reference data")
Container(api, "API Orchestrator", "API / Integration Service", "Coordinates internal and external integrations")
Container(audit, "Audit & Logging Service", "Observability Service", "Captures privileged access, reporting, and compliance-relevant events")
Container(notify, "Notification Service", "Shared Service", "Generates alerts, reminders, and exception notifications")

Container_Boundary(fin_app, "Financial Analysis") {
  Component(ui, "Financial Analysis UI", "Web UI", "Provides dashboards, analysis views, forecasting inputs, and reporting access")
  Component(reporting_service, "Financial Reporting Service", "Application Service", "Produces revenue, expense, margin, and operational financial reports")
  Component(cost_service, "Cost Analysis Service", "Application Service", "Calculates cost drivers, product costs, and production-related financial impacts")
  Component(margin_service, "Profitability & Margin Service", "Application Service", "Evaluates product, order, and channel profitability")
  Component(forecast_service, "Forecasting Service", "Application Service", "Projects revenue, demand, cost, and performance trends")
  Component(exception_service, "Financial Exception Service", "Application Service", "Identifies anomalies, thresholds, and conditions requiring review")
  Component(repository, "Financial Repository", "Data Access Component", "Reads and writes financial-analysis-related data")
}

Rel(owner, ui, "Uses")
Rel(staff, ui, "Uses")

Rel(ui, reporting_service, "Sends requests to")
Rel(ui, cost_service, "Sends requests to")
Rel(ui, margin_service, "Sends requests to")
Rel(ui, forecast_service, "Sends requests to")
Rel(ui, exception_service, "Sends requests to")

Rel(reporting_service, repository, "Reads from")
Rel(cost_service, repository, "Reads from")
Rel(margin_service, repository, "Reads from")
Rel(forecast_service, repository, "Reads from and writes to")
Rel(exception_service, repository, "Reads from and writes to")

Rel(repository, txdb, "Reads from and writes to")

Rel(reporting_service, datarepo, "Uses shared business data from")
Rel(cost_service, datarepo, "Uses shared business data from")
Rel(margin_service, datarepo, "Uses shared business data from")
Rel(forecast_service, datarepo, "Uses shared business data from")
Rel(exception_service, datarepo, "Uses shared business data from")

Rel(ui, auth, "Authenticates through")
Rel(reporting_service, api, "Sends reporting outputs through")
Rel(exception_service, notify, "Triggers alerts and threshold notifications through")
Rel(forecast_service, api, "Publishes forecast outputs through")

Rel(reporting_service, audit, "Logs reporting access to")
Rel(cost_service, audit, "Logs cost analysis activity to")
Rel(margin_service, audit, "Logs profitability analysis activity to")
Rel(forecast_service, audit, "Logs forecast generation activity to")
Rel(exception_service, audit, "Logs anomaly and exception review activity to")

@enduml