// Canonical example for the book: checkout saga architecture (orchestration + event bus).

person = kind "Person"
system = kind "System"
container = kind "Container"
database = kind "Database"
queue = kind "Message Queue"

customer = person "Customer"

checkout_system = system "Checkout Architecture" {
  api_gateway = container "API Gateway" {
    technology "Kong"
    description "Entry point for checkout requests"
  }

  order_service = container "Order Service" {
    technology "Node.js"
    description "Creates and tracks pending orders"
  }

  order_db = database "Order DB" {
    technology "PostgreSQL"
    description "Order state storage"
  }

  payment_service = container "Payment Service" {
    technology "Go"
    description "Processes payments"
  }

  payment_db = database "Payment DB" {
    technology "PostgreSQL"
    description "Payment records"
  }

  inventory_service = container "Inventory Service" {
    technology "Java"
    description "Reserves and releases inventory"
  }

  inv_db = database "Inventory DB" {
    technology "PostgreSQL"
    description "Inventory levels"
  }

  saga_orchestrator = container "Saga Orchestrator" {
    technology "Temporal"
    description "Manages the state of the checkout transaction"
  }

  event_bus = queue "Event Bus" {
    technology "Kafka"
    description "Checkout domain events"
  }
}

customer -> checkout_system.api_gateway "Submit Order"
checkout_system.api_gateway -> checkout_system.order_service "Create Pending Order"
checkout_system.order_service -> checkout_system.saga_orchestrator "Start Saga"
checkout_system.order_service -> checkout_system.order_db "Stores"
checkout_system.payment_service -> checkout_system.payment_db "Stores"
checkout_system.inventory_service -> checkout_system.inv_db "Stores"
checkout_system.api_gateway -> checkout_system.event_bus "Publishes Events"
checkout_system.saga_orchestrator -> checkout_system "Part of"
checkout_system.order_service -> checkout_system "Part of"
checkout_system.payment_service -> checkout_system "Part of"
checkout_system.inventory_service -> checkout_system "Part of"
