# fer-dev-mx/eshopmicroservices architecture

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

- Interactive diagram: https://gitdiagram.com/fer-dev-mx/eshopmicroservices
- Repository: https://github.com/fer-dev-mx/eshopmicroservices

## Overview

##### Main Components
- BuildingBlocks Library:
- This common library (located under src/BuildingBlocks) defines shared behaviors (like LoggingBehavior and ValidationBehavior), interfaces (ICommand, IQuery, their handlers), and exception handling classes.
- It as a “Core Framework/Shared Libraries” component that is utilized by each microservice.

- Microservices:
- Basket.API (in src/Services/Basket): A RESTful API handling shopping cart operations. Highlight endpoints for deleting, retrieving, and storing baskets as distinct functions within the service.
- Catalog.API (in src/Services/Catalog): A RESTful service managing product catalog operations. It features endpoints for creating, updating, deleting, and searching products.
- Discount.Grpc (in src/Services/Discount): A gRPC-based service that provides discount or coupon-related functionalities. Its reliance on gRPC (seen with the .proto file) sets it apart.

- Data Access Components:
- Each service includes its own data layer (for example, BasketRepository and CachedBasketRepository for the Basket API, CatalogInitialData and Product models for Catalog, and DiscountContext for Discount) which may map to separate databases or storage modules.

- Deployment & Containerization:
- Dockerfiles for each service and docker-compose files that orchestrate the services. Represent a “Container/Orchestration” layer that shows how these services run in isolated containers.

##### Relationships and Interactions
- “Shared Libraries” (BuildingBlocks) as a foundation that supports the operations of each microservice.
- For Discount, demonstrate its role as a gRPC service. Indicate that other microservices or components might consume its API via gRPC calls.
- If applicable, indicate any inter-service communication (for example, if the Basket service needs to validate discount coupons, it might call the Discount service).

##### Architectural Patterns and Technologies
- The use of CQRS (as seen in the BuildingBlocks/CQRS folder) should be called out. Mark both command and query flows within the microservices where this pattern applies.
- Each service follows the API endpoint pattern where endpoints are defined (for example, in Basket/Basket.API/Basket subfolders and Catalog’s Products folders). Group these under the umbrella of “API Endpoints.”
- Docker and docker-compose indicate container orchestration; include these symbols to show deployment structure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client (HTTP)"]:::client

    %% Shared Libraries
    BuildingBlocks["BuildingBlocks (Shared Libraries)"]:::library

    %% Basket.API Service
    subgraph "Basket.API Service"
        BasketAPI["Basket.API"]:::rest
        subgraph "Basket Endpoints"
            DeleteBasket["DeleteBasket Endpoint"]:::rest
            GetBasket["GetBasket Endpoint"]:::rest
            StoreBasket["StoreBasket Endpoint"]:::rest
        end
        BasketData["Basket Data Store"]:::data
        BasketDocker["Basket Dockerfile"]:::docker
    end

    %% Catalog.API Service
    subgraph "Catalog.API Service"
        CatalogAPI["Catalog.API"]:::rest
        subgraph "Catalog Endpoints"
            CreateProduct["CreateProduct Endpoint"]:::rest
            UpdateProduct["UpdateProduct Endpoint"]:::rest
            DeleteProduct["DeleteProduct Endpoint"]:::rest
            GetProductByCategory["GetProductByCategory Endpoint"]:::rest
            GetProductById["GetProductById Endpoint"]:::rest
            GetProducts["GetProducts Endpoint"]:::rest
        end
        CatalogData["Catalog Data Store"]:::data
        CatalogDocker["Catalog Dockerfile"]:::docker
    end

    %% Discount gRPC Service
    subgraph "Discount gRPC Service"
        DiscountGrpc["Discount gRPC"]:::grpc
        subgraph "Discount Service Details"
            DiscountProto["Discount Protos"]:::grpc
            DiscountImpl["Discount Service Implementation"]:::grpc
        end
        DiscountData["Discount Data Store"]:::data
        DiscountDocker["Discount Dockerfile"]:::docker
    end

    %% Container Orchestration Layer
    subgraph "Container Orchestration"
        DockerCompose["Docker Compose Configs"]:::compose
    end

    %% Relationships

    %% Client calls REST APIs
    Client -->|"HTTP_call"| BasketAPI
    Client -->|"HTTP_call"| CatalogAPI

    %% Microservices use BuildingBlocks
    BasketAPI -->|"uses"| BuildingBlocks
    CatalogAPI -->|"uses"| BuildingBlocks
    DiscountGrpc -->|"integrates"| BuildingBlocks

    %% Basket.API: Endpoints associations
    BasketAPI -->|"exposes"| DeleteBasket
    BasketAPI -->|"exposes"| GetBasket
    BasketAPI -->|"exposes"| StoreBasket
    DeleteBasket -->|"accesses"| BasketData
    GetBasket -->|"accesses"| BasketData
    StoreBasket -->|"accesses"| BasketData

    %% Catalog.API: Endpoints associations
    CatalogAPI -->|"exposes"| CreateProduct
    CatalogAPI -->|"exposes"| UpdateProduct
    CatalogAPI -->|"exposes"| DeleteProduct
    CatalogAPI -->|"exposes"| GetProductByCategory
    CatalogAPI -->|"exposes"| GetProductById
    CatalogAPI -->|"exposes"| GetProducts
    CreateProduct -->|"accesses"| CatalogData
    UpdateProduct -->|"accesses"| CatalogData
    DeleteProduct -->|"accesses"| CatalogData
    GetProductByCategory -->|"accesses"| CatalogData
    GetProductById -->|"accesses"| CatalogData
    GetProducts -->|"accesses"| CatalogData

    %% Potential inter-service communication: Basket.API calls Discount gRPC
    BasketAPI -->|"calls_discount"| DiscountGrpc

    %% Discount gRPC internal relationship
    DiscountProto -->|"defines"| DiscountImpl
    DiscountImpl -->|"accesses"| DiscountData

    %% Containerization: Dockerfiles linked to Docker Compose
    BasketDocker -->|"orchestrated_by"| DockerCompose
    CatalogDocker -->|"orchestrated_by"| DockerCompose
    DiscountDocker -->|"orchestrated_by"| DockerCompose

    %% Styles
    classDef client fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef rest fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef grpc fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef library fill:#C0C0C0,stroke:#000,stroke-width:2px;
    classDef data fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef docker fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef compose fill:#E6E6FA,stroke:#000,stroke-width:2px;

    %% Click Events
    click BuildingBlocks "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/BuildingBlocks/BuildingBlocks"
    click BasketAPI "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Basket/Basket.API"
    click DeleteBasket "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Basket/Basket.API/Basket/DeleteBasket/DeleteBasketEndpoints.cs"
    click GetBasket "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Basket/Basket.API/Basket/GetBasket/GetBasketEndpoints.cs"
    click StoreBasket "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Basket/Basket.API/Basket/StoreBasket/StoreBasketEndpoints.cs"
    click BasketData "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/Services/Basket/Basket.API/Data"
    click CatalogAPI "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API"
    click CreateProduct "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API/Products/CreateProduct/CreateProductEndpoint.cs"
    click UpdateProduct "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API/Products/UpdateProduct/UpdateProductEndpoint.cs"
    click DeleteProduct "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API/Products/DeleteProduct/DeleteProductEndpoint.cs"
    click GetProductByCategory "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API/Products/GetProductByCategory/GetProductByCategoryEndpoint.cs"
    click GetProductById "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API/Products/GetProductById/GetProductByIdEndpoint.cs"
    click GetProducts "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Catalog/Catalog.API/Products/GetProducts/GetProductsEndpoint.cs"
    click CatalogData "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/Services/Catalog/Catalog.API/Data"
    click DiscountGrpc "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Discount/Discount.Grpc"
    click DiscountProto "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Discount/Discount.Grpc/Protos/discount.proto"
    click DiscountImpl "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/Services/Discount/Discount.Grpc/Services/DiscountService.cs"
    click DiscountData "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/Services/Discount/Discount.Grpc/Data"
    click BasketDocker "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/Services/Basket/Basket.API/Dockerfile"
    click CatalogDocker "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/Services/Catalog/Catalog.API/Dockerfile"
    click DiscountDocker "https://github.com/fer-dev-mx/eshopmicroservices/tree/main/src/Services/Discount/Discount.Grpc/Dockerfile"
    click DockerCompose "https://github.com/fer-dev-mx/eshopmicroservices/blob/main/src/docker-compose.yml"
```
