DEV Community

Le Anh Phi
Le Anh Phi

Posted on

Muonroi Building Block: an open-core .NET foundation for rule engines, decision tables, and multi-tenancy

Repository: https://github.com/muonroi/muonroi-building-block

Status: public repo, open-core (Apache-2.0 OSS packages + commercial-licensed packages).

Target audience: unknown (repo docs suggest teams building .NET services that need rule orchestration, decision tables, multi-tenancy, and governance primitives).

Version: 1.0.0-alpha.9 (repo-wide versioning is configured via Directory.Build.props).

Executive summary

Muonroi Building Block is the .NET foundation of the Muonroi ecosystem. It bundles a rule engine stack (strongly typed rules + orchestration + tracing), decision tables (with common hit policies), and supporting infrastructure like governance/licensing concepts and multi-tenancy helpers. The repository is open-core: OSS packages are Apache 2.0, while commercial packages are distributed under a separate commercial license and are expected to be gated at runtime.

A key differentiator is its developer experience around rule authoring: write rule logic in normal C#, mark it with an attribute, then let source generators and CLI tools generate rule classes and DI registration glue. This reduces handmade boilerplate and allows verification steps (e.g., dependency checks) before runtime.

Key features and use cases

Key features (as described by repo README + deep map)

  • Strongly typed rule abstraction (IRule<TContext>) and shared state via a FactBag.
  • Rule orchestration with execution hooks, ordering, and dependency constraints.
  • Decision table engine with widely used hit policies (Unique, Any, First, All, Collect, RuleOrder).
  • Source generators + analyzers to extract rules from code and generate DI registration.
  • CLI toolchain (RuleGen) for extract/verify/register/watch flows.
  • Multi-tenancy packages for resolving tenant context and linking per-tenant resources.
  • Explicit OSS/commercial boundary enforcement via scripts (modular boundary checks).

Practical use cases

  • Policy/risk/fraud scoring where rules evolve faster than deployments.
  • Decision tables for business-friendly rule maintenance with deterministic evaluation.
  • Multi-tenant SaaS foundations: consistent tenant resolution + quota enforcement primitives.
  • Preproduction verification: catch rule dependency errors (and other analyzer-driven issues) before runtime.

Architecture and main components

Big-picture: rule execution pipeline

flowchart TD
  Input[Input context + facts] --> Orchestrator[IMRuleOrchestrator.ExecuteAsync]
  Orchestrator --> FactBag[FactBag shared state]
  FactBag --> Rules[Compiled rules / FEEL / decision tables / flow graph]
  Rules --> Result[OrchestratorResult + updated facts]
Enter fullscreen mode Exit fullscreen mode

Big-picture: code-first rule authoring + generation

