Application Layer (.NET)¶
This chapter documents the .NET application layer of the example: a small
layered ASP.NET Core application (MyApp) whose quality gates, architecture
policies, API contract, and diagrams are all deterministically generated
from code — the same documentation-as-code discipline the pipeline applies
to Terraform, OPA, and DSC.
Chapter Map¶
| Page | What it documents | Generated by |
|---|---|---|
| Code Quality Gate | The Roslyn analyzer gate: NetAnalyzers, Roslynator, SonarAnalyzer, security rules as errors (TreatWarningsAsErrors) |
maintained by hand (rules live in dotnet/Directory.Build.props + dotnet/.editorconfig) |
| Architecture Policies | The NetArchTest policy suite: APP-ARCH-001..003, APP-SEC-001 | scripts/generate-dotnet-policy-docs.py (from Policy.Define metadata in the test suite) |
| Architecture Diagrams | C4 Context / Container / Component diagrams | dotnet/tools/MyApp.Architecture.Diagrams (C4Sharp) + scripts/generate-c4-diagram-docs.py |
| API Reference (OpenAPI) | The HTTP API contract | dotnet build (native Microsoft.AspNetCore.OpenApi) + scripts/generate-openapi-docs.py |
| .NET API Reference (DocFX) | The C# API reference, per assembly | DocFX (dotnet/docs/docfx.json) |
| TDS API Export (Filtered) | The public API surface filtered for TDS composition, with <spec> requirement traces |
scripts/generate-dotnet-doc-export.py (from build-time XML doc files) |
Requirements and Decisions¶
The application layer is governed by the MoSCoW requirements APP-001 – APP-008 (see MoSCoW Prioritisation) and the .NET ADR series:
| ADR | Decision |
|---|---|
| ADR-0013 | DocFX for the .NET API reference |
| ADR-0014 | NetArchTest.Rules as the architecture-policy engine |
| ADR-0015 | Native build-time OpenAPI generation (no Swashbuckle) |
| ADR-0016 | Roslyn analyzers as the code-quality gate |
| ADR-0017 | C4Sharp for code-declared C4 diagrams |
| ADR-0022 | Filtered .NET API export from build-time XML doc comments |
Code-to-requirement traceability¶
Since ADR-0022, application
types and members declare the requirements they implement with
<spec> XML doc tags (for example <spec>moscow:M-001</spec> on
TodoService). The export tool verifies every tag against the
traceability metadata contract,
so application code and specification cannot drift apart silently —
and the filtered TDS API export
carries the traces into the composed document.
The full requirement → ADR → policy → implementation chain is documented in the Traceability Matrix.
Layering¶
The solution lives in example/dotnet/ and follows a strict layering —
enforced by the NetArchTest policies, not just convention:
graph LR
Api["MyApp.Api<br/><i>controllers, DTO mapping</i>"]
Application["MyApp.Application<br/><i>services, DTOs, interfaces</i>"]
Domain["MyApp.Domain<br/><i>entities, pure model</i>"]
Infrastructure["MyApp.Api.Infrastructure<br/><i>InMemoryTodoRepository</i>"]
Tests["MyApp.ArchitectureTests<br/>+ MyApp.UnitTests"]
Diagrams["MyApp.Architecture.Diagrams<br/><i>C4Sharp tool</i>"]
Api --> Application
Application --> Domain
Infrastructure -.->|"implements"| Application
Tests -.->|"verifies"| Api
Tests -.->|"verifies"| Application
Tests -.->|"verifies"| Domain
Diagrams -.->|"declares model of"| Api
Dependencies flow strictly downward (Api → Application → Domain); the domain layer references nothing above it (APP-ARCH-002), controllers talk only to application services (APP-ARCH-001) and never expose domain entities over the wire (APP-SEC-001).
Running Locally¶
cd example/dotnet
dotnet build MyApp.slnx -c Release # build + Roslyn gate + OpenAPI export
dotnet test MyApp.slnx --no-build # 9 unit tests + 4 architecture policies
See the Developer Guide onboarding for the full local pipeline walkthrough.