MicroserviceKit 0.1.0-beta

This is a prerelease version of MicroserviceKit.
There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global MicroserviceKit --version 0.1.0-beta
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local MicroserviceKit --version 0.1.0-beta
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=MicroserviceKit&version=0.1.0-beta&prerelease
                    
nuke :add-package MicroserviceKit --version 0.1.0-beta
                    

๐Ÿš€ .NET 8 Microservice Template Generator

A powerful, configurable template generator for .NET 8 microservices with a modular "Lego blocks" approach. Generate production-ready microservices with Clean Architecture, DDD patterns, CQRS, containerization, and comprehensive testing.

โœจ Features

๐Ÿ—๏ธ Architecture Levels

  • MINIMAL: Single project for simple CRUD services (1-2 developers)
  • STANDARD: 3-layer architecture for medium complexity (2-5 developers)
  • ENTERPRISE: 4-layer architecture for complex services (5+ developers)
  • AUTO: Intelligent selection based on your requirements

๐Ÿงฉ Modular Components

  • Domain Layer: Aggregates, Entities, Value Objects, Domain Events
  • Application Layer: Commands, Queries, Handlers, DTOs, Validation
  • API Layer: REST Controllers with OpenAPI, Validation, Error Handling
  • Infrastructure Layer: Repositories, DbContext, External Services
  • Testing: Unit Tests, Integration Tests, Test Utilities

๐Ÿณ Containerization

  • Docker: Intelligent Dockerfile generation for microservice and infrastructure
  • Docker Compose: Orchestration with PostgreSQL, MongoDB, RabbitMQ
  • Kubernetes: Production-ready manifests with HPA, Services, ConfigMaps

๐Ÿ”ง Technologies

  • .NET 8 with latest C# features
  • Wolverine for CQRS/Mediator (MIT license)
  • AggregateKit for DDD base classes
  • Entity Framework Core for persistence
  • FluentValidation for input validation
  • xUnit, FluentAssertions, Moq for testing

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/your-repo/microservice-net8-ddd.git
cd microservice-net8-ddd

# Build the CLI tool
dotnet build src/CLI/MicroserviceGenerator.CLI/MicroserviceGenerator.CLI.csproj

# Install globally (optional)
dotnet pack src/CLI/MicroserviceGenerator.CLI/MicroserviceGenerator.CLI.csproj
dotnet tool install -g MicroserviceGenerator.CLI

Generate Your First Microservice

# Interactive mode - guided setup
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new OrderService --interactive

# Quick start with defaults
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new OrderService

# From configuration file
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new OrderService --config examples/enterprise-service.json

# Custom output directory
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new OrderService --output ./my-services/

๐Ÿ“‹ Configuration

Basic Configuration

{
  "ServiceName": "OrderService",
  "RootNamespace": "Company.OrderService",
  "Architecture": {
    "Level": "standard"
  },
  "Features": {
    "Api": {
      "Style": "controllers",
      "Documentation": true,
      "Versioning": true
    },
    "Persistence": {
      "WriteModel": "postgresql",
      "ReadModel": "mongodb"
    },
    "Messaging": {
      "Enabled": true,
      "Provider": "rabbitmq"
    }
  },
  "Domain": {
    "Aggregates": [
      {
        "Name": "Order",
        "Properties": [
          { "Name": "CustomerId", "Type": "Guid" },
          { "Name": "TotalAmount", "Type": "decimal" },
          { "Name": "Status", "Type": "OrderStatus" }
        ],
        "Operations": ["Create", "UpdateStatus", "Cancel"]
      }
    ]
  }
}

Architecture Levels

Level Projects Use Case Team Size
MINIMAL 1 project Simple CRUD, prototypes 1-2 devs
STANDARD 3 projects Business logic, medium complexity 2-5 devs
ENTERPRISE 4+ projects Complex domains, high scalability 5+ devs
AUTO Intelligent Analyzes your config and decides Any

๐Ÿ—๏ธ Generated Structure

Standard Level

OrderService/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ OrderService.Domain/           # Aggregates, Entities, Events
โ”‚   โ”œโ”€โ”€ OrderService.Application/      # Commands, Queries, Handlers
โ”‚   โ””โ”€โ”€ OrderService.Api/             # Controllers, DTOs, Middleware
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ OrderService.UnitTests/       # Domain & Application tests
โ”‚   โ””โ”€โ”€ OrderService.IntegrationTests/ # API & Database tests
โ”œโ”€โ”€ docker/
โ”‚   โ”œโ”€โ”€ microservice.Dockerfile       # Main application
โ”‚   โ”œโ”€โ”€ postgres.Dockerfile          # Write model
โ”‚   โ”œโ”€โ”€ mongodb.Dockerfile           # Read model
โ”‚   โ””โ”€โ”€ docker-compose.yml           # Full orchestration
โ””โ”€โ”€ k8s/
    โ”œโ”€โ”€ deployment.yaml              # Kubernetes deployment
    โ”œโ”€โ”€ service.yaml                 # Load balancer
    โ””โ”€โ”€ hpa.yaml                     # Auto-scaling

