Skip to content
Purview Dev logo

The problem

Architecture tests for .NET. A repository declares its responsibilities and the dependency directions they may and may not use in a policy file, then derives one test class from PurviewArchitectureTests and gets the standard rule set as separate TUnit tests. The project-level rules read declared ProjectReferences; the type-level rule reads the compiled assemblies' metadata, so a reference that only arrives transitively or through a package is caught too, and nothing is loaded or executed. The set covers dependency direction, sibling independence, composition boundaries, forbidden packages and framework references, cycles, test references and project naming, with reviewed per-project waivers and an extension point for bespoke rules.

From the repository

.NET architecture tests driven by a policy file: declare responsibilities and dependency directions, then enforce them as TUnit tests at the project-reference and compiled-assembly level - including composition boundaries, forbidden packages and framework references, cycles, naming, and reviewed waivers.

Why it became a project

The standard architecture checks were being written into each repository's own test project, so the same dependency-direction and forbidden-reference rules existed in several places and drifted apart. Defining them once — the policy as data, the rule set as a package — means a repository states its architecture rather than re-deriving the tests, and the schema and the rules version together.

Where it fits

Use it when

You have an agreed layering — domain, application, infrastructure, composition — and want it held by the build rather than by review: at the project-reference level and at the type level, including dependencies that arrive transitively or through a package.

It may not fit when

Your architecture is still moving or the layering is not agreed, so a failing dependency rule would be noise rather than a decision — or you need a single repository-specific assertion that a few lines in a test express more directly than a policy file.

Use cases

Concrete examples of what Architests does, and who each one is for.

Developer

The whole rule set from a policy file and one derived class

You want your layering enforced by the build, but you do not want to hand-write the same dependency-direction and forbidden-reference tests in every repository.

csharp
// .config/architecture-policy.json declares the responsibilities.
// This is the entire test suite.
[InheritsTests]
public sealed class ArchitectureTests : PurviewArchitectureTests;

What you get: One policy file plus one derived test class is the whole suite. Each rule is a separate test, so a failure names the rule rather than collapsing the set into one assertion.

The base class ships twelve rule ids as separate [Test]s — graph discovery, naming, discouraged name, dependency matrix, assembly matrix, sibling independence, composition boundary, forbidden package, forbidden framework, cycle, test reference and waiver integrity — plus a schema-validation test that runs first. [InheritsTests] is required: without it TUnit discovers nothing, the run is green and nothing is enforced, which TUnit's own analyzer reports as TUnit0030.

Read Getting started →
Developer

Catch a type-level dependency a ProjectReference never shows

A project file only shows declared ProjectReferences. A type that arrives transitively through another project, or through a package, is invisible to a project-level check.

json
"assemblyRules": {
  "enabled": true,
  "assemblyRoots": [],
  "assemblyGlobs": ["*.dll"]
}

What you get: The same mayDependOn/mustNotDependOn matrix is applied to the types each compiled assembly actually references. An empty assemblyRoots scans the test output directory, which already holds every project the test project references.

The reader opens each assembly with System.Reflection.Metadata and walks the TypeReference table — nothing is loaded, executed, or resolved through a probing path, so a type initialiser never runs. Enabling the rule with no production assemblies found is a failure, not a silent pass.

Read Type-level rules →
Architect

A dependency the policy is silent about is a violation, not permission

Your layering is agreed and documented, and you want a reference that points the wrong way to fail the build rather than erode the design one reasonable-looking reference at a time.

json
{
  "version": 2,
  "sourceRoots": ["src"],
  "responsibilities": [
    {
      "name": "Domain",
      "category": "domain",
      "purpose": "The domain model, its invariants and its rules.",
      "mayDependOn": [],
      "mustNotDependOn": ["Application", "Persistence", "Composition"]
    }
  ]
}

What you get: The matrix is applied three ways: the same responsibility is always allowed, mustNotDependOn is a violation, and a reference the matrix neither permits nor forbids is also a violation — so a gap in the policy is surfaced instead of passing.

A project name is classified by its first segment only, so Persistence.SqlServer and Persistence follow the same rules and qualification is a naming choice rather than a different set of rules.

Read Policy reference →
Team lead

A reviewed waiver instead of switching a rule off

One project legitimately departs from the architecture policy, and you do not want to answer that by disabling the rule for the whole repository.

json
{
  "waivers": [
    {
      "project": "Persistence.Legacy",
      "mapsTo": "Persistence",
      "rules": ["forbiddenPackage"],
      "reason": "The legacy EF6 store is being replaced and still needs EntityFramework.",
      "reviewedOn": "2026-10-16"
    }
  ]
}

What you get: The departure is per project, carries a reason and a review date, keeps every other rule in force, and is itself checked. SkipRule opts a whole repository out with no record, so a waiver is the narrower choice.

