An open API service indexing awesome lists of open source software.

https://github.com/cristofima/banksystemmicroservices

Bank System Microservices developed in .NET following Clean Architecture, DDD and EDA
https://github.com/cristofima/banksystemmicroservices

azure-pipelines clean-architecture clean-code domain-driven-design dotnet entity-framework-core event-driven-architecture integration-tests microservices scalar sonar-qube test-containers unit-testing yarp

Last synced: 2 months ago
JSON representation

Bank System Microservices developed in .NET following Clean Architecture, DDD and EDA

Awesome Lists containing this project

README

          

# Bank System Microservices


Quality Gate Status
Bugs
Code Smells
Coverage
Duplicated Lines (%)


Lines of Code
Reliability Rating
Security Rating
Technical Debt
Maintainability Rating
Vulnerabilities

A modern, cloud-native banking system built with .NET 9 microservices architecture, designed for Azure deployment with Clean Architecture, CQRS, and Event-Driven Architecture patterns.

## ๐Ÿ—๏ธ Architecture Overview

This system implements a distributed banking platform using microservices that communicate through Azure Service Bus events, following Domain-Driven Design (DDD) principles and the CQRS pattern for optimal scalability and maintainability.

### Core Microservices

- **๐Ÿ” Security Service**: Handles authentication, authorization, and user management
- **๐Ÿฆ Account Service**: Manages customer accounts, balances, and account operations
- **๐Ÿ’ธ Transaction Service**: Processes financial transactions (deposits, withdrawals) - Write operations
- **๐Ÿ“Š Movement Service**: Provides transaction history and reporting - Read operations
- **๐Ÿ”” Notification Service**: Manages multi-channel notifications and alerts
- **๐Ÿ“ˆ Reporting Service**: Handles analytics, reports, and business intelligence

### Architecture Patterns

- **Clean Architecture**: Clear separation of concerns across layers
- **CQRS (Command Query Responsibility Segregation)**: Separate read and write operations
- **Event-Driven Architecture**: Asynchronous communication via Azure Service Bus
- **Domain-Driven Design**: Rich domain models with business logic encapsulation
- **Microservices**: Independently deployable and scalable services

## ๐Ÿš€ Technology Stack

### Backend

- **.NET 9**: Latest framework with improved performance and features
- **ASP.NET Core**: Web API framework
- **Entity Framework Core**: ORM for data access
- **MediatR**: CQRS and Mediator pattern implementation
- **FluentValidation**: Input validation
- **AutoMapper**: Object-to-object mapping
- **Serilog**: Structured logging

### Azure Services

- **Azure Service Bus**: Message broker for event-driven communication
- **Azure SQL Database**: Primary database for transactions and accounts
- **Azure Cosmos DB**: Document database for movement history (read-optimized)
- **Azure Key Vault**: Secrets and configuration management
- **Azure Application Insights**: Monitoring and telemetry
- **Azure API Management**: API Gateway and management
- **Azure Container Apps**: Container hosting platform

### Development Tools

- **Docker**: Containerization
- **.NET Aspire**: Local development orchestration and monitoring _(Local Development Only)_
- **YARP**: Reverse proxy for API Gateway _(Local Development Only)_
- **Terraform/Bicep**: Infrastructure as Code
- **Azure DevOps**: CI/CD pipelines
- **xUnit**: Unit testing framework
- **FluentAssertions**: Assertion library

### Environment Architecture

#### Local Development Environment

- **API Gateway**: YARP-based reverse proxy for service routing
- **.NET Aspire Dashboard**: Local orchestration and monitoring
- **ServiceDefaults**: Aspire-based service configuration and telemetry

#### Production Environment (Azure)

- **Azure API Management**: Replaces local API Gateway for enterprise-grade routing, policies, and security
- **Azure Application Insights Dashboard**: Replaces .NET Aspire Dashboard for production monitoring
- **Azure Service Discovery**: Native Azure service discovery and load balancing

## ๐Ÿ›๏ธ System Architecture