Enterprise Level

OrderService/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ OrderService.Domain/          # Rich domain model
โ”‚   โ”œโ”€โ”€ OrderService.Application/     # Use cases & DTOs
โ”‚   โ”œโ”€โ”€ OrderService.Infrastructure/  # Persistence & External services
โ”‚   โ””โ”€โ”€ OrderService.Api/            # REST/gRPC endpoints
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ OrderService.UnitTests/      # Fast, isolated tests
โ”‚   โ”œโ”€โ”€ OrderService.IntegrationTests/ # Database & API tests
โ”‚   โ””โ”€โ”€ OrderService.ArchitectureTests/ # Architecture compliance
โ””โ”€โ”€ deployment/                      # Full DevOps setup

๐Ÿงช Testing Strategy

Generated Test Types

Unit Tests

  • Domain logic and business rules
  • Command/Query handlers
  • Value object validation
  • Domain event handling

Integration Tests

  • API endpoints with real database
  • Repository implementations
  • Message publishing/consuming
  • External service integration

Architecture Tests

  • Layer dependency rules
  • Naming conventions
  • Code quality metrics

Test Example

[Fact]
public async Task CreateOrder_WithValidData_ShouldReturnOrderId()
{
    // Arrange
    var command = new CreateOrderCommand(
        CustomerId: Guid.NewGuid(),
        Items: [new OrderItem("Product", 2, 10.00m)]
    );

    // Act
    var result = await _handler.Handle(command, CancellationToken.None);

    // Assert
    result.Should().NotBeEmpty();
    _mockRepository.Verify(x => x.AddAsync(
        It.IsAny<Order>(), 
        It.IsAny<CancellationToken>()), 
        Times.Once);
}

๐Ÿณ Docker & Kubernetes

Docker Compose (Development)

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f orderservice

# Scale microservice
docker-compose up -d --scale orderservice=3

Kubernetes (Production)

# Deploy to Kubernetes
kubectl apply -f k8s/

# Check status
kubectl get pods -l app=orderservice

# Scale horizontally
kubectl scale deployment orderservice-deployment --replicas=5

# View auto-scaling
kubectl get hpa

๐Ÿ”„ Migration & Evolution

Migrate Existing Projects

# Analyze current project
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- migrate --analyze

# Preview migration to standard level
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- migrate --level standard --dry-run

# Execute migration
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- migrate --level standard

# View migration history
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- history

Smart Auto-Configuration

The generator automatically enables features based on complexity:

  • DDD: Enabled when complexity >= medium
  • CQRS: Enabled when multiple operations per aggregate
  • Infrastructure Layer: Enabled when external dependencies detected
  • Docker: Enabled for standard+ levels
  • Kubernetes: Enabled for enterprise level

๐Ÿ“š Examples

Simple CRUD Service

dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new ProductCatalog --config examples/minimal-crud.json

Event-Driven Microservice

dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new OrderService --config examples/event-driven.json

Enterprise Service

dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new PaymentService --config examples/enterprise-service.json

๐Ÿ› ๏ธ Development

Prerequisites

  • .NET 8 SDK
  • Docker & Docker Compose
  • Kubernetes (optional)

Build & Test

# Build solution
dotnet build

# Run tests
dotnet test

# Run CLI locally
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- --help

Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

๐Ÿ“– Documentation

๐ŸŽฏ Roadmap

โœ… Completed (Phase 1-2)

  • Domain Layer generation with AggregateKit
  • REST API Controllers with full CRUD
  • Comprehensive Unit Testing
  • CLI with interactive mode
  • Smart architecture level selection

๐Ÿšง In Progress (Phase 3)

  • Application Layer (Commands/Queries/Handlers)
  • Infrastructure Layer (Repositories/DbContext)
  • Integration Testing
  • Docker & Kubernetes support

๐Ÿ”ฎ Planned (Phase 4+)

  • gRPC API support
  • Event Sourcing patterns
  • Advanced CQRS with separate read/write models
  • Observability (Logging, Metrics, Tracing)
  • Performance optimization

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Support


Made with โค๏ธ for .NET developers who want to build better microservices faster.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.4.5 89 6/20/2025
0.4.4 98 6/20/2025
0.4.2 110 6/20/2025
0.4.1 136 6/20/2025
0.4.0 136 6/20/2025
0.3.0 295 6/10/2025
0.2.0 217 6/9/2025
0.1.0-beta 190 6/8/2025

🎉 BETA Release 0.1.0
โœ… Core functionality working:
- Domain Layer generation with AggregateKit
- REST API Controllers with full CRUD
- Comprehensive Unit Testing
- CLI with interactive mode
- Smart architecture selection

🚧 In Development:
- Application Layer (Commands/Queries/Handlers)
- Infrastructure Layer (Repositories/DbContext)
- Docker & Kubernetes support
- Integration Tests

โš ๏ธ This is a BETA version. Core features work but some modules are still in development.