# belsaied/e-commercemicroservice architecture

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

- Interactive diagram: https://gitdiagram.com/belsaied/e-commercemicroservice
- Repository: https://github.com/belsaied/e-commercemicroservice

## Overview

This is a .NET e-commerce microservices backend. The primary flow is client traffic through Ocelot to catalog and basket APIs; basket pricing synchronously consults Discount, while checkout publishes a versioned event that Ordering consumes asynchronously and persists as an order. IdentityServer issues JWTs for protected requests. The graph preserves catalog browsing, basket management, discounts, checkout, order history, and the documented database boundaries. README descriptions support several links whose implementation was not sampled; those are shown as documented, not inferred from imports.

Main entry points: [`APIGateway/Ocelot.APIGateway/Program.cs`](https://github.com/belsaied/e-commercemicroservice/blob/master/APIGateway/Ocelot.APIGateway/Program.cs) (Ocelot gateway), [`services/Basket/Basket.API/Controllers/BasketController.cs`](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Basket/Basket.API/Controllers/BasketController.cs) (Basket API), [`services/Ordering/Ordering.Application/Handlers`](https://github.com/belsaied/e-commercemicroservice/tree/master/services/Ordering/Ordering.Application/Handlers) (Order handlers), [`Infrastructure/eShop.Identity/Program.cs`](https://github.com/belsaied/e-commercemicroservice/blob/master/Infrastructure/eShop.Identity/Program.cs) (IdentityServer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Access and identity"]
  node_gateway["Ocelot gateway<br/>[Program.cs]"]
  node_identity["IdentityServer<br/>[Program.cs]"]
end

subgraph group_catalog["Product catalog"]
  node_catalog_api["Catalog API"]
  node_catalog_handlers["Catalog query handlers<br/>[Queries]"]
  node_catalog_store["Catalog repository"]
  node_catalog_db[("MongoDB")]
end

subgraph group_basket["Basket and discounts"]
  node_basket_api["Basket API"]
  node_basket_handlers["Basket handlers<br/>[Handlers]"]
  node_basket_store[("Redis cart store")]
  node_discount_client["Discount gRPC client"]
  node_discount_api["Discount gRPC API<br/>[DiscountService.cs]"]
  node_discount_handlers["Discount handlers"]
  node_discount_store["Discount repository"]
  node_discount_db[("PostgreSQL")]
end

subgraph group_ordering["Checkout and orders"]
  node_ordering_consumer["Checkout consumers"]
  node_ordering_api["Ordering API"]
  node_ordering_handlers["Order handlers<br/>[Handlers]"]
  node_ordering_store["Order repository<br/>[OrderRepository.cs]"]
  node_ordering_db[("SQL Server")]
end

subgraph group_messaging["Event integration"]
  node_event_contracts["Checkout event contracts"]
  node_rabbitmq["RabbitMQ"]
end

node_client(("Client"))

node_client -->|"sends requests"| node_gateway
node_gateway -->|"routes catalog"| node_catalog_api
node_gateway -->|"routes basket"| node_basket_api
node_gateway -->|"routes orders"| node_ordering_api
node_identity -->|"issues JWTs"| node_client
node_gateway -->|"enforces auth"| node_identity
node_catalog_api -->|"dispatches queries"| node_catalog_handlers
node_catalog_handlers -->|"reads products"| node_catalog_store
node_catalog_store -->|"reads and writes"| node_catalog_db
node_basket_api -->|"dispatches commands"| node_basket_handlers
node_basket_handlers -->|"reads and writes"| node_basket_store
node_basket_api -->|"requests pricing"| node_discount_client
node_discount_client -->|"calls gRPC"| node_discount_api
node_discount_api -->|"dispatches query"| node_discount_handlers
node_discount_handlers -->|"reads coupon"| node_discount_store
node_discount_store -->|"reads and writes"| node_discount_db
node_basket_api -->|"creates checkout event"| node_event_contracts
node_basket_api -->|"publishes event"| node_rabbitmq
node_rabbitmq -->|"delivers event"| node_ordering_consumer
node_ordering_consumer -->|"dispatches checkout"| node_ordering_handlers
node_ordering_api -->|"dispatches requests"| node_ordering_handlers
node_ordering_handlers -->|"reads and writes"| node_ordering_store
node_ordering_store -->|"persists orders"| node_ordering_db

click node_gateway "https://github.com/belsaied/e-commercemicroservice/blob/master/APIGateway/Ocelot.APIGateway/Program.cs"
click node_identity "https://github.com/belsaied/e-commercemicroservice/blob/master/Infrastructure/eShop.Identity/Program.cs"
click node_catalog_api "https://github.com/belsaied/e-commercemicroservice/blob/master/services/catalog/Catalog.API/Controllers/CatalogController.cs"
click node_catalog_handlers "https://github.com/belsaied/e-commercemicroservice/tree/master/services/catalog/Catalog.Application/Handlers/Queries"
click node_catalog_store "https://github.com/belsaied/e-commercemicroservice/blob/master/services/catalog/Catalog.Infrastructure/Repositories/ProductRepository.cs"
click node_basket_api "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Basket/Basket.API/Controllers/BasketController.cs"
click node_basket_handlers "https://github.com/belsaied/e-commercemicroservice/tree/master/services/Basket/Basket.Application/Handlers"
click node_discount_client "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Basket/Basket.Application/GrpcServices/DiscountGrpcService.cs"
click node_discount_api "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Discount/Discount.API/Services/DiscountService.cs"
click node_discount_handlers "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Discount/Discount.Application/Handlers/Queries/GetDiscountQueryHandler.cs"
click node_discount_store "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Discount/Discount.Infrastructure/Repositories/DiscountRepository.cs"
click node_event_contracts "https://github.com/belsaied/e-commercemicroservice/blob/master/Infrastructure/EventBus.Messages/Events/BasketCheckoutEvent.cs"
click node_ordering_consumer "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Ordering/Ordering.API/EventBusConsumer/BasketOrderingConsumer.cs"
click node_ordering_api "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Ordering/Ordering.API/Controllers/OrdersController.cs"
click node_ordering_handlers "https://github.com/belsaied/e-commercemicroservice/tree/master/services/Ordering/Ordering.Application/Handlers"
click node_ordering_store "https://github.com/belsaied/e-commercemicroservice/blob/master/services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.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_gateway,node_identity,node_client toneBlue
class node_catalog_api,node_catalog_handlers,node_catalog_store,node_catalog_db toneAmber
class node_basket_api,node_basket_handlers,node_basket_store,node_discount_client,node_discount_api,node_discount_handlers,node_discount_store,node_discount_db toneMint
class node_ordering_consumer,node_ordering_api,node_ordering_handlers,node_ordering_store,node_ordering_db toneRose
class node_event_contracts,node_rabbitmq toneIndigo
```

## Components

### Access and identity

- [Ocelot gateway](https://github.com/belsaied/e-commercemicroservice/blob/master/APIGateway/Ocelot.APIGateway/Program.cs): `APIGateway/Ocelot.APIGateway/Program.cs`
- [IdentityServer](https://github.com/belsaied/e-commercemicroservice/blob/master/Infrastructure/eShop.Identity/Program.cs): `Infrastructure/eShop.Identity/Program.cs`

### Product catalog

- [Catalog API](https://github.com/belsaied/e-commercemicroservice/blob/master/services/catalog/Catalog.API/Controllers/CatalogController.cs): `services/catalog/Catalog.API/Controllers/CatalogController.cs`
- [Catalog query handlers](https://github.com/belsaied/e-commercemicroservice/tree/master/services/catalog/Catalog.Application/Handlers/Queries): `services/catalog/Catalog.Application/Handlers/Queries`
- [Catalog repository](https://github.com/belsaied/e-commercemicroservice/blob/master/services/catalog/Catalog.Infrastructure/Repositories/ProductRepository.cs): `services/catalog/Catalog.Infrastructure/Repositories/ProductRepository.cs`
- **MongoDB**

### Basket and discounts

- [Basket API](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Basket/Basket.API/Controllers/BasketController.cs): `services/Basket/Basket.API/Controllers/BasketController.cs`
- [Basket handlers](https://github.com/belsaied/e-commercemicroservice/tree/master/services/Basket/Basket.Application/Handlers): `services/Basket/Basket.Application/Handlers`
- **Redis cart store**
- [Discount gRPC client](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Basket/Basket.Application/GrpcServices/DiscountGrpcService.cs): `services/Basket/Basket.Application/GrpcServices/DiscountGrpcService.cs`
- [Discount gRPC API](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Discount/Discount.API/Services/DiscountService.cs): `services/Discount/Discount.API/Services/DiscountService.cs`
- [Discount handlers](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Discount/Discount.Application/Handlers/Queries/GetDiscountQueryHandler.cs): `services/Discount/Discount.Application/Handlers/Queries/GetDiscountQueryHandler.cs`
- [Discount repository](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Discount/Discount.Infrastructure/Repositories/DiscountRepository.cs): `services/Discount/Discount.Infrastructure/Repositories/DiscountRepository.cs`
- **PostgreSQL**

### Checkout and orders

- [Checkout consumers](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Ordering/Ordering.API/EventBusConsumer/BasketOrderingConsumer.cs): `services/Ordering/Ordering.API/EventBusConsumer/BasketOrderingConsumer.cs`
- [Ordering API](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Ordering/Ordering.API/Controllers/OrdersController.cs): `services/Ordering/Ordering.API/Controllers/OrdersController.cs`
- [Order handlers](https://github.com/belsaied/e-commercemicroservice/tree/master/services/Ordering/Ordering.Application/Handlers): `services/Ordering/Ordering.Application/Handlers`
- [Order repository](https://github.com/belsaied/e-commercemicroservice/blob/master/services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs): `services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs`
- **SQL Server**

### Event integration

- [Checkout event contracts](https://github.com/belsaied/e-commercemicroservice/blob/master/Infrastructure/EventBus.Messages/Events/BasketCheckoutEvent.cs): `Infrastructure/EventBus.Messages/Events/BasketCheckoutEvent.cs`
- **RabbitMQ**

### Other components

- **Client**

## Connections

- Client → Ocelot gateway: sends requests
- Ocelot gateway → Catalog API: routes catalog
- Ocelot gateway → Basket API: routes basket
- Ocelot gateway → Ordering API: routes orders
- IdentityServer → Client: issues JWTs
- Ocelot gateway → IdentityServer: enforces auth
- Catalog API → Catalog query handlers: dispatches queries
- Catalog query handlers → Catalog repository: reads products
- Catalog repository → MongoDB: reads and writes
- Basket API → Basket handlers: dispatches commands
- Basket handlers → Redis cart store: reads and writes
- Basket API → Discount gRPC client: requests pricing
- Discount gRPC client → Discount gRPC API: calls gRPC
- Discount gRPC API → Discount handlers: dispatches query
- Discount handlers → Discount repository: reads coupon
- Discount repository → PostgreSQL: reads and writes
- Basket API → Checkout event contracts: creates checkout event
- Basket API → RabbitMQ: publishes event
- RabbitMQ → Checkout consumers: delivers event
- Checkout consumers → Order handlers: dispatches checkout
- Ordering API → Order handlers: dispatches requests
- Order handlers → Order repository: reads and writes
- Order repository → SQL Server: persists orders
