Enforces .NET architectural boundaries using NetArchTest and ArchUnitNET fitness functions for dependencies, layers, and performance. Generates test code and validates rules.
How this skill is triggered — by the user, by Claude, or both
Slash command
/enterprise-architecture:fitness-functionsThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use this skill when you need to:
Use this skill when you need to:
Keywords: fitness functions, architecture tests, NetArchTest, ArchUnitNET, dependency rules, layer constraints, architectural boundaries, module isolation, architecture validation, performance tests
Fitness functions are automated tests that validate architectural characteristics. They provide objective, repeatable verification that the system maintains desired properties as it evolves.
| Type | Validates | Example |
|---|---|---|
| Dependency | Component relationships | "Domain cannot depend on Infrastructure" |
| Layer | Vertical slice rules | "Controllers only call Application layer" |
| Naming | Convention compliance | "Handlers must end with 'Handler'" |
| Performance | Runtime characteristics | "API response < 200ms at p95" |
| Cyclomatic | Code complexity | "No method > 10 cyclomatic complexity" |
# For NetArchTest (simpler, recommended for most cases)
dotnet add package NetArchTest.Rules
# For ArchUnitNET (more powerful, Java-like syntax)
dotnet add package ArchUnitNET
dotnet add package ArchUnitNET.xUnit # or .NUnit
dotnet new xunit -n YourSolution.ArchitectureTests
dotnet add YourSolution.ArchitectureTests reference src/YourSolution.Domain
dotnet add YourSolution.ArchitectureTests reference src/YourSolution.Application
dotnet add YourSolution.ArchitectureTests reference src/YourSolution.Infrastructure
public class DependencyTests
{
[Fact]
public void Domain_ShouldNotDependOn_Infrastructure()
{
var result = Types.InAssembly(typeof(Order).Assembly)
.ShouldNot()
.HaveDependencyOn("YourSolution.Infrastructure")
.GetResult();
Assert.True(result.IsSuccessful, result.FailingTypeNames?.FirstOrDefault());
}
}
NetArchTest provides a fluent API for testing architectural constraints.
Detailed patterns: See references/netarchtest-patterns.md
// Dependency constraints
Types.InAssembly(domainAssembly)
.ShouldNot()
.HaveDependencyOn("Microsoft.EntityFrameworkCore");
// Naming conventions
Types.InAssembly(applicationAssembly)
.That()
.ImplementInterface(typeof(IRequestHandler<,>))
.Should()
.HaveNameEndingWith("Handler");
// Layer isolation
Types.InNamespace("Domain")
.ShouldNot()
.HaveDependencyOnAny("Application", "Infrastructure", "Api");
ArchUnitNET offers more expressive rules with a syntax similar to ArchUnit for Java.
Detailed patterns: See references/archunitnet-patterns.md
// Define architecture layers
private static readonly Architecture Architecture =
new ArchLoader().LoadAssemblies(
typeof(Order).Assembly,
typeof(OrderHandler).Assembly,
typeof(OrderRepository).Assembly
).Build();
private static readonly IObjectProvider<IType> DomainLayer =
Types().That().ResideInNamespace("Domain").As("Domain Layer");
private static readonly IObjectProvider<IType> InfrastructureLayer =
Types().That().ResideInNamespace("Infrastructure").As("Infrastructure Layer");
[Fact]
public void DomainLayer_ShouldNotDependOn_InfrastructureLayer()
{
IArchRule rule = Types().That().Are(DomainLayer)
.Should().NotDependOnAny(InfrastructureLayer);
rule.Check(Architecture);
}
Common dependency rules for modular monoliths:
Full catalog: See references/dependency-rules.md
[Fact]
public void Modules_ShouldNotCrossReference_CoreProjects()
{
var orderingCore = Types.InAssembly(typeof(Order).Assembly);
var inventoryCore = Types.InAssembly(typeof(Product).Assembly);
// Ordering.Core cannot reference Inventory.Core
var result = orderingCore
.ShouldNot()
.HaveDependencyOn("Inventory.Core")
.GetResult();
Assert.True(result.IsSuccessful);
}
[Fact]
public void SharedKernel_ShouldNotDependOn_AnyModule()
{
var sharedKernel = Types.InAssembly(typeof(Entity).Assembly);
var result = sharedKernel
.ShouldNot()
.HaveDependencyOnAny(
"Ordering", "Inventory", "Shipping", "Customers")
.GetResult();
Assert.True(result.IsSuccessful);
}
Test runtime characteristics to ensure performance standards.
Detailed guide: See references/performance-fitness.md
[Fact]
public async Task Api_ShouldRespondWithin_200ms()
{
var client = _factory.CreateClient();
var stopwatch = Stopwatch.StartNew();
var response = await client.GetAsync("/api/orders/123");
stopwatch.Stop();
Assert.True(stopwatch.ElapsedMilliseconds < 200,
$"Response took {stopwatch.ElapsedMilliseconds}ms");
}
[Fact]
public void Handler_ShouldNotAllocateExcessiveMemory()
{
var before = GC.GetTotalMemory(true);
for (int i = 0; i < 1000; i++)
{
_handler.Handle(new GetOrderQuery(Guid.NewGuid()));
}
var after = GC.GetTotalMemory(true);
var allocated = (after - before) / 1000; // Per operation
Assert.True(allocated < 10_000, $"Allocated {allocated} bytes per operation");
}
Use these templates to quickly create architecture tests:
references/templates/architecture-test-template.cs - Full test class scaffoldreferences/templates/performance-test-template.cs - Performance test patterns# Copy template and customize
cp templates/architecture-test-template.cs tests/ArchitectureTests.cs
- name: Run Architecture Tests
run: dotnet test --filter Category=Architecture
continue-on-error: false # Fail pipeline on violations
[Trait("Category", "Architecture")]
public class DependencyTests
{
// Architecture tests run separately from unit tests
}
Fitness functions enforce the boundaries discovered through event storming:
Event Storming → Bounded Contexts
↓
Modular Architecture → Module Structure
↓
Fitness Functions → Enforce Boundaries
After event storming identifies bounded contexts:
Test finds no types:
False positives:
Performance tests flaky:
references/netarchtest-patterns.md - NetArchTest usage patternsreferences/archunitnet-patterns.md - ArchUnitNET usage patternsreferences/performance-fitness.md - Performance testing patternsreferences/dependency-rules.md - Common dependency rules catalogreferences/templates/architecture-test-template.cs - Test class templatereferences/templates/performance-test-template.cs - Performance test templateWhen invoked directly by the user, this skill analyzes architecture fitness and optionally generates tests.
--generate flag, and --framework preference (netarchtest or archunitnet).--generate) - Spawn fitness-function-generator agent to create test project with DependencyTests, NamingConventionTests, and StructureTests.Date: 2025-12-22 Model: claude-opus-4-5-20251101
npx claudepluginhub melodic-software/claude-code-plugins --plugin enterprise-architectureDesigns architectural fitness functions as GC rules for periodic checks of system-wide properties like layer boundaries, coupling trends, complexity hotspots, and test coverage decline.
Design metrics that measure architecture health (coupling, modularity, scalability). Automate fitness function checks in CI/CD. Use when establishing quality gates or measuring architectural degradation.
Enforces architectural rules (layer responsibilities, dependency direction, structure) when generating or reviewing code. Supports clean/hexagonal/onion/monolith architectures via loaded rule sets.