Enforce a repository's architecture policy as TUnit tests, so the rules are defined once rather than copied into every repository's test project.
- Project-level dependency direction — a declared
ProjectReferencethe matrix forbids, or does not permit. - Type-level dependency direction — a type in one responsibility using a type in another, including a dependency that only arrives transitively or through a package. Read from the compiled assemblies by metadata only: nothing is loaded or executed.
- Composition boundary — only the composition root's category is exempt from being referenced back to.
- Sibling independence — qualified implementations of a responsibility must not reference one another.
- Forbidden packages and framework references — e.g.
Microsoft.AspNetCore.Appin a portable layer. - Cycles, naming and test references — the rest of the standard set, reported readably.
- Waivers — reviewed, per-project departures that keep every other rule in force and are themselves checked.
- An extension point — add a bespoke rule to the same reporting,
SkipRuleand waiver model, without a second architecture framework.
Adoption is two things: a policy file and one derived class.
{
"$schema": "https://raw.githubusercontent.com/purview-dev/architests/main/architecture-policy.schema.json",
"version": 2,
"sourceRoots": ["src"],
"responsibilities": [
{
"name": "Core",
"aliases": ["Domain"],
"category": "domain",
"purpose": "The domain model, its invariants and its rules.",
"mayDependOn": [],
"mustNotDependOn": ["Application", "Persistence"],
"forbiddenFrameworkReferences": ["Microsoft.AspNetCore.App"]
}
]
}[InheritsTests]
public sealed class ArchitectureTests : PurviewArchitectureTests;
[InheritsTests]is required. TUnit does not walk base types during discovery, so without it the class compiles, the run is green and nothing is enforced. TUnit's analyzer reportsTUnit0030— treat it as an error.
dotnet add package Purview.Architecture.Testing
- Getting started — adopt the package in a repository, step by step.
- Policy reference — every field, every rule id, every default.
- Type-level rules — how the assembly check works and how an assembly is attributed to a project.
- Extending — add your own rule to the standard set.
- The policy schema — the published JSON Schema.
src/samples/ArchitectureSample is a small, fully
working repository that adopts the package: four projects, a policy, and a test project whose whole
suite is one derived class.
dotnet test src/samples/ArchitectureSample/tests/Sample.ArchitectureTests/Sample.ArchitectureTests.csprojsrc/src/ArchitectureTesting— the package: policy reader, project and assembly graph, rule evaluator, and the TUnit base class.src/tests/ArchitectureTesting.UnitTests— rule tests against in-memory and fixture graphs.src/tests/Repository.UnitTests— the skill self-tests and the package applied to this repository.src/samples/ArchitectureSample— the adoption sample.architecture-policy.schema.json— the published policy schema, embedded into the package.skills/— the agent skills this repository publishes.
npx skills add purview-dev/architestsdotnet tool restore
just restore
just build
just test
just lint-check
just pack
just pipeline-pr
Part of Purview.BuildSdk · purview.dev