# ronaldofm/eshopmicroservices architecture

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

- Interactive diagram: https://gitdiagram.com/ronaldofm/eshopmicroservices
- Repository: https://github.com/ronaldofm/eshopmicroservices

## Overview

##### Main Components
- API Gateway: Represent the YARP API gateway (src/ApiGateways/YarpApiGateway) which acts as the entry point for external requests and forwards them to respective microservices.
- Microservices: Include components for each service – Basket, Catalog, Discount (gRPC based), and Ordering – as separate nodes. Each service has its own endpoints, business logic, and data access layers.
- Shared Building Blocks: Show the BuildingBlocks libraries which include common messaging components (MassTransit integration, CQRS elements, exception and validation behaviors). These provide shared infrastructure and design patterns leveraged by the microservices.
- Messaging/Event Bus: Highlight the event-driven pieces – integration events like BasketCheckoutEvent and corresponding handlers – to show how services communicate asynchronously (for example, from Ordering’s event handlers to BuildingBlocks.Messaging).

##### Relationships and Interactions
- Inter-service communication through messaging (e.g., integration events) that connect services via a message bus (represented by BuildingBlocks/Messaging with MassTransit extensions).
- API communication from the Web Application to the API Gateway and from the gateway to microservices.
- Database/repository interactions within each service (data layer) and any caching mechanisms if applicable (e.g., CachedBasketRepository).

##### Architectural Patterns and Design Principles
- Microservices Architecture: Clearly display each service as an autonomous component with its own bounded context.
- CQRS: Note that some services use the Command Query Responsibility Segregation pattern (as seen in the BuildingBlocks/CQRS folder and throughout the service endpoint implementations).
- Event-Driven Communication: Emphasize the usage of integration events and event handlers that support asynchronous processing between services.
- Containerization: Since several Dockerfiles and docker-compose files are present, mention that container orchestration is employed for deployment.

##### Relevant Technologies
- YARP for the API Gateway
- .NET Core / ASP.NET Core (as evident from .csproj files and Program.cs files)
- MassTransit for messaging
- gRPC (e.g., in Discount.Grpc service)
- Docker and docker-compose for containerization
- Likely Entity Framework Core for data access (as suggested by Migrations and ApplicationDbContext)

##### Detailed Elements
- HTTP or gRPC traffic flows from the API gateway to services.
- Event communication paths between services (e.g., BasketCheckoutEvent flow to Ordering).
- Data flow to/from databases or repositories.
- Application layers (UI, API, Business Logic, Data)
- Synchronous vs. asynchronous communication links

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        SW["Shopping.Web"]:::webApp
    end

    %% API Routing Layer
    subgraph "API Routing Layer"
        YARP["YARP API Gateway"]:::apiGateway
    end

    %% Microservices Layer
    subgraph "Microservices"
        BS["Basket Service"]:::service
        Cat["Catalog Service"]:::service
        DS["Discount Service (gRPC)"]:::service
        subgraph "Ordering Service"
            OA["Ordering API"]:::service
            OAPP["Ordering Application"]:::service
            ODOM["Ordering Domain"]:::service
            OINF["Ordering Infrastructure"]:::service
        end
    end

    %% Shared & Messaging Layer
    subgraph "Shared & Messaging"
        BB["BuildingBlocks (CQRS, Behaviors, Exceptions)"]:::shared
        Msg["Messaging (MassTransit)"]:::messaging
    end

    %% Data Persistence Layer
    subgraph "Data Persistence"
        BD["Basket Repository"]:::database
        CD["Catalog Initial Data"]:::database
        DD["Discount Context"]:::database
        OD["ApplicationDbContext"]:::database
    end

    %% Relationships
    SW -->|"HTTP"| YARP
    YARP -->|"routes"| BS
    YARP -->|"routes"| Cat
    YARP -->|"routes"| DS
    YARP -->|"routes"| OA

    BS -->|"reads/writes"| BD
    Cat -->|"loads"| CD
    DS -->|"accesses"| DD
    OAPP -->|"queries"| OD

    BS -->|"triggersBasketCheckoutEvent"| Msg
    Msg -->|"notifies"| OA

    BS ---|"uses"| BB
    Cat ---|"uses"| BB
    DS ---|"uses"| BB
    OA ---|"uses"| BB
    OAPP ---|"uses"| BB
    ODOM ---|"uses"| BB
    OINF ---|"uses"| BB

    %% Click Events
    click YARP "https://github.com/ronaldofm/eshopmicroservices/tree/main/src/ApiGateways/YarpApiGateway"
    click BS "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Basket/Basket.API"
    click Cat "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API"
    click DS "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Discount/Discount.Grpc"
    click OA "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Ordering/Ordering.API"
    click OAPP "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Ordering/Ordering.Application"
    click ODOM "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Ordering/Ordering.Domain"
    click OINF "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/Services/Ordering/Ordering.Infrastructure"
    click BB "https://github.com/ronaldofm/eshopmicroservices/tree/main/src/BuildingBlocks"
    click Msg "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/BuildingBlocks/BuildingBlocks.Messaging"
    click SW "https://github.com/ronaldofm/eshopmicroservices/blob/main/src/WebApps/Shopping.Web"

    %% Styles
    classDef webApp fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef apiGateway fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef service fill:#d5f5e3,stroke:#239b56,stroke-width:2px;
    classDef shared fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef messaging fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef database fill:#d6eaf8,stroke:#2e86c1,stroke-width:2px;
```
