Code Analysis
Cratis Architecture ships Roslyn analyzers that enforce architectural and coding conventions across Cratis codebases.
- Keep architectural intent enforceable
- Surface violations as early as possible
- Give developers and agents clear, actionable feedback
Rules Overview
Section titled “Rules Overview”| Rule ID | Title | Severity | Description |
|---|---|---|---|
| CRARCH0001 | Exception type naming | Warning | Exception types must use domain terminology and avoid the generic Exception suffix |
| CRARCH0002 | No built-in exception types | Warning | Throwing framework exceptions hides domain intent |
| CRARCH0003 | No postfixes on class names | Warning | Class names must describe domain concepts, not technical roles |
| CRARCH0004 | No Features in namespace | Warning | Namespace paths should stay domain-oriented and avoid framework-driven structure names |
| CRARCH0005 | No regions | Warning | Region directives usually indicate files that need better separation of responsibilities |
| CRARCH0006 | Logging via LoggerMessage | Warning | Structured, source-generated logging ensures consistency and better performance |
| CRARCH0007 | No IServiceProvider injection | Warning | Service locator patterns hide dependencies and make code harder to reason about |
| CRARCH0008 | Use is null checks | Warning | Pattern matching null checks are the preferred and consistent style |
| CRARCH0009 | Use string interpolation | Warning | Interpolated strings are clearer and easier to maintain |
| CRARCH0010 | Constructor fan-out | Warning | Too many dependencies indicate excessive responsibility in one type |
| CRARCH0011 | File length threshold | Warning | Very large files are difficult to understand and maintain |
| CRARCH0012 | async void forbidden | Error | async void methods hide failures and cannot be awaited in regular flows |
| CRARCH0013 | No blocking on async | Warning | Blocking asynchronous calls can cause deadlocks and reliability issues |
| CRARCH0014 | No test types in production | Error | Production assemblies must remain independent of test-only infrastructure |
| CRARCH0015 | Static class naming convention | Warning | Static utility types follow strict naming conventions to improve discoverability |
| CRARCH0016 | Unused interfaces | Warning | Speculative interfaces without implementations add unnecessary abstraction |
| CRARCH0017 | Namespace must align with folder path | Warning | Namespace and folder alignment improves navigability and consistency |
| CRARCH0018 | Avoid concrete type injection | Warning | Constructor dependencies should favor abstractions for loose coupling |
| CRARCH0019 | Avoid Async postfix on method names | Warning | Method names should avoid unnecessary suffixes unless sync/async pairs exist |
| CRARCH0020 | Handle asynchronous calls | Warning | Fire-and-forget calls can hide failures and produce nondeterministic behavior |
| CRARCH0021 | Serializable attribute not allowed | Warning | Legacy serialization attributes are not part of modern Cratis architecture guidance |
| CRARCH0022 | Private modifier not allowed | Warning | Private is implicit in C#, so explicit modifiers add noise |
| CRARCH0023 | Use typed logger category | Warning | Typed logger categories align log events with the producing type |
| CRARCH0024 | LoggerMessage container conventions | Warning | LoggerMessage methods must live in convention-based containers for consistency |
| CRARCH0025 | Use Cratis Fundamentals traces | Warning | Tracing should flow through Cratis Fundamentals abstractions for consistency |
| CRARCH0026 | Use Cratis Fundamentals metrics | Warning | Metrics should use Cratis Fundamentals abstractions instead of raw instrument creation |