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

LAYOUT_WITH_LEGEND()

title Inventory Application - Component Diagram

Person(owner, "Business Owner", "Oversees inventory accuracy, stock visibility, and operational decisions")
Person(staff, "Operations Staff", "Performs inventory updates, stock checks, and adjustments")

ContainerDb(txdb, "Transaction Database", "Database", "Stores inventory, materials, product, and transaction 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(notify, "Notification Service", "Shared Service", "Generates alerts and workflow notifications")

Container_Boundary(inventory_app, "Inventory Application") {
  Component(ui, "Inventory UI", "Web UI", "Provides inventory dashboards, stock lookup, adjustment forms, and reports")
  Component(stock_service, "Stock Management Service", "Application Service", "Handles stock levels, stock movement, and quantity calculations")
  Component(material_service, "Material Catalog Service", "Application Service", "Manages raw materials, supply metadata, and status")
  Component(product_service, "Finished Goods Service", "Application Service", "Tracks finished goods inventory and sellable product records")
  Component(adjustment_service, "Adjustment Service", "Application Service", "Processes stock corrections, losses, damages, and reconciliations")
  Component(reporting_service, "Inventory Reporting Service", "Application Service", "Produces stock status, valuation, and exception reports")
  Component(repository, "Inventory Repository", "Data Access Component", "Reads and writes inventory-related data")
}

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

Rel(ui, stock_service, "Sends requests to")
Rel(ui, material_service, "Sends requests to")
Rel(ui, product_service, "Sends requests to")
Rel(ui, adjustment_service, "Sends requests to")
Rel(ui, reporting_service, "Sends requests to")

Rel(stock_service, repository, "Reads from and writes to")
Rel(material_service, repository, "Reads from and writes to")
Rel(product_service, repository, "Reads from and writes to")
Rel(adjustment_service, repository, "Reads from and writes to")
Rel(reporting_service, repository, "Reads from")

Rel(repository, txdb, "Reads from and writes to")
Rel(stock_service, datarepo, "Uses shared business data from")
Rel(material_service, datarepo, "Uses shared business data from")
Rel(product_service, datarepo, "Uses shared business data from")

Rel(ui, auth, "Authenticates through")
Rel(stock_service, api, "Publishes events through")
Rel(adjustment_service, notify, "Triggers alerts through")
Rel(reporting_service, api, "Sends reporting data through")

@enduml