# dotnet-architecture/eshopondapr architecture

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

- Interactive diagram: https://gitdiagram.com/dotnet-architecture/eshopondapr
- Repository: https://github.com/dotnet-architecture/eshopondapr

## Overview

##### Main Components
- Frontend:
- Blazor web application (found under “src/Web/BlazorClient.Host” and “src/Web/BlazorClient”): This serves as the client interface.
- API Gateways and Aggregators:
- API gateway implemented via Envoy (located under “src/ApiGateways/Envoy”): Acts as a reverse proxy routing incoming external requests.
- Aggregator microservice for more complex workflows (located under “src/ApiGateways/Aggregators”): Consolidates data across multiple backend services.
- Core Microservices (each focusing on a distinct business capability):
- Basket Service (src/Services/Basket) – Manages shopping baskets.
- Catalog Service (src/Services/Catalog) – Manages product catalogs.
- Identity Service (src/Services/Identity) – Handles authentication and identity management.
- Ordering Service (src/Services/Ordering) – Manages order placement and processing.
- Payment Service (src/Services/Payment) – Handles payment transactions.
- Building Blocks and Cross-Cutting Concerns:
- Event Bus (in src/BuildingBlocks/EventBus): Implements asynchronous messaging (pub/sub) using Dapr’s supported messaging backends.
- Health Checks (in src/BuildingBlocks/Healthchecks): Monitors the health of Dapr sidecars and microservices.
- Infrastructural and Deployment Components:
- Dapr components (in the “dapr” folder): YAML definitions for pubsub, state store, secrets etc.
- Deployment scripts for Container Apps and Kubernetes (found in the “deploy” folder, including Bicep and Helm charts) which provide additional context on the environment.

##### Understanding Relationships and Interactions
- The Blazor frontend communicates with the API gateway (via Envoy) for both simple CRUD operations and more complex aggregated workflows.
- The API gateway directs requests to either:
- Directly interact with one of the core services (e.g., catalog service) or
- Route to the aggregator service which handles multi-step operations (by invoking one or more backend services).
- Core services (e.g., Basket, Catalog, Ordering, Payment) are built as independent microservices that communicate through direct synchronous calls (for simple tasks) and asynchronous events via the event bus. Dapr is used to facilitate this messaging and also provides side-car features like service invocation and state management.
- Dapr sidecars (configured via the dapr folder) are attached to each microservice instance, enabling them to abstract common patterns like pub/sub messaging.
- The infrastructure components (container apps, Kubernetes deployments) are configured using Bicep and Helm charts, ensuring that the deployment mirrors the microservices architecture and Dapr configuration.

##### Architectural Patterns and Design Principles
- Microservices decomposition: Each core service is self-contained and caters to a distinct business domain.
- API Gateway pattern: A gateway (via Envoy and aggregator microservice) abstracts the backend complexity from clients.
- Event-driven architecture: Asynchronous communication is supported using an event bus enabled by Dapr.
- Container-based deployment: Dockerfiles, container-app templates, and Kubernetes/Helm charts indicate a heavy reliance on containerization for deployment and scalability.
- Sidecar pattern: Usage of Dapr enables cross-cutting concerns without tightly coupling them into each service.