```mermaid
graph TB
%% Client Layer
Client[๐Ÿ“ฑ Client App
Angular]

%% Gateway Layer
Gateway[๐ŸŒ API Management
Gateway]

%% Core Services Layer
Security[๐Ÿ” Security
Service]
Account[๐Ÿฆ Account
Service]
Transaction[๐Ÿ’ธ Transaction
Service]

%% Event Bus
ServiceBus[๐ŸšŒ Azure Service Bus
Event Distribution]

%% Read Services Layer
Movement[๐Ÿ“Š Movement
Service]
Notification[๐Ÿ”” Notification
Service]
Reporting[๐Ÿ“ˆ Reporting
Service]

%% Data Layer
SqlDB[(๐Ÿ—„๏ธ Azure SQL
Database)]
CosmosDB[(๐ŸŒ Azure Cosmos DB
Movement History)]

%% Client to Gateway
Client --> Gateway

%% Gateway to Core Services
Gateway --> Security
Gateway --> Account
Gateway --> Transaction

%% Core Services to Event Bus
Security -.-> ServiceBus
Account -.-> ServiceBus
Transaction -.-> ServiceBus

%% Event Bus to Read Services
ServiceBus -.-> Movement
ServiceBus -.-> Notification
ServiceBus -.-> Reporting

%% Data Connections
Security --> SqlDB
Account --> SqlDB
Transaction --> SqlDB
Movement --> CosmosDB
Reporting --> SqlDB
Reporting --> CosmosDB

%% Styling - Darker backgrounds with white text for optimal contrast
classDef clientStyle fill:#0277bd,stroke:#01579b,stroke-width:2px,color:#ffffff
classDef gatewayStyle fill:#6a1b9a,stroke:#4a148c,stroke-width:2px,color:#ffffff
classDef coreServiceStyle fill:#388e3c,stroke:#2e7d32,stroke-width:2px,color:#ffffff
classDef readServiceStyle fill:#f57c00,stroke:#e65100,stroke-width:2px,color:#ffffff
classDef eventStyle fill:#ad1457,stroke:#c2185b,stroke-width:2px,color:#ffffff
classDef dataStyle fill:#689f38,stroke:#558b2f,stroke-width:2px,color:#ffffff

class Client clientStyle
class Gateway gatewayStyle
class Security,Account,Transaction coreServiceStyle
class Movement,Notification,Reporting readServiceStyle
class ServiceBus eventStyle
class SqlDB,CosmosDB dataStyle
```

## ๐Ÿ”„ Event-Driven Flow

### Transaction Processing Flow

1. **Client** initiates a deposit/withdrawal request
2. **API Gateway** routes to Transaction Service
3. **Transaction Service** validates and processes the transaction
4. **Transaction Service** publishes `TransactionCreatedEvent`
5. **Account Service** subscribes to update account balance
6. **Movement Service** subscribes to create movement history record

### Benefits

- **Loose Coupling**: Services communicate through events
- **Scalability**: Each service can scale independently
- **Resilience**: Failure in one service doesn't affect others
- **Eventual Consistency**: Data consistency across services

## ๐Ÿ“ Project Structure

