Cratis code analysis for framework contracts
The Cratis Stack
Catch framework mistakes while you build
Cratis code analysis reports framework contract violations during C# compilation and TypeScript or React linting. Roslyn analyzers check C# code in dotnet build; ESLint rules check frontend code when you run linting. Use these diagnostics to fix supported command, event, and UI contract mistakes before running the application, whether you or an AI agent wrote the code.
Why build gates, not docs alone
Section titled “Why build gates, not docs alone”A declaration can compile as ordinary C# yet fail a framework contract. Arc
reports a Handle() method on a type without [Command], for example, while
Chronicle reports reactor parameters that cannot be resolved. The diagnostic
identifies the rule and affected code, so you can investigate before debugging
runtime discovery. Several rules also offer an editor code fix.
The frontend rules address different mistakes: React hooks inside view models, component imports from the wrong entry point, or command callbacks that discard their values. Arc’s ESLint processor also excludes generated proxies, keeping lint feedback focused on code you can edit.
In an AI-native workflow, give the agent the diagnostic and ask it to correct the affected code, then rerun the check. Cratis AI supplies guidance before a change; configured build and lint gates check the contracts they cover afterward. A warning only stops a build if your configuration makes it an error.
Roslyn analyzer packages
Section titled “Roslyn analyzer packages”Roslyn is the C# compiler platform; its analyzers add diagnostics to the
compilation. Arc’s analyzer packages are dependencies of the Arc packages they
check. Chronicle’s analyzers arrive with Cratis.Chronicle, including through
Cratis.Chronicle.AspNetCore, from 19.4.8. Architecture’s coding conventions
are a separate, opt-in package.
Upgrading Chronicle from an older version to 19.4.8 or later can expose
violations that previously went unchecked. Error diagnostics fail compilation;
warning diagnostics can also fail it when warnings are treated as errors. For
older clients, add Cratis.Chronicle.CodeAnalysis at the client’s version.
Rules for events, projections, reactors, reducers, and other event-sourcing constructs. Arrives with Cratis.Chronicle and Cratis.Chronicle.AspNetCore from 19.4.8. Older versions need Cratis.Chronicle.CodeAnalysis added at the client’s version.
Rules for command, query, validation, and concept declarations. Arrives with Cratis.Arc.Core through Cratis.Arc.Core.CodeAnalysis. Does not need Chronicle.
Rules for Arc’s Chronicle integration: command identity, aggregate event handlers, reactor side effects, and audit metadata for secret command values. Arrives with Cratis.Arc.Chronicle.
House coding and architecture conventions used across Cratis codebases, such as exception naming and logging through LoggerMessage. Install Cratis.Architecture.CodeAnalysis separately if you want them.
Open the relevant rule index for diagnostic IDs, default severities, and available fixes. The indexes describe current rules; older package versions may not contain every rule listed. These Roslyn packages analyze C#, not the other Cratis client languages.
ESLint packages
Section titled “ESLint packages”For TypeScript and React, start with the shared ESLint configuration and add
the plugins for the products you use. They compose as flat config: an array of
configuration objects in eslint.config.mjs.
| Package | Source | What it checks |
|---|---|---|
@cratis/eslint-config |
Fundamentals | The consumer preset provides TypeScript and React hygiene, with relaxations for for_* behavior-driven spec files. The internal preset also adds the Cratis license-header rule for Cratis-owned repositories. |
@cratis/eslint-plugin-arc |
Arc | Excludes generated Arc proxies, forbids React hooks in view model classes, and forbids direct imports from mobx-react or mobx-react-lite. |
@cratis/eslint-plugin-components |
Components | Requires component-family subpath imports while allowing root setup symbols; forbids Dialog from primereact/dialog; requires command values from supported onBeforeExecute callbacks; and forbids hooks in view models and hand-written CommandForm markers. |
Install the packages you need as development dependencies. The Components 4
plugin’s supported range is >=4 <5; keep it on the same major as
@cratis/components. The
Components ESLint README
lists installation commands and rule options.
For a project using both Arc and Components, compose the presets in
eslint.config.mjs:
import cratis from '@cratis/eslint-config';import arc from '@cratis/eslint-plugin-arc';import components from '@cratis/eslint-plugin-components';
export default [ ...cratis.configs.consumer, ...arc.configs.recommended, ...components.configs.recommended,];Run ESLint through your project’s lint command; adding the configuration does
not make it part of dotnet build. The Components callback rule applies to
command dialogs, steppers, and Arc’s CommandForm. It does not require a return
value from CommandScope, whose callback returns void.
The AI layer and the enforcement layer
Section titled “The AI layer and the enforcement layer”Cratis AI gives the assistant conventions and task workflows. Code analysis supplies repeatable checks for the supported patterns, independent of whether the author followed that guidance.
Those checks have limits. For example, Chronicle’s event-marker analyzers accept certain explicit registrations visible in the same compilation, but cannot prove that those calls execute or that the actual store is configured correctly. The Chronicle rule index explains that boundary. Use behavior specs to check expected outcomes, and runtime checks for behavior that static analysis cannot establish.