Skip to content

suranig/MicroserviceKit

Repository files navigation

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

NuGet Version NuGet Downloads .NET License: MIT GitHub

πŸš€ Complete toolkit for generating production-ready .NET 8 microservices with DDD, CQRS, Clean Architecture, Event-Driven Architecture, and comprehensive infrastructure.

✨ Features

  • πŸ—οΈ Clean Architecture - Domain, Application, Infrastructure, API layers
  • πŸ“¦ Domain-Driven Design - Aggregates, Entities, Value Objects, Domain Events
  • ⚑ CQRS Pattern - Command Query Responsibility Segregation with MassTransit
  • πŸ”„ Event-Driven Architecture - RabbitMQ, MassTransit, Domain Events
  • πŸ—„οΈ Multi-Database Support - PostgreSQL (write), MongoDB (read), Redis (cache)
  • πŸ”— External Services Integration - HTTP clients with Polly resilience
  • πŸ§ͺ Comprehensive Testing - Unit, Integration, E2E with TestContainers
  • 🐳 Docker & Kubernetes - Production-ready containerization with Dockerfile, docker-compose.yml, Makefile
  • πŸ“Š Monitoring & Health Checks - Built-in observability
  • πŸ” Security - JWT authentication, OAuth2, RBAC
  • 🌐 API Gateway - Centralized routing and authentication

πŸ†• What's New in v0.4.5

  • βœ… Complete Template Library - All 16 microservice templates now included in CLI package
  • 🎯 Enhanced Discovery - microkit list command with filtering and detailed views
  • πŸ“‹ Template Details - microkit describe command for comprehensive template information
  • πŸš€ Production Ready - Templates include Docker, Kubernetes, testing, and monitoring
  • πŸ”§ CLI Improvements - Better error handling and user experience
  • πŸ“¦ NuGet Distribution - Templates embedded in NuGet package for global availability

πŸš€ Quick Start

Install the CLI tool

# Install latest version (v0.4.5)
dotnet tool install -g MicroserviceKit

# Or update existing installation
dotnet tool update -g MicroserviceKit

Generate your first microservice

# Interactive mode (recommended for beginners)
microkit generate MyService --interactive

# Quick start with enterprise template
microkit generate ArticleService --template cqrs-event-sourcing

# With custom aggregates and external services
microkit generate MyService --template cqrs-event-sourcing --aggregates Article Comment --external-services ImageService VideoService

Explore available templates

# List all 16 available templates
microkit list

# List by category
microkit list --category service-types
microkit list --category levels

# Get detailed template information
microkit describe cqrs-event-sourcing.json

πŸ“‹ Available Templates

16 production-ready templates across 4 categories:

🏷️ Enterprise Service Types

Perfect for production microservices with complex business requirements:

cqrs-event-sourcing.json ⭐ Most Popular

  • Use for: Services with complex business rules, audit trail requirements, event-driven architecture
  • Complexity: Enterprise (25 minutes)
  • Features: CQRS, Event Sourcing, Domain Events, Aggregate Root, PostgreSQL
  • Perfect for: Article management, Order processing, Financial transactions

bpc-workflow.json

  • Use for: Business process orchestration, workflow management, external system integration
  • Complexity: Enterprise (30 minutes)
  • Features: Workflow Engine, Saga Pattern, External Integrations, State Machine, Hangfire
  • Perfect for: Payment processing, Document approval workflows, Multi-step business processes

event-store.json

  • Use for: Centralized event storage, event replay, audit logs
  • Complexity: Enterprise (20 minutes)
  • Features: Event Store, Event Sourcing, Projections, Event Replay
  • Perfect for: Event sourcing infrastructure, Audit systems, Event analytics

read-model.json

  • Use for: High-performance read operations, reporting, data projections
  • Complexity: Medium (15 minutes)
  • Features: CQRS Read Side, MongoDB, Projections, Redis Cache, Event Handlers
  • Perfect for: Reporting services, Search APIs, Data analytics

identity-auth.json

  • Use for: User authentication, authorization, multi-tenant security
  • Complexity: Enterprise (25 minutes)
  • Features: OAuth2, JWT, RBAC, Multi-Auth, Identity Server
  • Perfect for: Identity provider, User management, API security

api-gateway.json

  • Use for: Centralized API management, routing, cross-cutting concerns
  • Complexity: Enterprise (20 minutes)
  • Features: API Gateway, Routing, Rate Limiting, Circuit Breaker, Ocelot
  • Perfect for: Microservices entry point, API aggregation, Security gateway

multi-tenant.json

  • Use for: SaaS applications, tenant isolation, configuration per tenant
  • Complexity: Enterprise (20 minutes)
  • Features: Multi-tenancy, Tenant Isolation, Configuration per Tenant, Domain Routing
  • Perfect for: SaaS platforms, Multi-client systems, Tenant-specific features

