Skip to content

Repository files navigation

Cratis Architecture

Roslyn analyzers that turn Cratis architectural conventions into build-time diagnostics for .NET codebases — MIT licensed and free to use.

Installation

Add the NuGet package to your project:

dotnet add package Cratis.Architecture.CodeAnalysis

Or add it directly to your .csproj file:

<ItemGroup>
  <PackageReference Include="Cratis.Architecture.CodeAnalysis" Version="*" />
</ItemGroup>

The analyzers will automatically run during build and provide diagnostics in your IDE.

What this project represents

This project turns architectural intent into executable rules. Instead of relying on review comments and tribal knowledge, you get immediate diagnostics directly in your editor and CI pipeline.

We treat architecture as a first-class part of developer feedback:

  • Architectural boundaries stay visible while you code
  • Teams get consistent enforcement across repositories
  • New contributors can follow conventions without memorizing all rules

Catch architectural problems early

Architectural drift gets expensive when it is discovered late. These analyzers are designed to fail fast:

  • During local development in your IDE
  • During build and test execution
  • Before non-compliant code becomes part of your shared history

This shortens feedback loops and keeps architecture aligned with design decisions over time.

Why this works well with LLMs and agentic development

LLMs and coding agents are much more effective when constraints are explicit and machine-checkable.

Cratis Architecture gives agents and humans the same contract:

  • Rules are deterministic and discoverable
  • Violations are specific and actionable
  • Code fixes are guided by clear architectural diagnostics

That means agent-generated code gets validated against your architectural standards immediately, which reduces rework and keeps automated development aligned with your intended design.

What the analyzers enforce

26 rules (CRARCH0001–CRARCH0026) covering:

  • Domain-oriented naming — exception type naming, no technical postfixes on class names, static class naming conventions, domain-oriented namespaces aligned with folder paths
  • Exceptions — domain-specific exception types instead of built-in framework exceptions
  • Logging and observability — source-generated LoggerMessage logging, typed logger categories, and Cratis Fundamentals traces and metrics
  • Async hygiene — no async void, no blocking on async calls, unawaited calls handled, no Async method-name postfix
  • Dependency injection — no IServiceProvider injection, no concrete type injection, constructor fan-out limits
  • Code structure and style — file length thresholds, no regions, no unused interfaces, no test types in production assemblies, is null pattern checks, string interpolation

See the rule reference for every rule with its severity and rationale.

Documentation

The Cratis ecosystem

This project is part of Cratis — free, MIT-licensed tools for building event-sourced and CQRS applications.

Everything Cratis publishes today is MIT licensed and free to use.

Releases

Packages

Contributors

Languages