```
BankSystemMicroservices/
โ”œโ”€โ”€ ๐Ÿ“„ README.md # Main documentation
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE # MIT License
โ”œโ”€โ”€ ๐Ÿ“„ docker-compose.yml # Docker orchestration
โ”œโ”€โ”€ ๐Ÿ“„ docker-compose.infrastructure.yml # Infrastructure services
โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Source code
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ BankSystem.sln # Main solution file
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ coverlet.runsettings # Test coverage settings
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ aspire-app/ # ๐Ÿ  LOCAL DEVELOPMENT ONLY
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ AppHost/ # .NET Aspire orchestration
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ AppHost.cs # Aspire host configuration
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ BankSystem.AppHost.csproj # AppHost project file
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ appsettings.json # Aspire settings
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ ServiceDefaults/ # Aspire service defaults
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ Extensions.cs # Service extensions
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ BankSystem.ServiceDefaults.csproj
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ gateway/ # ๐ŸŒ LOCAL DEVELOPMENT ONLY
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ ApiGateway/ # YARP-based API Gateway
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ Program.cs # Gateway entry point
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ BankSystem.ApiGateway.csproj # Gateway project
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ appsettings.json # Gateway configuration
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ services/ # ๐Ÿ—๏ธ Microservices
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Security/ # ๐Ÿ” Authentication & Authorization
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Security.Api/ # Web API layer
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Security.Application/ # Application layer (CQRS)
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Security.Domain/ # Domain layer (DDD)
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ Security.Infrastructure/ # Infrastructure layer
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/ # Service-specific tests
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Security.Application.UnitTests/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Security.Domain.UnitTests/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ Security.Infrastructure.IntegrationTests/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Account/ # ๐Ÿฆ Account Management
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Same structure as Security
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/ # Same test structure
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Transaction/ # ๐Ÿ’ธ Transaction Processing (Write)
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Same structure as Security
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/ # Same test structure
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Movement/ # ๐Ÿ“Š Movement History (Read)
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Same structure as Security
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/ # Same test structure
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ Notification/ # ๐Ÿ”” Notifications
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Same structure as Security
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/ # Same test structure
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ Reporting/ # ๐Ÿ“ˆ Reporting & Analytics
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Same structure as Security
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/ # Same test structure
โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ shared/ # ๐Ÿ”— Shared Components
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ src/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ BankSystem.Shared.Domain/ # Common domain logic
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ BankSystem.Shared.Infrastructure/ # Common infrastructure
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ BankSystem.Shared.WebApi/ # Web API configurations
โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ tests/
โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ BankSystem.Shared.Domain.UnitTests/
โ”œโ”€โ”€ ๐Ÿ“‚ docs/ # ๐Ÿ“š Documentation
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ dotnet-development-guidelines.md # Development guidelines
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ health-checks-configuration.md # Health checks guide
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ sonarqube-integration-guide.md # SonarQube setup
โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ guidelines/ # Detailed guidelines
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ clean-code.md # Clean code practices
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ api-design.md # API design patterns
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ cqrs-implementation.md # CQRS patterns
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ ... # Other guidelines
โ”œโ”€โ”€ ๐Ÿ“‚ scripts/ # ๐Ÿ”ง Build & Deployment Scripts
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ build-local.bat # Windows build script
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ build-local.ps1 # PowerShell build script
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ run-unit-tests.ps1 # Test execution script
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ BUILD_SCRIPTS.md # Scripts documentation
โ”œโ”€โ”€ ๐Ÿ“‚ tests/ # ๐Ÿงช Cross-Service Integration Tests
โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ integration/ # End-to-end test scenarios
โ””โ”€โ”€ ๐Ÿ“‚ build/ # ๐Ÿš€ CI/CD Configurations
โ”œโ”€โ”€ ๐Ÿ“‚ azure-pipelines/ # Azure DevOps pipelines
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ ci-build-test.yml # CI/CD pipeline definition
โ””โ”€โ”€ ๐Ÿ“‚ terraform/ # Infrastructure as Code
โ”œโ”€โ”€ ๐Ÿ“„ main.tf # Main Terraform config
โ””โ”€โ”€ ๐Ÿ“„ variables.tf # Terraform variables
```

### Local vs Production Components

