# yaml-language-server: $schema=../references/diagram.schema.json
title: Enterprise integration on Azure
subtitle: API Management fronts Logic Apps workflows that decouple back-end systems through Service Bus, with Event Grid waking the consumer when messages wait
direction: down
# Filled triangles, as in Azure's reference diagrams; one port per edge.
arrowhead: filled
layout: { merge: false, spacing: compact }

legend:
  solid: HTTPS calls
  dashed: Messages and events
  dotted: Sign-in

groups:
  sub: { type: azure:subscription, label: Integration subscription }
  rg: { type: azure:resource-group, label: rg-integration-prod, in: sub }
  backends: { type: zone, label: Back-end systems }

nodes:
  # Entra ID shares the client's row, to its left, so sign-in reads as a step beside the request path.
  entra: { icon: azure:entra-managed-identities, label: Microsoft Entra ID, note: Managed identities, align: app }
  app: { icon: generic:client, label: Client application, note: Web or mobile app }
  # align folds the chain into rows: the API layer, then the messaging layer, then the back ends.
  apim: { icon: azure:api-management-services, label: API Management, note: API gateway and developer portal, in: rg }
  intake: { icon: azure:logic-apps, label: Logic Apps, note: Intake workflow, align: apim, in: rg }
  bus: { icon: azure:azure-service-bus, label: Azure Service Bus, note: Queues and topics, in: rg }
  events: { icon: azure:event-grid-topics, label: Azure Event Grid, note: Service Bus system topic, align: bus, in: rg }
  process: { icon: azure:logic-apps, label: Logic Apps, note: Processing workflow, align: bus, in: rg }
  legacy: { icon: generic:server, label: Message-based service, note: Existing order system, in: backends }
  saas: { icon: generic:cloud, label: SaaS service, in: backends }
  sql: { icon: azure:sql-database, label: Azure SQL Database, note: Line-of-business data, in: backends }

edges:
  # The client signs in first, then calls the gateway with the token.
  - app ..> entra: OAuth 2.0
  - app -> apim: HTTPS
  - apim -> intake
  - intake --> bus: send
  # Proxied push: Service Bus raises an event when messages wait, so nothing polls the queue.
  - bus --> events: messages waiting
  - events --> process: trigger
  # The consumers pull from Service Bus with PeekLock, so the arrowheads stay on the queue.
  - { from: bus, to: process, arrow: start, line: dashed, label: peek-lock receive }
  - process -> saas: REST connector
  - process -> sql: SQL connector
  - { from: bus, to: legacy, arrow: start, line: dashed, label: topic subscription }
