Skip to content

Analyzers

Modulus ships with five Roslyn analyzers that enforce modular architecture conventions directly in your IDE. Violations appear as real-time diagnostics (red squiggles, warnings, and suggestions) while you code, catching architectural issues before they reach a pull request.

Why Analyzers?

Architecture tests with NetArchTest are powerful but only run during dotnet test. A developer can write violating code, commit it, push it, and only learn about the issue when CI fails. Roslyn analyzers close this gap by providing instant feedback in the editor.

Together, analyzers and architecture tests form two complementary layers:

LayerWhenFeedbackScope
Roslyn AnalyzersReal-time in IDE, dotnet buildInstant squigglesPer-file analysis
Architecture Testsdotnet test, CI pipelineTest failureFull assembly analysis

Rule Summary

RuleSeverityDescriptionCode Fix
MOD001ErrorModule boundary violation -- cross-module reference to non-Integration project--
MOD002WarningHandler not returning Result or Result<T>--
MOD003WarningThrowing exceptions for expected errors in handlersYes
MOD004WarningInfrastructure attributes (EF, JSON) in Domain layerYes
MOD005InfoPublic setter on entity propertyYes

Installation

If you scaffolded your solution with the Modulus CLI, analyzers are already configured. To add them manually:

xml
<PackageReference Include="ModulusKit.Analyzers"
                  OutputItemType="Analyzer"
                  ReferenceOutputAssembly="false" />

Both ModulusKit.Analyzers and ModulusKit.Generators are transitively included through ModulusKit.Mediator.Abstractions.

What's Next

  • Rule Reference -- Detailed documentation for each rule with violation and correct code examples
  • Configuration -- Adjust severities, suppress rules, and enforce in CI

Released under the MIT License.