- **aspire-app/** and **gateway/**: Used only for local development
- **Production**: Azure API Management and Azure Application Insights replace these components

## ๐Ÿšฆ Getting Started

### Prerequisites

- .NET 9 SDK
- Docker Desktop
- Azure CLI
- Visual Studio 2022 or VS Code

### Local Development Setup

1. **Clone the repository**

```bash
git clone https://github.com/your-org/bank-system-microservices.git
cd bank-system-microservices
```

2. **Start infrastructure services**

```bash
docker-compose -f docker-compose.infrastructure.yml up -d
```

3. **Update connection strings**

```bash
# Update appsettings.Development.json in each service
```

4. **Run database migrations**

```bash
dotnet ef database update --project src/services/Account/src/Account.Infrastructure
dotnet ef database update --project src/services/Transaction/src/Transaction.Infrastructure
```

5. **Start services**

```bash
# Terminal 1 - Security Service
dotnet run --project src/services/Security/src/Security.Api

# Terminal 2 - Account Service
dotnet run --project src/services/Account/src/Account.Api

# Terminal 3 - Transaction Service
dotnet run --project src/services/Transaction/src/Transaction.Api

# Terminal 4 - Movement Service
dotnet run --project src/services/Movement/src/Movement.Api

# Terminal 5 - Notification Service
dotnet run --project src/services/Notification/src/Notification.Api

# Terminal 6 - Reporting Service
dotnet run --project src/services/Reporting/src/Reporting.Api
```

## ๐Ÿ”ง Configuration

### Environment Variables

```bash
# Database Connections
CONNECTIONSTRINGS__DEFAULTCONNECTION="Server=localhost;Database=BankSystem;Trusted_Connection=true;"

# Azure Service Bus
AZURE__SERVICEBUS__CONNECTIONSTRING="Endpoint=sb://your-namespace.servicebus.windows.net/..."

# JWT Settings
JWT__KEY="your-super-secret-key"
JWT__ISSUER="https://localhost:5001"
JWT__AUDIENCE="bank-system-api"
```

## ๐Ÿ“Š API Documentation

Each microservice exposes its own OpenAPI/Scalar documentation:

- **Security API**: `https://localhost:5001/scalar`
- **Account API**: `https://localhost:5002/scalar`
- **Transaction API**: `https://localhost:5003/scalar`
- **Movement API**: `https://localhost:5004/scalar`
- **Notification API**: `https://localhost:5005/scalar`
- **Reporting API**: `https://localhost:5006/scalar`

## ๐Ÿงช Testing

### Run Unit Tests

**Basic unit test execution:**

```bash
dotnet test
```

**Run unit tests with code coverage (recommended):**

```powershell
# Use the provided PowerShell script
./scripts/run-unit-tests.ps1
```

This will:

- Run all unit test projects in the solution
- Generate code coverage reports in multiple formats (HTML, Cobertura, JSON)
- Open the HTML coverage report automatically
- Results are saved to `TestResults/` directory

**Manual coverage command:**

```bash
dotnet test --configuration Debug --collect:"XPlat Code Coverage" --settings coverlet.runsettings --results-directory TestResults /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=TestResults/coverage.cobertura.xml
```

### Run Integration Tests

```bash
dotnet test --configuration Release --filter Category=Integration
```

### Run Load Tests

```bash
# Using k6 or Azure Load Testing
k6 run tests/load/transaction-load-test.js
```

### Available Test Scripts

See [scripts/README.md](scripts/README.md) for detailed information about available build and test scripts.

## ๐Ÿš€ Deployment

### Azure Deployment

```bash
# Deploy infrastructure
terraform apply -var-file="environments/prod.tfvars"

# Deploy applications
az acr build --registry bankSystemRegistry --image security-service:latest ./src/services/Security
az containerapp update --name security-service --image bankSystemRegistry.azurecr.io/security-service:latest
```

## ๐Ÿ” Monitoring & Observability

- **Application Insights**: Performance monitoring and telemetry
- **Azure Monitor**: Infrastructure monitoring
- **Structured Logging**: Centralized logging with Serilog
- **Health Checks**: Service health monitoring
- **Distributed Tracing**: Request flow tracking

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Follow the [Development Guidelines](docs/dotnet-development-guidelines.md)
4. Commit your changes (`git commit -m 'Add amazing feature'`)
5. Push to the branch (`git push origin feature/amazing-feature`)
6. Open a Pull Request

## ๐Ÿ“š Documentation

- [.NET Development Guidelines](docs/dotnet-development-guidelines.md)
- [API Documentation](docs/api-documentation.md)
- [Architecture Decision Records](docs/adr/)
- [Deployment Guide](docs/deployment-guide.md)

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ”— Related Services

- [Security Service](src/services/Security/README.md)
- [Account Service](src/services/Account/README.md)
- [Transaction Service](src/services/Transaction/README.md)
- [Movement Service](src/services/Movement/README.md)
- [Notification Service](src/services/Notification/README.md)
- [Reporting Service](src/services/Reporting/README.md)