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

LAYOUT_WITH_LEGEND()

title Craft Manufacturing / MRP - Component Diagram

Person(owner, "Business Owner", "Oversees production planning, fulfillment priorities, and operational decisions")
Person(staff, "Operations Staff", "Executes production planning, work orders, and fulfillment preparation")

ContainerDb(txdb, "Transaction Database", "Database", "Stores production, BOM, inventory, order, 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(audit, "Audit & Logging Service", "Observability Service", "Captures production, workflow, and compliance-relevant events")
Container(notify, "Notification Service", "Shared Service", "Generates alerts, reminders, and exception notifications")

Container_Boundary(mrp_app, "Craft Manufacturing / MRP") {
  Component(ui, "MRP UI", "Web UI", "Provides dashboards, planning views, work-order management, and production status")
  Component(bom_service, "BOM Management Service", "Application Service", "Maintains bills of material, component relationships, and required quantities")
  Component(workorder_service, "Work Order Service", "Application Service", "Creates, updates, and tracks production work orders")
  Component(schedule_service, "Production Scheduling Service", "Application Service", "Plans production timing, priorities, and resource sequencing")
  Component(material_service, "Material Consumption Service", "Application Service", "Tracks material allocation, consumption, shortages, and exceptions")
  Component(fulfillment_service, "Fulfillment Readiness Service", "Application Service", "Determines order readiness, handoff status, and completion conditions")
  Component(reporting_service, "MRP Reporting Service", "Application Service", "Produces production status, exceptions, throughput, and readiness reports")
  Component(repository, "MRP Repository", "Data Access Component", "Reads and writes production-related data")
}

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

Rel(ui, bom_service, "Sends requests to")
Rel(ui, workorder_service, "Sends requests to")
Rel(ui, schedule_service, "Sends requests to")
Rel(ui, material_service, "Sends requests to")
Rel(ui, fulfillment_service, "Sends requests to")
Rel(ui, reporting_service, "Sends requests to")

Rel(bom_service, repository, "Reads from and writes to")
Rel(workorder_service, repository, "Reads from and writes to")
Rel(schedule_service, repository, "Reads from and writes to")
Rel(material_service, repository, "Reads from and writes to")
Rel(fulfillment_service, repository, "Reads from and writes to")
Rel(reporting_service, repository, "Reads from")

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

Rel(bom_service, datarepo, "Uses shared business data from")
Rel(workorder_service, datarepo, "Uses shared business data from")
Rel(schedule_service, datarepo, "Uses shared business data from")
Rel(material_service, datarepo, "Uses shared business data from")
Rel(fulfillment_service, datarepo, "Uses shared business data from")

Rel(ui, auth, "Authenticates through")
Rel(workorder_service, api, "Publishes production events through")
Rel(fulfillment_service, api, "Publishes readiness and completion events through")
Rel(material_service, notify, "Triggers shortage and exception alerts through")
Rel(reporting_service, api, "Sends reporting outputs through")

Rel(bom_service, audit, "Logs BOM changes to")
Rel(workorder_service, audit, "Logs work-order activity to")
Rel(schedule_service, audit, "Logs scheduling decisions to")
Rel(material_service, audit, "Logs material consumption events to")
Rel(fulfillment_service, audit, "Logs fulfillment state changes to")

@enduml