# alperenkucukali/dotnet-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/alperenkucukali/dotnet-microservices
- Repository: https://github.com/alperenkucukali/dotnet-microservices

## Overview

##### Project Type & Purpose
- This is a .NET 8 sample Distributed Bank using a microservices architecture.
- It demonstrates DDD, CQRS, MediatR, FluentValidation, AutoMapper, gRPC, event‐driven communication (RabbitMQ/MassTransit), API gateway (Ocelot), containerization (Docker), centralized logging (ELK), health checks, resilience (Polly), and multiple databases (PostgreSQL, MongoDB).

##### High‐Level Components (from file tree & README)
- API Gateway: OcelotApiGateway
- Microservices (each following Clean Architecture & DDD)
- Customer
· REST API (Customer.API)
· gRPC Server (Customer.GRPC)
· PostgreSQL (via EF Core)
- Account
· REST API (Account.API)
· Consumes Customer gRPC
· Publishes transaction events to RabbitMQ
· PostgreSQL (via EF Core)
- Transaction
· REST API (Transaction.API)
· Consumes RabbitMQ events
· MongoDB
- WebStatus: ASP.NET MVC status‐page UI
- Shared Building Blocks: Common.Logging (SeriLogger), EventBus.Messages (integration contracts)
- Infrastructure & Support
- RabbitMQ (MassTransit)
- PostgreSQL, MongoDB
- ELK Stack (Elasticsearch, Logstash, Kibana)
- Portainer, pgAdmin
- Docker Compose setup

##### Architectural Patterns & Interactions
- API Gateway routes external HTTP clients to service REST endpoints.
- Customer gRPC Server offers strongly-typed inter-service calls; consumed by Account API.
- Account publishes IntegrationBaseEvent messages to a RabbitMQ exchange; Transaction API hosts a MassTransit consumer.
- Each microservice implements CQRS via MediatR: Commands, Queries, Behaviours, Validators.
- Data stores are isolated per service (PostgreSQL for Customer/Account; MongoDB for Transaction).
- Centralized logging streams to ELK; health checks expose readiness.
- Resilience on outbound HTTP calls via IHttpClientFactory + Polly (retry, circuit breaker).

##### Final Checklist
– [ ] All major components labeled
– [ ] Callouts for Clean Architecture layers and shared blocks
– [ ] Docker Compose orchestration overview
– [ ] Health checks and logging flows

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Browser["Browser / API Consumer"]:::external

    %% API Gateway
    Gateway["OcelotApiGateway"]:::gateway
    Browser -->|"HTTP/REST"| Gateway
    click Gateway "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/ApiGateways/OcelotApiGateway/OcelotApiGateway.csproj"

    %% Docker Compose orchestrates all
    subgraph "Docker Compose" 
        direction TB

        %% Customer Service
        subgraph "Customer Service"
            direction TB
            CustomerAPI["Customer.API\n(MediatR, EF Core)"]:::micro
            CustomerGRPC["Customer.GRPC\n(gRPC Server)"]:::grpc
            CustomerDB[(PostgreSQL)]:::db

            Gateway -->|"REST/HTTP"| CustomerAPI
            CustomerAPI --> CustomerDB
            click CustomerAPI "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Customer/Customer.API/Customer.API.csproj"
            click CustomerGRPC "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Customer/Customer.GRPC/Customer.GRPC.csproj"
            click CustomerDB "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Customer/Customer.Infrastructure/Customer.Infrastructure.csproj"
        end

        %% Account Service
        subgraph "Account Service"
            direction TB
            AccountAPI["Account.API\n(MediatR, EF Core, MassTransit)"]:::micro
            AccountApp["Account.Application"]:::module
            AccountDomain["Account.Domain"]:::module
            AccountInfra["Account.Infrastructure"]:::module
            AccountDB[(PostgreSQL)]:::db

            Gateway -->|"REST/HTTP"| AccountAPI
            AccountAPI --> AccountApp
            AccountApp --> AccountDomain
            AccountDomain --> AccountInfra
            AccountAPI --> AccountDB
            AccountAPI -->|"gRPC"| CustomerGRPC
            AccountAPI -->|"AMQP"| RabbitMQ
            click AccountAPI "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Account/Account.API/Account.API.csproj"
            click AccountApp "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Account/Account.Application/Account.Application.csproj"
            click AccountDomain "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Account/Account.Domain/Account.Domain.csproj"
            click AccountInfra "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Account/Account.Infrastructure/Account.Infrastructure.csproj"
        end

        %% Transaction Service
        subgraph "Transaction Service"
            direction TB
            TransactionAPI["Transaction.API\n(MediatR, MongoDB, MassTransit Consumer)"]:::micro
            TransactionGRPC["Transaction.GRPC"]:::grpc
            TransactionMongo[(MongoDB)]:::db

            Gateway -->|"REST/HTTP"| TransactionAPI
            TransactionAPI --> TransactionMongo
            RabbitMQ -->|"AMQP"| TransactionAPI
            click TransactionAPI "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Transaction/Transaction.API/Transaction.API.csproj"
            click TransactionGRPC "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Transaction/Transaction.GRPC/Transaction.GRPC.csproj"
            click TransactionMongo "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Transaction/Transaction.API/Data/TransactionContext.cs"
            click TransactionAPI "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/Services/Transaction/Transaction.API/EventBusConsumer/AccountTransactionConsumer.cs"
        end

    end

    %% Message Broker
    RabbitMQ[(RabbitMQ)]:::broker

    %% Shared Building Blocks
    subgraph "Shared Building Blocks"
        direction TB
        Logging["Common.Logging\n(SeriLogger)"]:::shared
        Contracts["EventBus.Messages"]:::shared
        click Logging "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/BuildingBlocks/Common.Logging/SeriLogger.cs"
        click Contracts "https://github.com/alperenkucukali/dotnet-microservices/blob/master/src/BuildingBlocks/EventBus.Messages/EventBus.Messages.csproj"
    end

    %% Platform Infrastructure
    subgraph "Platform Infrastructure"
        direction TB
        ELK["ELK Stack\n(Elasticsearch, Logstash, Kibana)"]:::infra
        Portainer["Portainer"]:::infra
        pgAdmin["pgAdmin"]:::infra
        HealthMonitor["Health Monitor UI"]:::infra
        Logging --> ELK
        CustomerAPI -->|"Logs"| ELK
        AccountAPI -->|"Logs"| ELK
        TransactionAPI -->|"Logs"| ELK
    end

    %% Health Checks
    CustomerAPI -.->|"Health| readiness"| HealthMonitor
    CustomerGRPC -.->|"Health| readiness"| HealthMonitor
    AccountAPI -.->|"Health| readiness"| HealthMonitor

    %% gRPC Inter-service
    AccountAPI -->|"gRPC| Customer Service"| CustomerGRPC

    %% Legend
    classDef external fill:#ffffff,stroke:#999,stroke-width:1px;
    classDef gateway fill:#a292f8,stroke:#333,stroke-width:1px;
    classDef micro fill:#8fbce6,stroke:#333,stroke-width:1px;
    classDef grpc fill:#a8e6a3,stroke:#333,stroke-width:1px;
    classDef db fill:#f5b042,stroke:#333,stroke-width:1px;
    classDef broker fill:#e6c449,stroke:#333,stroke-width:1px;
    classDef shared fill:#d3d3d3,stroke:#333,stroke-width:1px;
    classDef infra fill:#cccccc,stroke:#333,stroke-width:1px;
    classDef module fill:#c2d6d6,stroke:#333,stroke-width:1px;
```
