MicroserviceKit 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global MicroserviceKit --version 0.2.0
                    
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.2.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=MicroserviceKit&version=0.2.0
                    
nuke :add-package MicroserviceKit --version 0.2.0
                    

๐Ÿš€ MicroserviceKit - .NET 8 Microservice Template Generator

NuGet Version NuGet Downloads .NET License: MIT GitHub

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

# Install globally from NuGet
dotnet tool install --global MicroserviceKit --prerelease

# Or install specific version
dotnet tool install --global MicroserviceKit --version 0.1.0-beta

Generate Your First Microservice

# Interactive mode - guided setup
microkit new OrderService --interactive

# Quick start with defaults
microkit new OrderService

# From configuration file
microkit new OrderService --config examples/enterprise-service.json

# Custom output directory
microkit new OrderService --output ./my-services/

# Show help
microkit --help

Alternative: Build from Source

# Clone the repository
git clone https://github.com/suranig/MicroserviceKit.git
cd MicroserviceKit

# Build and run locally
dotnet build
dotnet run --project src/CLI/MicroserviceGenerator.CLI -- new OrderService

๐Ÿ“‹ 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
microkit migrate --analyze

# Preview migration to standard level
microkit migrate --level standard --dry-run

# Execute migration
microkit migrate --level standard

# View migration history
microkit 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

microkit new ProductCatalog --config examples/minimal-crud.json

Event-Driven Microservice

microkit new OrderService --config examples/event-driven.json

Enterprise Service

microkit new PaymentService --config examples/enterprise-service.json

๐Ÿ› ๏ธ Development

Prerequisites

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

Build & Test

# Build solution
make build

# Run unit tests
make test

# Run CLI tests
make cli-test

# Run full CLI test suite
make cli-test-full

# Clean CLI test directories
make cli-clean

# Development workflow (build + test)
make dev

# Run CLI locally (if building from source)
dotnet run --project src/CLI/CLI.csproj -- --help

# Or use installed version
microkit --help

CLI Testing

The project includes a dedicated testing infrastructure for CLI commands:

# Quick CLI test (standard microservice)
./test_cli/quick-test.sh

# Full test suite (all architecture levels)
./test_cli/full-test.sh

# Clean test directories
./test_cli/clean.sh

# Test specific architecture level
make test-basic      # Minimal level
make test-standard   # Standard level  
make test-enterprise # Enterprise level

# Interactive CLI testing
make cli-interactive

Test Directory Structure:

test_cli/
โ”œโ”€โ”€ basic/          # Basic microservice tests
โ”œโ”€โ”€ standard/       # Standard architecture tests
โ”œโ”€โ”€ enterprise/     # Enterprise configuration tests
โ”œโ”€โ”€ messaging/      # Messaging module tests (future)
โ””โ”€โ”€ *.sh           # Test automation scripts

All CLI tests are automatically excluded from version control and run in isolated directories.

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

๐Ÿ“ฆ NuGet Package

MicroserviceKit is available on NuGet.org:

  • Package: MicroserviceKit
  • Current Version: 0.1.0-beta
  • Command: microkit
  • Installation: dotnet tool install --global MicroserviceKit --prerelease

Package Statistics

NuGet Version NuGet Downloads

๐Ÿ“„ License

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


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 77 6/20/2025
0.4.4 96 6/20/2025
0.4.2 108 6/20/2025
0.4.1 134 6/20/2025
0.4.0 134 6/20/2025
0.3.0 293 6/10/2025
0.2.0 216 6/9/2025
0.1.0-beta 189 6/8/2025

🎉 Major Release 0.2.0 - Enterprise-Ready Microservices!

โœ… NEW ENTERPRISE FEATURES:
- 📨 Event-Driven Architecture with RabbitMQ messaging
- 📊 CQRS with MongoDB read models and PostgreSQL write models  
- 🌐 External Services integration with Polly resilience patterns
- 🐳 Complete Docker & Kubernetes deployment infrastructure
- 🧪 Comprehensive Integration Testing with TestContainers
- 🔒 Production-ready security, monitoring, and health checks
- 📈 Built-in metrics, logging, and observability

โœ… COMPLETE INFRASTRUCTURE:
- REST APIs with proper /api/rest/{aggregate} structure
- Domain events with automatic read model synchronization
- Service registry with circuit breaker, retry, timeout patterns
- Docker Compose with full development stack
- Kubernetes manifests with HPA, monitoring, security
- Integration tests for APIs, databases, and messaging

🚀 PRODUCTION READY: Generate enterprise-grade microservices with complete infrastructure, testing, and deployment capabilities!