# mehmetozkaya/eshopmicroservices-udemy-sections architecture

> Architecture diagram of the GitHub repository mehmetozkaya/eshopmicroservices-udemy-sections, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mehmetozkaya/eshopmicroservices-udemy-sections
- Repository: https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections

## Overview

##### Project Type & Purpose
- This is a full-stack, e-commerce “EShopMicroservices” reference implementation built in .NET.
- It demonstrates a microservices architecture featuring Catalog, Basket, Discount (gRPC), and Ordering services, working together via synchronous HTTP calls (for queries/commands) and asynchronous events (RabbitMQ via MassTransit).
- A YARP API Gateway fronts the services, and a Razor Pages web app (Shopping.Web) provides the UI.

##### Key Architectural Components
a. Client Layer
- Shopping.Web (Razor Pages) – invokes REST/gRPC endpoints via HTTP clients.
b. API Gateway
- YarpApiGateway – routes HTTP traffic to appropriate microservices; handles cross-cutting concerns (CORS, authentication).
c. Microservices
- Catalog.API (HTTP/REST + EF Core/PostgreSQL)
- Basket.API (HTTP/REST + Redis)
- Discount.Grpc (gRPC + EF Core/SQLite or PostgreSQL)
- Ordering.API (HTTP/REST + EF Core/SQL Server)
d. Messaging Infrastructure
- MassTransit + RabbitMQ broker – carries IntegrationEvents (e.g., BasketCheckoutEvent) to decouple Basket and Ordering.
e. Datastores
- Redis – Basket cache
- Relational DBs (PostgreSQL, SQL Server, SQLite) – persisted state per service
f. Shared Libraries
- BuildingBlocks (CQRS abstractions, behaviors, exception handling, pagination)
- BuildingBlocks.Messaging (IntegrationEvent base, MassTransit extensions)

##### Interactions & Data Flows
- Synchronous HTTP/gRPC:
- UI → API Gateway → Catalog/Basket/Ordering services
- API Gateway → Discount.Grpc via gRPC client
- Asynchronous events:
- Basket.API publishes BasketCheckoutEvent → RabbitMQ → Ordering.Application consumes → creates order
- Data persistence per service: each service owns its database; no shared schema.
- IntegrationEvent library standardizes event payloads.

##### Architectural Patterns & Principles
- Microservices (bounded contexts per domain module)
- API Gateway pattern (YARP)
- Event-driven communication (pub/sub via RabbitMQ)
- CQRS for command/query separation within services via BuildingBlocks.CQRS
- Clean/vertical slice architecture: each service contains its own Controllers/Endpoints, Application (CQRS handlers), Domain (models/events), Infrastructure (EF Core, messaging), DI setup.
- Shared “BuildingBlocks” libraries for cross-cutting concerns (validation, logging, exception handling).

##### Detailed Capture
- Don’t just list components—show their interactions.
- Both synchronous (request/response) and asynchronous (event-driven) flows.
- Shared libraries to show code-reuse.
- Data ownership boundaries (each microservice has its own database).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    ShoppingWeb["Shopping.Web (Razor Pages)"]:::ui
    click ShoppingWeb "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/WebApps/Shopping.Web"

    %% API Gateway
    YarpApiGateway["YarpApiGateway (API Gateway)"]:::gateway
    click YarpApiGateway "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/tree/main/ApiGateways/YarpApiGateway"

    %% Microservices Layer
    subgraph "Catalog Service" 
        direction TB
        CatalogAPI["Catalog.API\n(HTTP/REST)"]:::service
        click CatalogAPI "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Catalog/Catalog.API"
        CatalogDB["PostgreSQL"]:::db
    end

    subgraph "Basket Service"
        direction TB
        BasketAPI["Basket.API\n(HTTP/REST)"]:::service
        click BasketAPI "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Basket/Basket.API"
        Redis["Redis"]:::db
    end

    subgraph "Discount Service"
        direction TB
        DiscountGrpc["Discount.Grpc\n(gRPC)"]:::service
        click DiscountGrpc "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Discount/Discount.Grpc"
        DiscountDB["SQLite/PostgreSQL"]:::db
    end

    subgraph "Ordering Service"
        direction TB
        OrderingAPI["Ordering.API\n(HTTP/REST)"]:::service
        click OrderingAPI "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Ordering/Ordering.API"
        OrderingApp["Ordering.Application"]:::service
        click OrderingApp "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Ordering/Ordering.Application"
        OrderingDomain["Ordering.Domain"]:::service
        click OrderingDomain "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Ordering/Ordering.Domain"
        OrderingInfra["Ordering.Infrastructure"]:::service
        click OrderingInfra "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/Services/Ordering/Ordering.Infrastructure"
        SqlServer["SQL Server"]:::db
    end

    %% Shared Libraries
    BuildingBlocks["BuildingBlocks\n(CQRS, behaviors)"]:::shared
    click BuildingBlocks "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/tree/main/BuildingBlocks/BuildingBlocks"
    MessagingLib["BuildingBlocks.Messaging\n(IntegrationEvent)"]:::shared
    click MessagingLib "https://github.com/mehmetozkaya/eshopmicroservices-udemy-sections/blob/main/BuildingBlocks/BuildingBlocks.Messaging"

    %% Messaging Broker
    RabbitMQ["RabbitMQ\n(MassTransit)"]:::messaging

    %% Flows - Synchronous
    ShoppingWeb -->|"HTTP/gRPC"| YarpApiGateway
    YarpApiGateway -->|"HTTP REST"| CatalogAPI
    YarpApiGateway -->|"HTTP REST"| BasketAPI
    YarpApiGateway -->|"HTTP REST"| OrderingAPI
    YarpApiGateway -->|"gRPC"| DiscountGrpc

    %% Data Stores connections
    CatalogAPI -->|"EF Core"| CatalogDB
    BasketAPI -->|"Redis Client"| Redis
    DiscountGrpc -->|"EF Core"| DiscountDB
    OrderingAPI -->|"Application→Infra"| OrderingApp
    OrderingApp -->|"Domain Models"| OrderingDomain
    OrderingInfra -->|"EF Core"| SqlServer

    %% Asynchronous events
    BasketAPI -->|"Publishes BasketCheckoutEvent"| RabbitMQ
    RabbitMQ -->|"Consumes|Ordering.Application"| OrderingApp

    %% Shared libraries consumption
    CatalogAPI -->|">" |BuildingBlocks
    BasketAPI -->|">" |BuildingBlocks
    DiscountGrpc -->|">" |BuildingBlocks
    OrderingAPI -->|">" |BuildingBlocks
    OrderingApp -->|">" |BuildingBlocks

    CatalogAPI -->|">" |MessagingLib
    BasketAPI -->|">" |MessagingLib
    DiscountGrpc -->|">" |MessagingLib
    OrderingApp -->|">" |MessagingLib

    %% Styles
    classDef ui fill:#a8d5ba,stroke:#333,stroke-width:1px;
    classDef gateway fill:#f7b267,stroke:#333,stroke-width:1px;
    classDef service fill:#5dade2,stroke:#333,stroke-width:1px;
    classDef db fill:#d7dbdd,stroke:#333,stroke-width:1px,shape:cylinder;
    classDef messaging fill:#f9e79f,stroke:#333,stroke-width:1px,shape:cloud;
    classDef shared fill:#af7ac5,stroke:#333,stroke-width:1px;
```