flowchart LR
  Dev[Developer writes C# method] --> Attr[[MExtractAsRule]]
  Attr --> CLI[muonroi-rule extract/register/verify]
  CLI --> Gen[Generated rule classes + DI registration]
  Gen --> DI[services.AddRuleEngine<T>() + AddGeneratedRules()]
  DI --> Runtime[Runtime executes rules via orchestrator]
Enter fullscreen mode Exit fullscreen mode

Monorepo layout (high level)

muonroi-building-block/
  src/
    Muonroi.RuleEngine.Abstractions/
    Muonroi.RuleEngine.Core/
    Muonroi.RuleEngine.DecisionTable/
    Muonroi.RuleEngine.SourceGenerators/
    Muonroi.Tenancy.*
    Muonroi.Governance.*
    Muonroi.Observability
    (...more packages...)
  tools/
    Muonroi.RuleGen/                  # CLI for rule extraction/registration/verification
    Muonroi.DecisionTableGen/         # decision table tooling (per deep map)
    Muonroi.RuleGen.VisualStudio/     # VS extension (per deep map)
    Muonroi.RuleGen/vscode-extension/ # VS Code extension (per deep map)
  samples/
    Quickstart.RuleEngine/
    Quickstart.DecisionTable/
    FraudDetection/
    LoanApproval/
    MultiTenantSaaS/
    RuleSourceGen/
  REPO_DEEP_MAP.md
  OSS-BOUNDARY.md
  LICENSE-APACHE / LICENSE-COMMERCIAL
Enter fullscreen mode Exit fullscreen mode

If you want the “map of everything,” the repo provides it:

Installation and quickstart

Install the core rule engine packages

dotnet add package Muonroi.RuleEngine.Core
dotnet add package Muonroi.RuleEngine.SourceGenerators
Enter fullscreen mode Exit fullscreen mode

Exact versions are unknown here; prefer pinning versions explicitly for production.

Quick example: write a rule in plain C

[MExtractAsRule("HIGH_VALUE_ORDER", DependsOn = new[] { "CREDIT_SCORE" })]
public RuleResult HighValue(OrderContext context, FactBag facts)
{
    if (context.Amount <= 1000m) return RuleResult.Failure("Below threshold.");
    facts["requiresReview"] = true;
    return RuleResult.Success();
}
Enter fullscreen mode Exit fullscreen mode

Generate the glue code and wire up DI

muonroi-rule extract --source src/Rules --output Generated/Rules
muonroi-rule register --rules Generated/Rules --output Generated/RuleEngineRegistrationExtensions.g.cs
Enter fullscreen mode Exit fullscreen mode
using Muonroi.RuleEngine.Generated;

builder.Services.AddRuleEngine<OrderContext>();
builder.Services.AddGeneratedRules();
Enter fullscreen mode Exit fullscreen mode

Run a sample (Rule Engine quickstart)

cd <workspace-root>\muonroi-building-block\samples\Quickstart.RuleEngine\src\Quickstart.RuleEngine.Api
dotnet restore
dotnet run
Enter fullscreen mode Exit fullscreen mode

Test request:

curl -X POST http://localhost:5000/api/orders/evaluate `
  -H "Content-Type: application/json" `
  -d "{\"amount\":1200,\"customerType\":\"premium\",\"countryCode\":\"US\"}"
Enter fullscreen mode Exit fullscreen mode

Run a sample (Decision Table quickstart)

Start Postgres locally:

docker run --name muonroi-sample-postgres `
  -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin -e POSTGRES_DB=muonroi_decision_tables `
  -p 5432:5432 -d postgres:16
Enter fullscreen mode Exit fullscreen mode

Run the API sample:

cd <workspace-root>\muonroi-building-block\samples\Quickstart.DecisionTable\src\Quickstart.DecisionTable.Api
dotnet restore
dotnet run
Enter fullscreen mode Exit fullscreen mode

Create and execute a table via REST APIs:

Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/v1/decision-tables" `
  -ContentType "application/json" -InFile ".\assets\discount-table.json"

$body = '{"inputs":{"amount":1200,"customerType":"premium","country":"US"}}'
Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/v1/decision-tables/discount-rules/execute" `
  -ContentType "application/json" -Body $body
Enter fullscreen mode Exit fullscreen mode

Contribution guide and license

Contributing

The contribution guide emphasizes “boundary-safe” work:

  • Default working branch: develop
  • Prereqs: .NET SDK 8+, PowerShell 7+; Postgres/Redis only if your change needs them
  • Run tests + the modular boundary check before opening a PR:
pwsh ./scripts/check-modular-boundaries.ps1 -RepoRoot .
dotnet test Muonroi.BuildingBlock.sln -c Debug
Enter fullscreen mode Exit fullscreen mode

Contributing guide:

https://github.com/muonroi/muonroi-building-block/blob/main/CONTRIBUTING.md

License (open-core)

  • OSS packages: Apache 2.0 (LICENSE-APACHE)
  • Commercial packages: Muonroi commercial license (LICENSE-COMMERCIAL)
  • The repo documents an OSS/commercial boundary rule and checks it via a script:
    • OSS packages MUST NOT depend on commercial packages.
    • Commercial packages MAY depend on OSS packages.

Key boundary doc:

https://github.com/muonroi/muonroi-building-block/blob/main/OSS-BOUNDARY.md

License files:

Comparison to similar projects (brief)

Suggested tags and social blurb

Suggested dev.to tags

dotnet, csharp, rulesengine, decisiontable, opensource, multitenant, architecture, sourcegenerators, cli, observability

Social blurb (3–5 lines)

Muonroi Building Block is an open-core .NET foundation for rule engines, decision tables, and multi-tenant services.

It supports code-first rules + source-generated registration, decision table evaluation, and runtime orchestration with shared FactBag state.

If you’re building policy-heavy systems (risk/fraud/pricing) and want strong DX around rule authoring, it’s worth a deep look.

Repo: https://github.com/muonroi/muonroi-building-block

References

Top comments (0)