legacy-adapter.json

  • Use for: Integration with legacy systems, data synchronization
  • Complexity: Medium (15 minutes)
  • Features: Adapter Pattern, Legacy Integration, Data Sync, Anti-corruption Layer
  • Perfect for: Legacy system integration, Data migration, System modernization

search-indexing.json

  • Use for: Full-text search, content indexing, search analytics
  • Complexity: Medium (15 minutes)
  • Features: Elasticsearch, Search Indexing, Event-driven, Full-text Search
  • Perfect for: Content search, Product catalogs, Document search

cqrs-simple.json

  • Use for: CQRS without Event Sourcing, simpler business logic
  • Complexity: Medium (15 minutes)
  • Features: CQRS, Clean Architecture, PostgreSQL, Redis Cache
  • Perfect for: CRUD-heavy services, Simple business logic, Standard applications

πŸ—οΈ Architecture Levels

Choose based on your project complexity:

standard-service.json πŸ“Š Balanced

  • Use for: Standard business applications, moderate complexity
  • Complexity: Medium (10 minutes)
  • Features: Clean Architecture, CQRS, SQLite, JWT Auth
  • Perfect for: Business applications, Standard APIs, Moderate complexity

enterprise-service.json 🏒 Full Featured

  • Use for: Enterprise applications, all patterns included
  • Complexity: Complex (20 minutes)
  • Features: DDD, CQRS, Event Sourcing, Microservices Patterns, Docker, Kubernetes
  • Perfect for: Large enterprises, Complex domains, Full-scale microservices

πŸ—οΈ Generated Architecture

Every generated service includes:

MyService/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Domain/                 # Domain layer (DDD)
β”‚   β”‚   β”œβ”€β”€ Aggregates/         # Aggregate roots with business logic
β”‚   β”‚   β”œβ”€β”€ Entities/           # Domain entities
β”‚   β”‚   β”œβ”€β”€ ValueObjects/       # Immutable value objects
β”‚   β”‚   β”œβ”€β”€ Events/             # Domain events
β”‚   β”‚   └── Repositories/       # Repository interfaces
β”‚   β”œβ”€β”€ Application/            # Application layer (CQRS)
β”‚   β”‚   β”œβ”€β”€ Commands/           # Command handlers (write operations)
β”‚   β”‚   β”œβ”€β”€ Queries/            # Query handlers (read operations)
β”‚   β”‚   β”œβ”€β”€ DTOs/               # Data transfer objects
β”‚   β”‚   └── Behaviors/          # Cross-cutting concerns
β”‚   β”œβ”€β”€ Infrastructure/         # Infrastructure layer
β”‚   β”‚   β”œβ”€β”€ Persistence/        # EF Core, MongoDB, Redis
β”‚   β”‚   β”œβ”€β”€ ExternalServices/   # HTTP clients with Polly
β”‚   β”‚   β”œβ”€β”€ Messaging/          # MassTransit + RabbitMQ
β”‚   β”‚   └── Configuration/      # Dependency injection
β”‚   └── Api/                    # API layer
β”‚       β”œβ”€β”€ Controllers/        # REST API controllers
β”‚       β”œβ”€β”€ Middleware/         # Custom middleware
β”‚       └── Extensions/         # Service registration
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ Unit/                   # Unit tests with xUnit
β”‚   β”œβ”€β”€ Integration/            # Integration tests with TestContainers
β”‚   └── EndToEnd/               # E2E tests
β”œβ”€β”€ Dockerfile                  # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml          # Complete development environment
β”œβ”€β”€ Makefile                    # Development commands
β”œβ”€β”€ k8s/                        # Kubernetes manifests
└── docs/                       # Auto-generated documentation

πŸ› οΈ CLI Commands

πŸš€ Generate Commands

# Interactive mode (recommended)
microkit generate MyService --interactive

# Quick generation with template
microkit generate ArticleService --template cqrs-event-sourcing

# Custom aggregates
microkit generate MyService --template cqrs-event-sourcing --aggregates Article Comment User

# External services integration
microkit generate MyService --template cqrs-event-sourcing --external-services ImageService VideoService NotificationService

# Full customization
microkit generate MyService --template cqrs-event-sourcing \
  --aggregates Article Comment \
  --external-services ImageService VideoService \
  --database postgresql \
  --output ./services/ArticleService

πŸ“‹ Discovery Commands

# List all 16 available templates
microkit list

# List by category (4 categories available)
microkit list --category service-types  # 10 enterprise templates
microkit list --category levels         # 3 architecture levels
microkit list --category examples       # 1 complete example
microkit list --category configs        # 2 base configurations

