CodeCharter consists of four layers that are developed and tested independently. This separation is also the reason why the analysis is deterministic — each layer has well-defined inputs and well-defined outputs.
Layers from Bottom to Top
1. Analysis (CodeCharter.Analysis)
Reads a .NET solution using MSBuild and builds an abstract code model with types, methods, properties, fields, and their relationships (coupling, inheritance, method calls).
A syntactic pre-analysis also runs here, performing specific pattern detection
such as "DateTime.Now was called directly" or "async method has no
CancellationToken parameter". These findings are stored as SyntaxIssue
objects in the model.
Output: an AnalysisModel with the collections Types, Methods,
Properties, Fields, Events, Namespaces, Assemblies,
TypeDependencies, and SyntaxIssues.
2. DSL (CodeCharter.Dsl)
Reads .ccr files, parses them into an AST, and compiles the LINQ queries into
executable lambdas. The DSL is a true subset of LINQ — queries are translated
into compiled lambdas and executed against the analysis model.
Output: a set of executable rules that can run against the analysis model.
Alongside this sits CodeCharter.Dsl.LanguageServer, an LSP server for the
VS Code extension. It provides IntelliSense for DSL property names, checks
syntax errors live, and suggests schema paths.
3. Output (CodeCharter.Output)
Converts findings into the requested format: text, JSON, SARIF, or GitHub annotations. Each output formatter is its own class; new formats are isolatable.
4. Core (CodeCharter.Core)
Orchestrates the other three layers. Cache management, threading, CLI parameter parsing, configuration loading. This layer also decides whether something is analyzed incrementally or from scratch.
Distributions
| Distribution | What it contains |
|---|---|
| CLI (Standalone) | All four layers in one binary, self-contained. |
| Windows Installer | CLI plus VS Code extension plus PATH setup. |
| VS Code Extension | LSP client that starts CodeCharter.Dsl.LanguageServer and invokes the CLI. |
| GitHub Action | Composite action that pulls the CLI from the portal, runs it, and publishes annotations. |
Data and Control Flow
codecharter analyze .
│
▼
Core.Loader (reads solution + .codecharter config)
│
▼
Analysis.Loader (parses solution with MSBuild)
│
▼
Analysis.SyntaxScanner (detects DateTime.Now, empty catch blocks, ...)
│
▼
Analysis.Model (builds collections)
│
▼
Dsl.RuleLoader (reads all .ccr files)
│
▼
Dsl.Compiler (LINQ queries -> lambdas)
│
▼
Dsl.RuleEngine (runs rules against model)
│
▼
Core.FindingsCollector
│
▼
Output.Formatter (--output console|json|sarif|github)
│
▼
Stdout / file
What This Architecture Enables
- Determinism because the analysis is stateless. Same input, same output.
- Multiple output formats without the analysis layer knowing anything about them.
- Custom rule packages because the DSL treats schema stability as a contract. We don't break the model between patch releases.