# dpedwards/dotnet-core-micro-rabbit architecture

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

- Interactive diagram: https://gitdiagram.com/dpedwards/dotnet-core-micro-rabbit
- Repository: https://github.com/dpedwards/dotnet-core-micro-rabbit

## Overview

##### Project Type and Purpose
- This project implements a microservice architecture using .NET Core with a clear Domain Driven Design (DDD) approach.
- It spans multiple independent services, such as Banking and Transfer APIs, as well as a separate MVC web client.
- RabbitMQ is used as the centralized message bus to publish and subscribe for events and commands between services.
- The project is organized into several layers: Domain, Application, Data, API, and an MVC client.

##### Analyzing the File Structure
- Notice the distinct top-level project folders (e.g., MicroRabbit.Banking.Api, MicroRabbit.Transfer.Api, MicroRabbit.MVC) which represent separate services.
- There are dedicated projects for the Domain layers (e.g., MicroRabbit.Banking.Domain, MicroRabbit.Transfer.Domain) that include Models, Commands, Events, and Command/Event Handlers.
- The Application and Data layers in each bounded context (Banking and Transfer) reflect the separation of concerns (i.e., service interfaces and repositories).
- Infrastructure libraries such as MicroRabbit.Domain.Core, MicroRabbit.Infra.Bus, and MicroRabbit.Infra.IoC indicate the use of a central message bus and dependency injection for loose coupling.

##### Key Components
a. Banking Microservice:
- Banking API: Represented by MicroRabbit.Banking.Api (exposes endpoints via controllers), using a Startup configuration for dependency injection and middleware.
- Banking Application Layer: Contains the service (e.g., AccountService) and interfaces in MicroRabbit.Banking.Application.
- Banking Domain Layer: Contains domain models, commands (e.g., TransferCommand or CreateTransferCommand), and command handlers.
- Banking Data Layer: Represents the context (BankingDbContext) and repository (AccountRepository) interacting with SQL Server.
b. Transfer Microservice:
- Transfer API: MicroRabbit.Transfer.Api with its controllers and configurations.
- Transfer Application Layer: Contains business logic and service interfaces (ITransferService and TransferService).
- Transfer Domain Layer: Contains events (e.g., TransferCreatedEvent) and event handlers (e.g., TransferEventHandler), along with the repository interface.
- Transfer Data Layer: Contains the TransferDbContext and repository implementation (TransferRepository).
c. RabbitMQ Bus/Infrastructure:
- A central bus component (RabbitMQBus in MicroRabbit.Infra.Bus) handles event publishing and messaging between microservices.
- Domain Core components (Command, Event and the corresponding interfaces) that standardize commands and events.
d. MicroRabbit.MVC Client:
- The MVC project provides a user interface and interacts with the back-end services. It has its own controller (e.g., HomeController) and service (TransferService) for consuming API data.
- This client is meant to showcase the integration of UI with the microservices by interfacing with Banking and Transfer APIs.

##### Relationships and Interactions
- RabbitMQBus as a mediator between the Banking and Transfer services: for example, from Banking’s CommandHandlers and Event publishers to Transfer’s EventHandlers.
- Then, demonstrate consumer connectivity from the MVC client to the Banking API (and indirectly to the Transfer API if applicable) via REST calls/API calls.
- Usage of Swagger as an API documentation tool for the Banking and Transfer APIs.

##### Architectural Patterns and Design Principles
- Domain Driven Design (DDD): Separate domain, data, and application concerns in distinct projects.
- Microservices: Each API (Banking and Transfer) is an independent service with its own database and responsibility.
- Messaging via RabbitMQ: Use of publish/subscribe patterns to decouple communication between services.
- Dependency Injection: Noted in the MicroRabbit.Infra.IoC project for managing dependencies across the solution.
- Layered Architecture: Each microservice follows a layered structure (API → Application → Domain → Data).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        MVC["MVC Client"]:::frontend
    end

    %% Banking Microservice
    subgraph "Banking Microservice"
        BA["Banking API"]:::api
        BApp["Banking Application Layer"]:::internal
        BDom["Banking Domain Layer"]:::internal
        BData["Banking Data Layer"]:::data
        BDB["Banking SQL DB"]:::data
        BA -->|"calls"| BApp
        BApp -->|"processes"| BDom
        BDom -->|"interacts"| BData
        BData -->|"persists"| BDB
    end

    %% Transfer Microservice
    subgraph "Transfer Microservice"
        TA["Transfer API"]:::api
        TApp["Transfer Application Layer"]:::internal
        TDom["Transfer Domain Layer"]:::internal
        TData["Transfer Data Layer"]:::data
        TDB["Transfer SQL DB"]:::data
        TA -->|"calls"| TApp
        TApp -->|"processes"| TDom
        TDom -->|"interacts"| TData
        TData -->|"persists"| TDB
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        Bus["RabbitMQ Bus"]:::infra
        DC["Domain Core Components"]:::infra
        DI["Dependency Injection Container"]:::infra
    end

    %% Connections Between Layers
    MVC -->|"REST"| BA
    MVC -->|"REST"| TA

    BDom -->|"publish_event"| Bus
    Bus -->|"deliver_event"| TDom

    DC -->|"defines_cmds_evt"| BDom
    DC -->|"defines_cmds_evt"| TDom

    DI -->|"resolve_deps"| BA
    DI -->|"resolve_deps"| TA
    DI -->|"resolve_deps"| MVC
    DI -->|"resolve_deps"| Bus

    %% Click Events
    click BA "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Banking.Api"
    click BApp "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Banking.Application"
    click BDom "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Banking.Domain"
    click BData "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Banking.Data"
    click TA "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Transfer.Api"
    click TApp "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Transfer.Application"
    click TDom "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Transfer.Domain"
    click TData "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Transfer.Data"
    click Bus "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Infra.Bus/RabbitMQBus.cs"
    click DC "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Domain.Core"
    click DI "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.Infra.IoC/DependencyContainer.cs"
    click MVC "https://github.com/dpedwards/dotnet-core-micro-rabbit/blob/master/MicroRabbit/MicroRabbit.MVC"

    %% Styles
    classDef api fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef internal fill:#d4e4ff,stroke:#333,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef infra fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef frontend fill:#d4edda,stroke:#333,stroke-width:2px;
```