# Filter by complexity
microkit list --complexity enterprise   # Advanced templates
microkit list --complexity medium       # Balanced templates
microkit list --complexity simple       # Quick start templates

# Detailed view with features and usage info
microkit list --detailed

# Output in different formats
microkit list --format table           # Default table view
microkit list --format json            # JSON output
microkit list --format markdown        # Markdown format

# Get comprehensive template information
microkit describe cqrs-event-sourcing.json    # Full template details
microkit describe api-gateway.json --format json  # JSON output
microkit describe standard-service.json        # Architecture level info

πŸ”§ Template Customization

Example: Article Service Configuration

{
  "templateType": "cqrs-event-sourcing",
  "microserviceName": "ArticleService",
  "namespace": "Company.ArticleService",
  "domain": {
    "aggregates": [
      {
        "name": "Article",
        "properties": [
          { "name": "Title", "type": "string", "isRequired": true },
          { "name": "Content", "type": "string", "isRequired": true },
          { "name": "Status", "type": "ArticleStatus", "isRequired": true }
        ],
        "operations": ["Create", "Update", "Publish", "Archive"]
      }
    ]
  },
  "features": {
    "database": {
      "writeModel": { "provider": "postgresql" },
      "readModel": { "provider": "mongodb" }
    },
    "messaging": { "enabled": true, "provider": "rabbitmq" },
    "externalServices": {
      "enabled": true,
      "services": [
        {
          "name": "ImageService",
          "baseUrl": "https://api.images.com",
          "operations": ["Upload", "Process", "Delete"]
        }
      ]
    }
  },
  "deployment": {
    "docker": { "enabled": true },
    "kubernetes": { "enabled": true }
  }
}

πŸ§ͺ Testing & Development

Generated Development Environment

Every service includes a complete development setup:

# Start development environment
make dev-setup

# Run the service
make run

# Run tests
make test

# Build Docker image
make docker-build

# Run with Docker
make docker-run

# Clean up
make clean

Testing with TestContainers

# Unit tests
dotnet test tests/Unit/

# Integration tests with real databases
dotnet test tests/Integration/

# End-to-end tests
dotnet test tests/EndToEnd/

# All tests
make test

🐳 Docker & Kubernetes

Complete Containerization

Every generated service includes:

  • Multi-stage Dockerfile - Optimized for production
  • docker-compose.yml - Complete development environment with PostgreSQL, MongoDB, Redis, RabbitMQ
  • Kubernetes manifests - Production-ready K8s deployment
  • Health checks - Liveness and readiness probes
  • Makefile - All development commands
# Development with Docker Compose
docker-compose up -d

# Build production image
docker build -t myservice:latest .

# Deploy to Kubernetes
kubectl apply -f k8s/

πŸ“Š Monitoring & Observability

Built-in Monitoring

  • Health Checks - /health, /health/ready, /health/live
  • Metrics - ASP.NET Core built-in metrics
  • Structured Logging - Serilog with correlation IDs
  • Distributed Tracing - OpenTelemetry ready
# Health endpoints
curl http://localhost:5000/health
curl http://localhost:5000/health/ready
curl http://localhost:5000/health/live

# Metrics endpoint
curl http://localhost:5000/metrics

πŸ” Security

Authentication & Authorization

# JWT for internal services
curl -H "Authorization: Bearer <jwt-token>" \
     http://localhost:5000/api/articles

# OAuth2 for external applications
curl -H "Authorization: Bearer <oauth-token>" \
     http://localhost:5000/api/articles

🌟 Real-World Examples

Headless CMS Architecture

# Article management service
microkit generate ArticleService --template cqrs-event-sourcing --aggregates Article ArticleBlock

# Page management service
microkit generate PageService --template cqrs-event-sourcing --aggregates Page PageLayout

# Content read service
microkit generate ContentReadService --template read-model --aggregates ArticleProjection PageProjection

# Search service
microkit generate SearchService --template search-indexing

# Identity service
microkit generate IdentityService --template identity-auth --aggregates User Role Permission

# API Gateway
microkit generate ApiGateway --template api-gateway

E-commerce Platform

# Order management
microkit generate OrderService --template cqrs-event-sourcing --aggregates Order OrderItem

# Product catalog
microkit generate ProductService --template cqrs-simple --aggregates Product Category

# Inventory management
microkit generate InventoryService --template cqrs-event-sourcing --aggregates Inventory

# Payment processing
microkit generate PaymentService --template bpc-workflow --aggregates Payment PaymentMethod

# Search service
microkit generate SearchService --template search-indexing

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

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

πŸ†˜ Support


Built with ❀️ for the .NET community

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors