# sapkalsachin2011/sagapattern architecture

> Architecture diagram of the GitHub repository sapkalsachin2011/sagapattern, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sapkalsachin2011/sagapattern
- Repository: https://github.com/sapkalsachin2011/sagapattern

## Overview

This is an orchestrated order-processing Saga: a client submits and polls an order; the API persists it and publishes an event; the Saga coordinates inventory reservation and payment, then confirms the order or compensates by releasing inventory. Workers keep service-owned state, while the API and notification worker consume status changes. The README documents the principal message flow and scenarios; sampled source confirms API submission, inventory reservation, and service persistence setup, but not every consumer or the state machine implementation.

Main entry points: [`src/Saga.Orchestrator/OrderSagaStateMachine.cs`](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Orchestrator/OrderSagaStateMachine.cs) (Order Saga), [`src/Saga.Contracts/Messages.cs`](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Contracts/Messages.cs) (Saga messages), [`src/Order.Api/Program.cs`](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Order.Api/Program.cs) (Order HTTP API), [`src/Inventory.Worker/Consumers/ReserveInventoryConsumer.cs`](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Inventory.Worker/Consumers/ReserveInventoryConsumer.cs) (Inventory worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Order API"]
  node_order_api["Order HTTP API<br/>[Program.cs]"]
  node_order_store[("Order database<br/>[OrderDbContext.cs]")]
end

subgraph group_orchestration["Saga orchestration"]
  node_saga["Order Saga"]
  node_saga_store[("Saga database<br/>[SagaDbContext.cs]")]
end

subgraph group_workers["Domain workers"]
  node_inventory["Inventory worker"]
  node_inventory_store[("Inventory database")]
  node_payment["Payment worker"]
  node_payment_store[("Payment database")]
  node_notification["Notification worker"]
  node_notification_store[("Notification database")]
end

subgraph group_messaging["Messaging contracts"]
  node_contracts["Saga messages<br/>[Messages.cs]"]
end

node_client(("Client"))
node_broker["RabbitMQ"]

node_client -->|"submits / polls"| node_order_api
node_order_api -->|"reads and writes"| node_order_store
node_order_api -->|"publishes order"| node_broker
node_broker -->|"delivers order"| node_saga
node_saga -->|"persists state"| node_saga_store
node_saga -->|"sends commands"| node_broker
node_broker -->|"delivers inventory command"| node_inventory
node_inventory -->|"reads and updates"| node_inventory_store
node_inventory -->|"publishes result"| node_broker
node_broker -->|"delivers inventory result"| node_saga
node_broker -->|"delivers charge command"| node_payment
node_payment -->|"persists payment"| node_payment_store
node_payment -->|"publishes result"| node_broker
node_broker -->|"delivers payment result"| node_saga
node_saga -->|"publishes status"| node_broker
node_broker -->|"delivers status"| node_order_api
node_broker -->|"delivers status"| node_notification
node_notification -->|"records status"| node_notification_store
node_contracts -->|"defines messages"| node_order_api
node_contracts -->|"defines messages"| node_saga
node_contracts -->|"defines messages"| node_inventory
node_contracts -->|"defines messages"| node_payment
node_contracts -->|"defines messages"| node_notification

click node_order_api "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Order.Api/Program.cs"
click node_order_store "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Order.Api/Persistence/OrderDbContext.cs"
click node_saga "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Orchestrator/OrderSagaStateMachine.cs"
click node_saga_store "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Orchestrator/Persistence/SagaDbContext.cs"
click node_inventory "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Inventory.Worker/Consumers/ReserveInventoryConsumer.cs"
click node_inventory_store "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Inventory.Worker/Persistence/InventoryDbContext.cs"
click node_payment "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Payment.Worker/Consumers/ChargePaymentConsumer.cs"
click node_payment_store "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Payment.Worker/Persistence/PaymentDbContext.cs"
click node_notification "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Notification.Worker/Consumers/OrderStatusChangedConsumer.cs"
click node_notification_store "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Notification.Worker/Persistence/NotificationDbContext.cs"
click node_contracts "https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Contracts/Messages.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_order_api,node_order_store,node_client toneBlue
class node_saga,node_saga_store toneAmber
class node_inventory,node_inventory_store,node_payment,node_payment_store,node_notification,node_notification_store toneMint
class node_contracts toneRose
class node_broker toneIndigo
```

## Components

### Order API

- [Order HTTP API](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Order.Api/Program.cs): `src/Order.Api/Program.cs`
- [Order database](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Order.Api/Persistence/OrderDbContext.cs): `src/Order.Api/Persistence/OrderDbContext.cs`

### Saga orchestration

- [Order Saga](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Orchestrator/OrderSagaStateMachine.cs): `src/Saga.Orchestrator/OrderSagaStateMachine.cs`
- [Saga database](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Orchestrator/Persistence/SagaDbContext.cs): `src/Saga.Orchestrator/Persistence/SagaDbContext.cs`

### Domain workers

- [Inventory worker](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Inventory.Worker/Consumers/ReserveInventoryConsumer.cs): `src/Inventory.Worker/Consumers/ReserveInventoryConsumer.cs`
- [Inventory database](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Inventory.Worker/Persistence/InventoryDbContext.cs): `src/Inventory.Worker/Persistence/InventoryDbContext.cs`
- [Payment worker](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Payment.Worker/Consumers/ChargePaymentConsumer.cs): `src/Payment.Worker/Consumers/ChargePaymentConsumer.cs`
- [Payment database](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Payment.Worker/Persistence/PaymentDbContext.cs): `src/Payment.Worker/Persistence/PaymentDbContext.cs`
- [Notification worker](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Notification.Worker/Consumers/OrderStatusChangedConsumer.cs): `src/Notification.Worker/Consumers/OrderStatusChangedConsumer.cs`
- [Notification database](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Notification.Worker/Persistence/NotificationDbContext.cs): `src/Notification.Worker/Persistence/NotificationDbContext.cs`

### Messaging contracts

- [Saga messages](https://github.com/sapkalsachin2011/sagapattern/blob/main/src/Saga.Contracts/Messages.cs): `src/Saga.Contracts/Messages.cs`

### Other components

- **Client**
- **RabbitMQ**

## Connections

- Client → Order HTTP API: submits / polls
- Order HTTP API → Order database: reads and writes
- Order HTTP API → RabbitMQ: publishes order
- RabbitMQ → Order Saga: delivers order
- Order Saga → Saga database: persists state
- Order Saga → RabbitMQ: sends commands
- RabbitMQ → Inventory worker: delivers inventory command
- Inventory worker → Inventory database: reads and updates
- Inventory worker → RabbitMQ: publishes result
- RabbitMQ → Order Saga: delivers inventory result
- RabbitMQ → Payment worker: delivers charge command
- Payment worker → Payment database: persists payment
- Payment worker → RabbitMQ: publishes result
- RabbitMQ → Order Saga: delivers payment result
- Order Saga → RabbitMQ: publishes status
- RabbitMQ → Order HTTP API: delivers status
- RabbitMQ → Notification worker: delivers status
- Notification worker → Notification database: records status
- Saga messages → Order HTTP API: defines messages
- Saga messages → Order Saga: defines messages
- Saga messages → Inventory worker: defines messages
- Saga messages → Payment worker: defines messages
- Saga messages → Notification worker: defines messages