Any rule id may be waived, including siblingIndependence and assemblyDependencyMatrix, but an unknown id is a waiverIntegrity failure — a typo cannot silently excuse nothing — and only graphDiscovery and waiverIntegrity are not waivable.

Read Policy reference →
Contributor

Add a bespoke rule to the same reporting and waiver model

You need a repository-specific check — a banned API, a required convention — and do not want a second architecture framework to maintain alongside the standard set.

csharp
[InheritsTests]
public sealed class ArchitectureTests : PurviewArchitectureTests
{
    protected override IReadOnlyList<IArchitectureRule> AdditionalRules => [new NoConsoleLoggingRule()];

    sealed class NoConsoleLoggingRule : IArchitectureRule
    {
        public string Rule => "noConsoleLogging";

        public IReadOnlyList<ArchitectureViolation> Evaluate(ArchitectureContext context) =>
            context.Projects.Values
                .Where(project => !project.IsTestProject)
                .Select(project => new ArchitectureViolation(Rule, project.Name, "Console logging is banned here."))
                .ToArray();
    }
}

What you get: An additional rule runs as its own test, honours SkipRule by its rule id, and is excused by a matching waiver without any extra plumbing — the same reporting the built-in rules use.

The evaluator takes the parsed policy, the project graph and the assemblies as constructor arguments, so a rule is testable as a small in-memory fixture rather than a repository on disk — which is how the package's own rules are tested.

Read Extending →

Packages

1 package

Purview.Architecture.TestingnugetInstall ↓1.2.1—645

Install

.NET CLI
dotnet add package Purview.Architecture.Testing

Agent skills

Architests authors agent skills for coding agents. They are installed explicitly with the skills CLI and are not part of any package.

Skills are installed explicitly with the skills CLI. Nothing ships them inside a NuGet package, and no build writes into your agent's directories: installation is a decision you make. Use whichever package manager you already have.

npm

Terminal window
npx skills add purview-dev/architests

bun

Terminal window
bunx skills add purview-dev/architests

pnpm

Terminal window
pnpm dlx skills add purview-dev/architests

yarn

Terminal window
yarn dlx skills add purview-dev/architests
  • Installs at project level by default. Add -g for a user-level install, or -a <agent> to target one agent.
  • To match the release you use, pin a commit or tag by appending #<ref> to any command above (for example npx skills add purview-dev/architests#<ref>).
  • The CLI records what it installed in skills-lock.json; restore it with the same runner:
Terminal window
npx skills experimental_install
  • purview-architests

    Adopt or debug Purview.Architecture.Testing, the package that enforces a repository's project and type-level dependency policy as TUnit tests. Use when adding architecture tests to a repository, writing or changing .config/architecture-policy.json, validating a policy with the architests tool, enabling the assembly, type, API or port rules, recording or expiring a waiver, setting a dependency budget, interpreting a policy-integrity, dependency-matrix, type-level, cycle, sibling-independence, composition-boundary, forbidden-package, framework-reference or naming failure, or when the architecture tests pass but enforce nothing.

    1 file
  • purview-architests-contracts

    Use when enabling or debugging Purview.Architecture.Testing's committed-API and port rules - apiSurface, apiDocumentation, portImplementation and portPurity. Covers capturing and reviewing .config/api-surface.json, reading an added or breaking API change, requiring XML documentation, and keeping an inner-layer port implemented and technology-neutral.

    1 file
  • purview-architests-extending

    Use when adding a bespoke rule to Purview.Architecture.Testing, implementing IArchitectureRule, or working on the package's internals - the three-layer design, the project graph, the metadata-only assembly reader, or the evaluator. Covers the ArchitectureContext, what an additional rule gets for free, and testing a rule against an in-memory fixture.

    1 file
  • purview-architests-migration

    Use when adopting Purview.Architecture.Testing in an existing repository that already has tangled dependencies, or when ratcheting an adopted policy tighter. Covers a permissive first policy, committing the API baseline before enforcing it, recording narrow waivers instead of using SkipRule, starting an empty dependency budget, and tightening one rule at a time without a big-bang rewrite.

    1 file
  • purview-architests-policy-authoring

    Use when authoring or changing .config/architecture-policy.json for Purview.Architecture.Testing - defining responsibilities, categories, mayDependOn and mustNotDependOn, choosing sourceRoots, adding aliases, recording a waiver, setting waiver expiry, or fixing a policyIntegrity failure. Covers the version-3 document, the matrix semantics, and how to validate a policy without running the tests.

    1 file
  • purview-architests-type-rules

    Use when enabling or debugging Purview.Architecture.Testing's type-level rules - typeNaming, typeShape, typeNamespace and attributePolicy. Covers the typeRules policy section, which public types are governed, why a type is reported as unsealed or outside its root namespace, how generated code and nested types are treated, and how to fix or waive each finding.

    1 file