Muonroi.Modular.Template 1.8.1

There is a newer version of this package available.
See the version list below for details.
dotnet new install Muonroi.Modular.Template::1.8.1
                    
This package contains a .NET Template Package you can call from the shell/command line.

Muonroi.Modular.Template

Ask DeepWiki

A .NET solution template for building Modular Monolith applications using ASP.NET Core with the Muonroi.BuildingBlock library. Perfect for enterprise systems with medium complexity that need module separation while keeping deployment simple.

Quick Start

# 1. Install template
dotnet new install Muonroi.Modular.Template

# 2. Create new project
dotnet new mr-mod-sln -n MyModularApp

# 3. Setup
cd MyModularApp/MyModularApp
dotnet restore

# 4. Run migrations
cd src/Host/MyModularApp.Host
dotnet ef migrations add InitialCreate --project ../../Shared/MyModularApp.Kernel
dotnet ef database update --project ../../Shared/MyModularApp.Kernel

# 5. Run
dotnet run

Open: https://localhost:5001/swagger

Prerequisites

Installation

dotnet new install Muonroi.Modular.Template

From source

git clone https://github.com/muonroi/MuonroiBuildingBlock.git
cd MuonroiBuildingBlock/src/Muonroi.Modular.Template
dotnet new install ./

Verify installation

dotnet new list | grep "mr-mod-sln"

Usage

Create new project

dotnet new mr-mod-sln -n <ProjectName>
Parameter Short Description Default
--name -n Solution/project name (required)

Examples

# Create modular monolith for e-commerce
dotnet new mr-mod-sln -n ECommerce

# Creates modules: Identity, Catalog with shared Kernel

Project Structure

MyModularApp/
├── MyModularApp.sln
├── src/
│   ├── Host/                              # Application Entry Point
│   │   └── MyModularApp.Host/             # Web API Host
│   │       ├── appsettings.json
│   │       ├── appsettings.Development.json
│   │       ├── appsettings.Production.json
│   │       ├── Program.cs                  # Bootstrapper
│   │       └── Infrastructures/            # DI Configuration
│   ├── Modules/                            # Independent Business Modules
│   │   ├── Identity/                       # User/Auth module
│   │   │   ├── Controllers/
│   │   │   ├── Models/
│   │   │   ├── Services/
│   │   │   └── IdentityModule.cs          # Module registration
│   │   └── Catalog/                        # Product catalog module
│   │       ├── Controllers/
│   │       ├── Models/
│   │       ├── Services/
│   │       └── CatalogModule.cs           # Module registration
│   └── Shared/                             # Shared Infrastructure
│       ├── MyModularApp.Kernel/            # Data layer, DbContext
│       │   ├── Persistence/
│       │   │   ├── MyModularAppDbContext.cs
│       │   │   └── Migrations/
│       │   └── Repositories/
│       └── MyModularApp.Shared/            # Shared contracts
│           ├── Events/                     # Domain events
│           └── Dtos/                       # Shared DTOs
└── README.md

Configuration

Supported Database Types

DbType Connection String Key
Sqlite SqliteConnectionString
SqlServer SqlServerConnectionString
MySql MySqlConnectionString
PostgreSql PostgreSqlConnectionString
MongoDb MongoDbConnectionString

Example Configuration

{
  "DatabaseConfigs": {
    "DbType": "Sqlite",
    "ConnectionStrings": {
      "SqliteConnectionString": "Data Source=modular_app.db"
    }
  },
  "TokenConfigs": {
    "Issuer": "https://localhost:5001",
    "Audience": "https://localhost:5001",
    "SymmetricSecretKey": "your-secret-key-minimum-32-characters!",
    "UseRsa": false,
    "ExpiryMinutes": 60
  },
  "EnableEncryption": false
}

Feature Flags

Toggle optional features to reduce startup time:

{
  "FeatureFlags": {
    "UseGrpc": false,
    "UseServiceDiscovery": false,
    "UseMessageBus": false,
    "UseBackgroundJobs": false,
    "UseEnsureCreatedFallback": true
  }
}

Database Migrations

Since modules share a single database (via Kernel), migrations are centralized:

# Add migration
dotnet ef migrations add "AddNewFeature" \
    -p ./src/Shared/MyModularApp.Kernel \
    --startup-project ./src/Host/MyModularApp.Host \
    -o Persistence/Migrations

# Update database
dotnet ef database update \
    -p ./src/Shared/MyModularApp.Kernel \
    --startup-project ./src/Host/MyModularApp.Host

Modular Monolith Architecture

Why Modular Monolith?

  • Simpler than Microservices - Single deployment, no distributed complexity
  • Better than Monolith - Clear module boundaries, independent development
  • Migration Path - Easy to extract modules into microservices later

Module Communication

Modules communicate via:

  1. Domain Events - In-process async communication
  2. Integration Events - Cross-module events via MediatR
  3. Shared Contracts - DTOs in Shared project (use sparingly)
  4. Direct References - Avoid when possible

Adding New Module

  1. Create module folder under src/Modules/:

    src/Modules/
    └── Orders/                    # New module
        ├── Controllers/
        ├── Models/
        ├── Services/
        └── OrdersModule.cs       # Module registration
    
  2. Add module project reference to Host

  3. Register module services in Program.cs:

    builder.Services.AddOrdersModule();
    
  4. Add module entities to Kernel DbContext (optional)

Features

  • Modular Monolith - Independent modules, single deployment
  • CQRS with MediatR - Command/Query separation per module
  • Authentication & Authorization - JWT, permissions, roles
  • Entity Framework Core - Shared Kernel database
  • Structured Logging - Serilog with service-specific log files
  • Caching - Memory, Redis, or Multi-level
  • Multi-tenancy - Data isolation by tenant
  • Inter-Module Events - Loose coupling via domain events
  • Service Discovery - Consul integration
  • Message Bus - Kafka/RabbitMQ via MassTransit
  • Background Jobs - Hangfire/Quartz integration

Module Guidelines

DO:

  • Keep modules independent and loosely coupled
  • Use events for inter-module communication
  • Share only necessary contracts (DTOs/interfaces)
  • Follow Domain-Driven Design within modules
  • Use separate folders for module concerns

DON'T:

  • Create direct module-to-module dependencies
  • Share domain entities across modules
  • Put business logic in Shared projects
  • Mix module responsibilities

Documentation

Troubleshooting

"Connection string is not provided"

Ensure DbType matches the connection string key:

{
  "DatabaseConfigs": {
    "DbType": "MySql",  // Must match key below
    "ConnectionStrings": {
      "MySqlConnectionString": "..."  // ✓ Correct key
    }
  }
}

"The input is not a valid Base-64 string"

Set "EnableEncryption": false in appsettings.

Migration errors

Always specify both -p (Kernel) and --startup-project (Host):

dotnet ef migrations add Init \
    -p ./src/Shared/MyModularApp.Kernel \
    --startup-project ./src/Host/MyModularApp.Host

API slow on startup

Disable unused features in FeatureFlags.

Module not loading

Check Program.cs for module registration:

builder.Services.AddIdentityModule();
builder.Services.AddCatalogModule();

License

MIT License. See LICENSE.txt for details.

  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.9.3 99 2/8/2026
1.9.2 99 2/8/2026
1.8.1 109 1/25/2026
1.8.0 108 1/25/2026
1.7.6 106 1/24/2026
1.7.5 106 1/24/2026
1.7.4 110 1/24/2026
1.7.3 110 1/24/2026