# turkayurkmez/ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/turkayurkmez/ecommerce
- Repository: https://github.com/turkayurkmez/ecommerce

## Overview

##### Project type and purpose
- This is a microservices-based e-commerce platform built on .NET 9, employing Domain-Driven Design, Clean Architecture, and event-driven communication.
- Separate bounded contexts for Basket, Catalog, and Identity services, plus shared building blocks and a message/Event bus for inter-service events.

##### File structure
- Top-level directories:
- src/BuildingBlocks – common utilities (Behaviors, Middleware, EventBus, MessageBroker)
- src/Services – three service folders: Basket, Catalog, Identity.
- Each service follows the Clean Architecture layers:
- .API (presentation / gRPC & HTTP endpoints)
- .Application (use-cases, MediatR commands & queries)
- .Domain (entities, domain events, interfaces)
- .Infrastructure (persistence, Redis or EF Core, event handlers)
- Infrastructure also contains configuration for Redis (Basket), SQL migrations (Catalog, Identity), RabbitMQ settings, and MassTransit publisher.

##### README for additional insights
- Confirms microservices using gRPC for inter-service calls, Redis for basket persistence, MediatR for domain events, and Clean Architecture layering.
- Mentions Docker Compose possibly used for orchestration, though not in file tree.

##### Main components and relationships
a. Components to show:
- Basket Service:
- API (HTTP/gRPC)
- Application (MediatR)
- Domain (ShoppingCart aggregate)
- Infra (Redis repository, domain event handlers)
- Redis instance
- Catalog Service:
- API (HTTP)
- Application (commands/queries)
- Domain (Product, Category aggregates)
- Infra (EF Core DbContext, SQL database)
- Identity Service:
- API (HTTP)
- Application (Auth, Roles, Users use cases)
- Domain (User, Role aggregates)
- Infra (EF Core DbContext, SQL database)
- Common Building Blocks:
- ECommerce.Common: middleware, behaviors, extensions
- ECommerce.EventBus: integration event definitions, RabbitMQ settings
- ECommerce.MessageBroker: publisher/consumer abstractions (MassTransit)
- External Infra:
- Redis cache
- RabbitMQ broker
- SQL Databases (CatalogDb, IdentityDb)
b. Relationships & interactions:
- API-layer receives HTTP or gRPC calls from front-end or other services.
- Application layer dispatches commands/queries to domain via MediatR.
- Domain events are raised and handled internally (persisted, side effects) and published as integration events via message broker.
- ECommerce.EventBus publishes/publishes to RabbitMQ.
- Other services subscribe (via ECommerce.MessageBroker consumers) to events (e.g., Basket listens for ProductPriceChanged).
- Services communicate via gRPC for synchronous calls (BasketGrpcService) when needed.
c. Architectural patterns/design principles:
- Clean Architecture (onion layering) per service
- Domain-Driven Design with aggregates and domain events
- CQRS style (commands/queries via MediatR)
- Event-driven async communication via RabbitMQ
- Distributed caching (Redis) for basket
d. Key technologies/frameworks:
- .NET 9, C# 12
- MediatR library
- gRPC (.proto definitions in Basket)
- MassTransit for RabbitMQ integration
- StackExchange.Redis
- Entity Framework Core for SQL persistence
- Newtonsoft.Json for serialization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Shared Building Blocks
    subgraph "Shared Building Blocks"
        direction TB
        Common["ECommerce.Common"]:::building
        EventBus["ECommerce.EventBus"]:::building
        MessageBroker["ECommerce.MessageBroker"]:::building
    end

    %% RabbitMQ Broker
    RabbitMQ["RabbitMQ Broker"]:::broker

    %% Services
    subgraph "Basket Service"
        direction TB
        BAPI["Basket.API"]:::api
        BApp["Basket.Application"]:::app
        BDom["Basket.Domain"]:::domain
        BInfra["Basket.Infrastructure"]:::infra
        Redis["Redis Cache"]:::db
    end

    subgraph "Catalog Service"
        direction TB
        CAPI["Catalog.API"]:::api
        CApp["Catalog.Application"]:::app
        CDom["Catalog.Domain"]:::domain
        CInfra["Catalog.Infrastructure"]:::infra
        CatDB["Catalog SQL DB"]:::db
    end

    subgraph "Identity Service"
        direction TB
        IAPI["Identity.API"]:::api
        IApp["Identity.Application"]:::app
        IDom["Identity.Domain"]:::domain
        IInfra["Identity.Infrastructure"]:::infra
        IdDB["Identity SQL DB"]:::db
    end

    %% Synchronous and internal flows
    BAPI -->|"HTTP/gRPC"| BApp
    BApp -->|"MediatR"| BDom
    BDom -->|"Domain Events"| BInfra
    BInfra -->|"Persist"| Redis

    CAPI -->|"HTTP/JSON"| CApp
    CApp -->|"MediatR"| CDom
    CDom -->|"Domain Events"| CInfra
    CInfra -->|"Persist"| CatDB

    IAPI -->|"HTTP/JSON"| IApp
    IApp -->|"MediatR"| IDom
    IDom -->|"Domain Events"| IInfra
    IInfra -->|"Persist"| IdDB

    %% Event Bus integration
    BInfra -->|"Publish AMQP"| RabbitMQ
    CInfra -->|"Publish AMQP"| RabbitMQ
    IInfra -->|"Publish AMQP"| RabbitMQ

    RabbitMQ -->|"Consume"| BInfra
    RabbitMQ -->|"Consume"| CInfra
    RabbitMQ -->|"Consume"| IInfra

    %% Shared block usage
    Common --> BAPI
    Common --> CAPI
    Common --> IAPI
    Common --> BApp
    Common --> CApp
    Common --> IApp

    EventBus --> BInfra
    EventBus --> CInfra
    EventBus --> IInfra

    MessageBroker --> BInfra
    MessageBroker --> CInfra
    MessageBroker --> IInfra

    %% Click Events
    click Common "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.Common"
    click EventBus "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.EventBus"
    click MessageBroker "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.MessageBroker"
    click BAPI "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Basket/ECommerce.Basket.API"
    click BApp "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Basket/ECommerce.Basket.Application"
    click BDom "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Basket/ECommerce.Basket.Domain"
    click BInfra "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Basket/ECommerce.Basket.Infrastructure"
    click CAPI "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Catalog/Catalog.API"
    click CApp "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Catalog/Catalog.Application"
    click CDom "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Catalog/Catalog.Domain"
    click CInfra "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Catalog/Catalog.Infrastructure"
    click IAPI "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Identity/ECommerce.Identity.API"
    click IApp "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Identity/ECommerce.Identity.Application"
    click IDom "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Identity/ECommerce.Identity.Domain"
    click IInfra "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Identity/ECommerce.Identity.Infrastructure"
    click Redis "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Basket/ECommerce.Basket.Infrastructure/Repositories/RedisBasketRepository.cs"
    click CatDB "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Catalog/Catalog.Infrastructure/Persistence/CatalogDbContext.cs"
    click CInfra "https://github.com/turkayurkmez/ecommerce/tree/master/src/Services/Catalog/Catalog.Infrastructure/Migrations"
    click IdDB "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Identity/ECommerce.Identity.Infrastructure/Persistence/IdentityDbContext.cs"
    click IInfra "https://github.com/turkayurkmez/ecommerce/tree/master/src/Services/Identity/ECommerce.Identity.Infrastructure/Migrations"
    click MessageBroker "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.MessageBroker/Implementations/MassTransitPublisher.cs"
    click EventBus "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.EventBus/Settings/RabbitMqSettings.cs"
    click EventBus "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.EventBus/Extensions/EventBusExtensions.cs"
    click Common "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.Common/Middleware/ExceptionHandlingMiddleware.cs"
    click Common "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.Common/Behaviors/LoggingBehavior.cs"
    click Common "https://github.com/turkayurkmez/ecommerce/blob/master/src/BuildingBlocks/ECommerce.Common/Behaviors/ValidationBehavior.cs"
    click BAPI "https://github.com/turkayurkmez/ecommerce/blob/master/src/Services/Basket/ECommerce.Basket.API/Protos/basket.proto"

    %% Styles
    classDef api fill:#D6EAF8,stroke:#21618C;
    classDef app fill:#FCF3CF,stroke:#B7950B;
    classDef domain fill:#E8DAEF,stroke:#7D3C98;
    classDef infra fill:#D5F5E3,stroke:#239B56;
    classDef building fill:#FADBD8,stroke:#C0392B;
    classDef db fill:#ABEBC6,stroke:#196F3D;
    classDef broker fill:#FDEDEC,stroke:#922B21;
```