##### Instructing the Principal Software Engineer
- Clusters or grouping to indicate related functionalities (e.g., group all the identity, catalog, ordering, basket, and payment services together as core services).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        FE1["Blazor Client Host"]:::frontend
        FE2["Blazor Client"]:::frontend
    end

    %% API Gateway and Aggregator Layer
    subgraph "API Gateway / Aggregator"
        APIGW["API Gateway (Envoy)"]:::gateway
        AGGR["Aggregator Microservice"]:::gateway
    end

    %% Core Microservices Layer
    subgraph "Core Microservices"
        BASKET["Basket Service (Dapr-enabled)"]:::microservice
        CATALOG["Catalog Service"]:::microservice
        IDENTITY["Identity Service"]:::microservice
        ORDERING["Ordering Service"]:::microservice
        PAYMENT["Payment Service"]:::microservice
    end

    %% Infrastructure and Shared Services
    subgraph "Infrastructure & Shared Services"
        EVENTBUS["Event Bus"]:::infrastructure
        HEALTH["Health Checks"]:::infrastructure
        DAPR["Dapr Components"]:::infrastructure
    end

    %% Deployment Layer
    subgraph "Deployment"
        DEPLOY["Deployment Scripts"]:::deployment
    end

    %% Connections - Frontend to API Gateway
    FE1 -->|"sendsReq"| APIGW
    FE2 -->|"sendsReq"| APIGW

    %% Connections - API Gateway to Backend
    APIGW -->|"directCall"| CATALOG
    APIGW -->|"directCall"| BASKET
    APIGW -->|"directCall"| IDENTITY
    APIGW -->|"routesTo"| AGGR

    %% Connections - Aggregator to Core Services for complex workflows
    AGGR -->|"calls"| ORDERING
    AGGR -->|"calls"| PAYMENT

    %% Asynchronous event flow using Event Bus
    BASKET ---|"pubSub"| EVENTBUS
    EVENTBUS ---|"asyncCall"| ORDERING
    ORDERING ---|"pubSub"| EVENTBUS
    EVENTBUS ---|"asyncCall"| PAYMENT

    %% Dapr sidecar interactions for each core microservice
    BASKET ---|"usesDapr"| DAPR
    CATALOG ---|"usesDapr"| DAPR
    IDENTITY ---|"usesDapr"| DAPR
    ORDERING ---|"usesDapr"| DAPR
    PAYMENT ---|"usesDapr"| DAPR

    %% Deployment orchestrates infrastructure
    DEPLOY -->|"deploys"| DAPR
    DEPLOY -->|"deploys"| APIGW
    DEPLOY -->|"deploys"| AGGR
    DEPLOY -->|"deploys"| BASKET
    DEPLOY -->|"deploys"| CATALOG
    DEPLOY -->|"deploys"| IDENTITY
    DEPLOY -->|"deploys"| ORDERING
    DEPLOY -->|"deploys"| PAYMENT

    %% Click Events for Frontend
    click FE1 "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/Web/BlazorClient.Host"
    click FE2 "https://github.com/dotnet-architecture/eshopondapr/tree/main/src/Web/BlazorClient"

    %% Click Events for API Gateway and Aggregator
    click APIGW "https://github.com/dotnet-architecture/eshopondapr/tree/main/src/ApiGateways/Envoy"
    click AGGR "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/ApiGateways/Aggregators/Web.Shopping.HttpAggregator"

    %% Click Events for Core Microservices
    click BASKET "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/Services/Basket/Basket.API"
    click CATALOG "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/Services/Catalog/Catalog.API"
    click IDENTITY "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/Services/Identity/Identity.API"
    click ORDERING "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/Services/Ordering/Ordering.API"
    click PAYMENT "https://github.com/dotnet-architecture/eshopondapr/blob/main/src/Services/Payment/Payment.API"

    %% Click Events for Infrastructure & Shared Services
    click EVENTBUS "https://github.com/dotnet-architecture/eshopondapr/tree/main/src/BuildingBlocks/EventBus"
    click HEALTH "https://github.com/dotnet-architecture/eshopondapr/tree/main/src/BuildingBlocks/Healthchecks"
    click DAPR "https://github.com/dotnet-architecture/eshopondapr/tree/main/dapr"

    %% Click Event for Deployment
    click DEPLOY "https://github.com/dotnet-architecture/eshopondapr/tree/main/deploy"

    %% Styles
    classDef frontend fill:#C6E3FF,stroke:#036,stroke-width:2px;
    classDef gateway fill:#FFE0B2,stroke:#E65100,stroke-width:2px;
    classDef microservice fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef infrastructure fill:#F0F4C3,stroke:#827717,stroke-width:2px;
    classDef deployment fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;
```
