# rafaelbergo/sistemasdistribuidos3 architecture

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

- Interactive diagram: https://gitdiagram.com/rafaelbergo/sistemasdistribuidos3
- Repository: https://github.com/rafaelbergo/sistemasdistribuidos3

## Overview

This repository implements a signed-message e-commerce system of .NET services. The main workflow accepts an order, checks product details through the inventory API, publishes the order event, reserves stock, and—when stock is available—starts payment processing; a webhook handles later payment updates. Separate catalog, promotions, delivery, and promotion-consumer applications are also present. The sampled files show the order, inventory, and payment paths; some other service behavior is known only from the source index, so those links are omitted where their runtime wiring is not evidenced.

Main entry points: [`MS.Estoque/Services/EstoqueConsumerService.cs`](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Services/EstoqueConsumerService.cs) (Inventory consumer), [`MS.Pagamento/Services/PagamentoConsumerService.cs`](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Services/PagamentoConsumerService.cs) (Payment consumer), [`MS.Principal/Controllers/PedidosController.cs`](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Principal/Controllers/PedidosController.cs) (Order API), [`Foundation/SignatureService.cs`](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/SignatureService.cs) (Signature service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commerce["Order and catalog"]
  node_principal["Order API"]
  node_catalog_api["Catalog API"]
end

subgraph group_fulfillment["Fulfillment services"]
  node_stock_api["Inventory API"]
  node_stock_worker["Inventory consumer"]
  node_stock_manager["Inventory manager<br/>[EstoqueManager.cs]"]
  node_payment_worker["Payment consumer"]
  node_payment_manager["Pending payments"]
  node_webhook["Payment webhook"]
  node_delivery["Delivery service<br/>[Program.cs]"]
end

subgraph group_shared["Shared messaging and security"]
  node_order_data["Order contracts<br/>[PedidoCriado.cs]"]
  node_request_data["Order request<br/>[PedidoRequest.cs]"]
  node_catalog_data["Catalog contracts"]
  node_stock_data["Stock records<br/>[ProdutoEstoque.cs]"]
  node_promotion_data["Promotion contract<br/>[Promocao.cs]"]
  node_publisher["Signed event publisher"]
  node_message["Signed message envelope<br/>[Message.cs]"]
  node_signature["Signature service"]
  node_key_management["Key management<br/>[KeyManagement.cs]"]
  node_key_config["Key configuration<br/>[KeyConfig.cs]"]
end

subgraph group_promotions["Promotions"]
  node_promotions_service["Promotions service<br/>[Program.cs]"]
  node_consumer_c1["Promotion consumer C1<br/>[Program.cs]"]
  node_consumer_c2["Promotion consumer C2<br/>[Program.cs]"]
end

node_customer(("Order client"))
node_payment_provider["Mock payment API"]
node_broker["RabbitMQ"]

node_customer -->|"submits order"| node_principal
node_principal -->|"accepts"| node_request_data
node_principal -->|"checks products"| node_stock_api
node_principal -->|"deserializes"| node_catalog_data
node_principal -->|"builds order"| node_order_data
node_principal -->|"publishes order"| node_publisher
node_publisher -->|"signs content"| node_signature
node_publisher -->|"reads keys"| node_key_config
node_publisher -->|"wraps event"| node_message
node_publisher -->|"publishes event"| node_broker
node_stock_api -->|"delegates lookup"| node_stock_manager
node_stock_worker -->|"consumes orders"| node_broker
node_stock_worker -->|"deserializes envelope"| node_message
node_stock_worker -->|"processes order"| node_order_data
node_stock_worker -->|"verifies signature"| node_signature
node_stock_worker -->|"reads key paths"| node_key_config
node_stock_worker -->|"reserves stock"| node_stock_manager
node_stock_worker -->|"publishes stock result"| node_broker
node_stock_manager -->|"stores quantities"| node_stock_data
node_payment_worker -->|"consumes stock result"| node_broker
node_payment_worker -->|"deserializes envelope"| node_message
node_payment_worker -->|"processes order"| node_order_data
node_payment_worker -->|"verifies signature"| node_signature
node_payment_worker -->|"reads key paths"| node_key_config
node_payment_worker -->|"records pending order"| node_payment_manager
node_payment_worker -->|"requests charge"| node_payment_provider
node_webhook -->|"updates payment"| node_payment_manager
node_webhook -->|"publishes event"| node_publisher
node_promotions_service -->|"uses promotions"| node_promotion_data
node_promotions_service -->|"uses envelope"| node_message
node_promotions_service -->|"uses signatures"| node_signature
node_consumer_c1 -->|"uses promotions"| node_promotion_data
node_consumer_c1 -->|"uses envelope"| node_message
node_consumer_c1 -->|"verifies signatures"| node_signature
node_consumer_c2 -->|"uses promotions"| node_promotion_data
node_consumer_c2 -->|"uses envelope"| node_message
node_consumer_c2 -->|"verifies signatures"| node_signature
node_key_management -.->|"supports key setup"| node_signature
node_delivery -.->|"handles events"| node_broker

click node_principal "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Principal/Controllers/PedidosController.cs"
click node_catalog_api "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Principal/Controllers/CatalogoController.cs"
click node_order_data "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/PedidoCriado.cs"
click node_request_data "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/PedidoRequest.cs"
click node_catalog_data "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/ProdutoCatalogoDto.cs"
click node_stock_api "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Controllers/ProdutosController.cs"
click node_stock_worker "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Services/EstoqueConsumerService.cs"
click node_stock_manager "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Services/EstoqueManager.cs"
click node_stock_data "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/ProdutoEstoque.cs"
click node_payment_worker "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Services/PagamentoConsumerService.cs"
click node_payment_manager "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Services/PagamentoManager.cs"
click node_webhook "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Controllers/WebhookController.cs"
click node_delivery "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Entrega/Program.cs"
click node_promotions_service "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Promocoes/Program.cs"
click node_consumer_c1 "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Consumidor.C1/Program.cs"
click node_consumer_c2 "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Consumidor.C2/Program.cs"
click node_promotion_data "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/Promocao.cs"
click node_publisher "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Services/RabbitMqPublisher.cs"
click node_message "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Message.cs"
click node_signature "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/SignatureService.cs"
click node_key_management "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Keys/KeyManagement.cs"
click node_key_config "https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Keys/KeyConfig.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_principal,node_catalog_api,node_customer toneBlue
class node_stock_api,node_stock_worker,node_stock_manager,node_payment_worker,node_payment_manager,node_webhook,node_delivery toneAmber
class node_order_data,node_request_data,node_catalog_data,node_stock_data,node_promotion_data,node_publisher,node_message,node_signature,node_key_management,node_key_config,node_payment_provider toneMint
class node_promotions_service,node_consumer_c1,node_consumer_c2 toneRose
class node_broker toneIndigo
```

## Components

### Order and catalog

- [Order API](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Principal/Controllers/PedidosController.cs): `MS.Principal/Controllers/PedidosController.cs`
- [Catalog API](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Principal/Controllers/CatalogoController.cs): `MS.Principal/Controllers/CatalogoController.cs`

### Fulfillment services

- [Inventory API](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Controllers/ProdutosController.cs): `MS.Estoque/Controllers/ProdutosController.cs`
- [Inventory consumer](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Services/EstoqueConsumerService.cs): `MS.Estoque/Services/EstoqueConsumerService.cs`
- [Inventory manager](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Estoque/Services/EstoqueManager.cs): `MS.Estoque/Services/EstoqueManager.cs`
- [Payment consumer](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Services/PagamentoConsumerService.cs): `MS.Pagamento/Services/PagamentoConsumerService.cs`
- [Pending payments](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Services/PagamentoManager.cs): `MS.Pagamento/Services/PagamentoManager.cs`
- [Payment webhook](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Pagamento/Controllers/WebhookController.cs): `MS.Pagamento/Controllers/WebhookController.cs`
- [Delivery service](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Entrega/Program.cs): `MS.Entrega/Program.cs`

### Shared messaging and security

- [Order contracts](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/PedidoCriado.cs): `Foundation/Models/PedidoCriado.cs`
- [Order request](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/PedidoRequest.cs): `Foundation/Models/PedidoRequest.cs`
- [Catalog contracts](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/ProdutoCatalogoDto.cs): `Foundation/Models/ProdutoCatalogoDto.cs`
- [Stock records](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/ProdutoEstoque.cs): `Foundation/Models/ProdutoEstoque.cs`
- [Promotion contract](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Models/Promocao.cs): `Foundation/Models/Promocao.cs`
- [Signed event publisher](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Services/RabbitMqPublisher.cs): `Foundation/Services/RabbitMqPublisher.cs`
- [Signed message envelope](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Message.cs): `Foundation/Message.cs`
- [Signature service](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/SignatureService.cs): `Foundation/SignatureService.cs`
- [Key management](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Keys/KeyManagement.cs): `Foundation/Keys/KeyManagement.cs`
- [Key configuration](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Foundation/Keys/KeyConfig.cs): `Foundation/Keys/KeyConfig.cs`

### Promotions

- [Promotions service](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/MS.Promocoes/Program.cs): `MS.Promocoes/Program.cs`
- [Promotion consumer C1](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Consumidor.C1/Program.cs): `Consumidor.C1/Program.cs`
- [Promotion consumer C2](https://github.com/rafaelbergo/sistemasdistribuidos3/blob/main/Consumidor.C2/Program.cs): `Consumidor.C2/Program.cs`

### Other components

- **Order client**
- **Mock payment API**
- **RabbitMQ**

## Connections

- Order client → Order API: submits order (evidence: `MS.Principal/Controllers/PedidosController.cs`)
- Order API → Order request: accepts (evidence: `MS.Principal/Controllers/PedidosController.cs`)
- Order API → Inventory API: checks products (evidence: `MS.Principal/Controllers/PedidosController.cs`)
- Order API → Catalog contracts: deserializes (evidence: `MS.Principal/Controllers/PedidosController.cs`)
- Order API → Order contracts: builds order (evidence: `MS.Principal/Controllers/PedidosController.cs`)
- Order API → Signed event publisher: publishes order (evidence: `MS.Principal/Controllers/PedidosController.cs`)
- Signed event publisher → Signature service: signs content (evidence: `Foundation/Services/RabbitMqPublisher.cs`)
- Signed event publisher → Key configuration: reads keys (evidence: `Foundation/Services/RabbitMqPublisher.cs`)
- Signed event publisher → Signed message envelope: wraps event (evidence: `Foundation/Services/RabbitMqPublisher.cs`)
- Signed event publisher → RabbitMQ: publishes event (evidence: `Foundation/Services/RabbitMqPublisher.cs`)
- Inventory API → Inventory manager: delegates lookup (evidence: `MS.Estoque/Controllers/ProdutosController.cs`)
- Inventory consumer → RabbitMQ: consumes orders (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory consumer → Signed message envelope: deserializes envelope (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory consumer → Order contracts: processes order (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory consumer → Signature service: verifies signature (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory consumer → Key configuration: reads key paths (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory consumer → Inventory manager: reserves stock (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory consumer → RabbitMQ: publishes stock result (evidence: `MS.Estoque/Services/EstoqueConsumerService.cs`)
- Inventory manager → Stock records: stores quantities (evidence: `MS.Estoque/Services/EstoqueManager.cs`)
- Payment consumer → RabbitMQ: consumes stock result (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment consumer → Signed message envelope: deserializes envelope (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment consumer → Order contracts: processes order (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment consumer → Signature service: verifies signature (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment consumer → Key configuration: reads key paths (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment consumer → Pending payments: records pending order (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment consumer → Mock payment API: requests charge (evidence: `MS.Pagamento/Services/PagamentoConsumerService.cs`)
- Payment webhook → Pending payments: updates payment (evidence: `MS.Pagamento/Controllers/WebhookController.cs`)
- Payment webhook → Signed event publisher: publishes event (evidence: `MS.Pagamento/Controllers/WebhookController.cs`)
- Promotions service → Promotion contract: uses promotions (evidence: `MS.Promocoes/Program.cs`)
- Promotions service → Signed message envelope: uses envelope (evidence: `MS.Promocoes/Program.cs`)
- Promotions service → Signature service: uses signatures (evidence: `MS.Promocoes/Program.cs`)
- Promotion consumer C1 → Promotion contract: uses promotions (evidence: `Consumidor.C1/Program.cs`)
- Promotion consumer C1 → Signed message envelope: uses envelope (evidence: `Consumidor.C1/Program.cs`)
- Promotion consumer C1 → Signature service: verifies signatures (evidence: `Consumidor.C1/Program.cs`)
- Promotion consumer C2 → Promotion contract: uses promotions (evidence: `Consumidor.C2/Program.cs`)
- Promotion consumer C2 → Signed message envelope: uses envelope (evidence: `Consumidor.C2/Program.cs`)
- Promotion consumer C2 → Signature service: verifies signatures (evidence: `Consumidor.C2/Program.cs`)
- Key management → Signature service: supports key setup
- Delivery service → RabbitMQ: handles events
