📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you document and communicate the architecture of a .NET system so it stays useful? Explain Architecture Decision Records, the C4 model, and how fitness functions keep the real system aligned with the documented architecture.

Documenting architecture: ADRs (format, lifecycle, where they live), C4 diagrams as code, and fitness functions (architecture tests, performance and dependency checks) that keep docs and code aligned.

Senior Architecture Advanced adr architecture architecture-tests c4-model documentation fitness-functions

🎯 Key points

  • ADR = short record of one decision: context, decision, alternatives, consequences, status; immutable, superseded not edited
  • Keep ADRs in the repo next to the code (docs/adr), reviewed by pull request
  • C4 model: Context, Containers, Components, Code; most teams need only the first two or three levels
  • Diagrams as code (Structurizr DSL, Mermaid, PlantUML) so they are versioned and reviewed
  • Fitness functions check that the running code still meets the architectural decisions and constraints (ArchUnitNET/NetArchTest tests, load tests, vulnerable-package checks, Azure Policy, SLO alerts); as a side effect they keep code and docs aligned
  • Audience-specific communication: context diagram for stakeholders, containers for engineers, ADRs for future maintainers
  • Living documentation: ADR prompt in the PR template, revisit triggers in each ADR, quarterly review against the live application map, and onboarding feedback used to fix gaps

⏱ 30-second answer

I use three tools that reinforce each other. Architecture Decision Records capture each significant decision in one short page: context, decision, alternatives, consequences and status. They live in the repo and are reviewed by pull request; when a decision changes, a new ADR supersedes the old one.

The C4 model gives diagrams at the right zoom level: System Context for stakeholders, Containers for engineers, Components where it helps. I keep them as code (Structurizr DSL or Mermaid) so they're versioned.

Fitness functions stop the docs from lying: architecture tests (ArchUnitNET), load tests and dependency checks that fail the build when the code drifts from the decisions.

The trade-off: documentation costs time, so I keep it small and automate the checks instead of writing long documents nobody reads.

🗣 Full answer (senior)

How I would answer this in an interview

"I want architecture documentation that answers two questions for someone joining next year: what does the system look like, and why is it like this? For the 'why', I use Architecture Decision Records. Each ADR is one page in docs/adr in the repo: the context, the decision, the options we rejected, and the consequences, good and bad. They're reviewed by pull request like code, numbered, and never rewritten; if we change our mind, a new ADR supersedes the old one, so the history stays honest.

For the 'what', I use the C4 model. A System Context diagram shows the system, its users and external systems, which is what stakeholders and security reviewers need. A Container diagram shows the deployables and data stores: the API, the worker, Azure SQL, Service Bus. I only go down to Components for complex areas, and almost never to Code. I keep the diagrams as code in Structurizr DSL or Mermaid in the same repo. For example, at [company] our architecture lived in a [Confluence page last updated two years earlier]. I moved it into the repo as [12] ADRs reconstructed with the team, plus C4 context and container diagrams, and linked each key ADR to a fitness function, such as an ArchUnitNET test that Billing can't reference Ordering internals, and a load test enforcing our p95 target. Onboarding time for new engineers went from [about four weeks] to [two], and the architecture tests caught [nine] boundary violations in the first quarter.

The mistake I see is big up-front documents that are out of date in a month. My senior line is: write down decisions, not descriptions, and let automated checks keep the description true."


The three tools

Tool Answers Audience Lives in
ADRs Why is it like this? Engineers, future maintainers, reviewers docs/adr/NNNN-title.md
C4 diagrams What does it look like at each zoom level? Stakeholders (Context), engineers (Containers/Components) Diagrams as code in the repo
Fitness functions Is it still true? CI pipeline Test projects, pipeline steps, monitoring

C4 levels

Level Shows Use it for
1. System Context System, users, external systems Stakeholders, security and privacy reviews
2. Containers Deployables and data stores, protocols Engineering, operations, threat modelling
3. Components Major parts inside one container Complex containers only
4. Code Classes Rarely; generate from IDE if needed

Examples of fitness functions

Decision (ADR) Fitness function
Modules communicate only via contracts ArchUnitNET test in CI
p95 < 300 ms for search Azure Load Testing run with pass/fail criteria
No known critical vulnerabilities dotnet list package --vulnerable failing the build
Personal data stays in Australia East Azure Policy allowed-locations assignment
Availability 99.9% SLO burn-rate alert in Azure Monitor

Production example

Moving architecture docs into the repo as ADRs and C4-as-code, with fitness functions for the top decisions, halved onboarding time from [four] to [two] weeks and caught [nine] boundary violations in CI in the first quarter.

🔍 What the interviewer is checking

Checks whether the candidate can make architecture knowledge durable and enforceable, and use documentation to build alignment.

Green flags

  • ADR format with alternatives, consequences and supersession
  • C4 at the right levels, diagrams as code
  • Fitness functions linked to decisions
  • Tailors communication to audiences and uses ADRs to build consensus

Red flags

  • Long up-front design documents only
  • Diagrams with no notation or zoom level
  • No way to detect drift between docs and code

📚 Learn in depth

1. Why decisions, not descriptions

Code shows what the system does; it rarely shows why. The why is lost first: people leave, chat history disappears. Michael Nygard's ADR format (2011) keeps it lightweight enough that people actually write them.

# 0007. Use a modular monolith on Azure App Service

Status: Accepted (supersedes 0002)
Date: 2026-03-14

## Context
One team of 6, ~40 req/s peak, rules change each budget cycle, data must stay in Australia East.

## Decision
Single deployable with modules per subdomain; schema per module in one Azure SQL database.

## Alternatives considered
Microservices on AKS (rejected: ops cost, team size). Plain layered monolith (rejected: weak boundaries).

## Consequences
+ Low ops cost, simple deploys. - Must enforce boundaries with tests. Revisit if > 3 teams or > 500 req/s.

Statuses: Proposed → Accepted → (Deprecated | Superseded by NNNN). Tooling such as adr-tools or log4brains helps but isn't required.

2. Which decisions deserve an ADR

Architecturally significant ones: hard to reverse, affect quality attributes, cross teams, or surprised someone. Examples: choosing a message broker, data ownership rules, authentication approach, the decision not to use microservices. Skip trivial library choices.

3. The C4 model

Simon Brown's C4 uses a small vocabulary: people, software systems, containers (deployable or data store, not Docker specifically), components.

Level 1: System Context
  [Broker] ──uses──► [Quoting System] ──sends email via──► [SendGrid]
                          │
                          └──reads policies from──► [Legacy Policy Admin]

Level 2: Containers (inside Quoting System)
  [Web app: Blazor] ──HTTPS/JSON──► [API: ASP.NET Core] ──EF Core──► [Azure SQL]
                                        │
                                        └──AMQP──► [Service Bus] ──► [Worker: .NET]

Diagrams as code (Structurizr DSL, Mermaid C4Context, PlantUML C4) put diagrams under version control and in pull requests. Some teams also generate a live view from telemetry, such as the Application Insights application map, and compare it with the intended container diagram.

4. Fitness functions

From Building Evolutionary Architectures (Ford, Parsons, Kua): an objective function that assesses how close the system is to an architectural characteristic. Kinds:

  • Atomic vs holistic: one rule (dependency test) vs system-wide (load test).
  • Triggered vs continuous: in CI vs monitoring in production.
  • Static vs dynamic: code structure vs runtime behaviour.

In .NET: ArchUnitNET or NetArchTest for dependency rules, Roslyn analysers for coding rules, BenchmarkDotNet for micro-performance, Azure Load Testing or k6 for throughput, dotnet list package --vulnerable for supply chain, Azure Policy for infrastructure rules, SLO alerts for availability.

5. Keeping it alive

  • ADR link in the PR template ("Does this change need an ADR?").
  • ADRs reference the fitness function that enforces them; tests reference the ADR in their name or comment.
  • Review triggers in each ADR ("revisit if...").
  • A quarterly 30-minute architecture review of diagrams against the live application map.

6. Communicating for influence

The same decision needs different framing: a one-paragraph business summary for leadership (cost, risk, time), a C4 container diagram for engineers, a threat model for security. Writing an ADR as a Proposed decision and inviting comments by PR is a low-friction way to build consensus and record dissent.

Try it yourself

  1. Write ADR 0001 "Record architecture decisions" and one ADR for a real past decision.
  2. Draw a C4 Context and Container diagram for a system you know in Structurizr DSL or Mermaid.
  3. Add an ArchUnitNET test enforcing one rule from an ADR, referencing the ADR number.
  4. Add a pipeline step that fails on vulnerable packages.
  5. Compare your Container diagram with the Application Insights application map and note differences.

💻 Code

Linking an ADR to a fitness function: an ArchUnitNET test that enforces the module boundary decision.

namespace Quoting.ArchitectureTests;

using ArchUnitNET.Domain;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

public class ModuleBoundaryTests
{
    private static readonly Architecture Architecture = new ArchLoader()
        .LoadAssemblies(typeof(Billing.Core.BillingModule).Assembly,
                        typeof(Ordering.Core.OrderingModule).Assembly)
        .Build();

    // Enforces ADR-0007: modules communicate only through *.Contracts.
    [Fact]
    public void Billing_does_not_depend_on_Ordering_internals() =>
        Types().That().ResideInNamespace("Billing", useRegularExpressions: false)
            .Should().NotDependOnAny(Types().That().ResideInNamespace("Ordering.Core"))
            .Because("ADR-0007: modules may only reference other modules' Contracts")
            .Check(Architecture);
}
workspace "Quoting" {
    model {
        broker = person "Broker"
        quoting = softwareSystem "Quoting System" {
            web = container "Web app" "Blazor"
            api = container "API" "ASP.NET Core 10"
            db  = container "Database" "Azure SQL (Australia East)"
        }
        broker -> web "Creates quotes"
        web -> api "HTTPS/JSON"
        api -> db "EF Core"
    }
    views { container quoting { include * autolayout lr } }
}
# Pipeline fitness function: fail on known vulnerable packages.
- script: |
    dotnet list package --vulnerable --include-transitive | tee vuln.txt
    ! grep -q "has the following vulnerable packages" vuln.txt
  displayName: Fail on vulnerable packages

⚠ Common mistakes

  • Mistake: Writing one big architecture document up front. Why it is wrong: It goes stale within weeks and nobody trusts it. Instead: Small ADRs per decision plus C4 diagrams as code, updated by PR.
  • Mistake: Editing old ADRs when the decision changes. Why it is wrong: You lose the history of why things changed. Instead: Write a new ADR that supersedes the old one.
  • Mistake: ADRs without alternatives or consequences. Why it is wrong: Readers can't tell whether the context has changed enough to revisit. Instead: Always list rejected options, trade-offs and revisit triggers.
  • Mistake: Diagrams in a drawing tool outside the repo. Why it is wrong: They aren't reviewed and drift from reality. Instead: Diagrams as code next to the source.
  • Mistake: Drawing every C4 level for everything. Why it is wrong: Code-level diagrams are expensive and stale immediately. Instead: Context and Containers always; Components only where complex.
  • Mistake: Documenting rules without enforcing them. Why it is wrong: Rules erode silently under deadline pressure. Instead: Fitness functions in CI and monitoring that reference the ADR.
  • Mistake: One format for every audience. Why it is wrong: Leadership won't read an ADR; engineers need more than a slide. Instead: Tailor: business summary, context diagram, container diagram, ADR.

🏛 Senior insight: trade-offs

Documentation is an influence tool, not just a record. A Proposed ADR raised as a pull request gives everyone a place to disagree in writing, and the final ADR records the dissent and the reasons. When I disagree with a decision but the team goes another way, I make sure the ADR captures the risk and a revisit trigger, then commit to it fully.

The automation is what makes documentation trustworthy. I aim for every high-impact ADR to have at least one fitness function; if a decision can't be checked automatically, I add it to a lightweight quarterly review.

Option When it fits Cost When not to
ADRs in repo Any team making significant decisions Low Trivial, easily reversed choices
C4 Context + Containers Every system Low —
C4 Components Complex containers, onboarding hot spots Medium Simple CRUD services
Fitness functions in CI Rules that can be checked statically or by test Low-medium Rules needing human judgement
Wiki-only docs Non-engineering audiences Low Anything that must stay in sync with code

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions fitness functions Why: Checks their understanding of evolutionary architecture
    How to answer

    Evolutionary architecture (Ford, Parsons and Kua) is architecture designed to support guided, incremental change, rather than a fixed upfront design. The key tool is fitness functions: automated checks that protect the characteristics you care about, such as dependency rules (architecture tests), latency budgets, or startup time, run in CI or production. Around that, I keep boundaries modular (often a modular monolith first), make decisions reversible where possible and defer irreversible ones to the last responsible moment, record decisions in ADRs, and rely on continuous delivery, feature flags and observability so each change is small and safe.

  2. When: Candidate mentions ArchUnitNET or NetArchTest Why: Checks they can implement architecture tests in .NET
    How to answer

    Make the rules executable at several levels:

    • Project references enforce dependency direction at compile time (Domain can't see Infrastructure if it doesn't reference it).
    • internal hides implementation types so other projects can't use them.
    • Architecture tests check rules the compiler can't: "Domain must not depend on Microsoft.EntityFrameworkCore", "Billing may only use Orders.Contracts". ArchUnitNET (actively maintained) or NetArchTest (the original is unmaintained since 2021; the eNhancedEdition fork is maintained) inspect compiled assemblies inside a normal test run.
    • Analysers, such as the banned-API analyser, block specific calls like DateTime.Now.

    Roll out with a baseline so legacy violations don't block the build. The trade-off: cheap, fast feedback, but only for static dependencies.

  3. When: Candidate says ADRs record alternatives and trade-offs Why: Checks how they reach the decision the ADR records
    How to answer

    I start from the business drivers, not the technology. I ask what the system must be good at and turn that into a short, ranked list of quality attributes: scalability, availability, modifiability, security, cost. Then I make each one measurable as a quality attribute scenario ("p95 under 300 ms at 500 requests a second"), and I list the constraints I can't change: budget, deadline, compliance such as data staying in Azure Australia East, and the team's size and skills.

    • The ranking forces trade-offs: high availability and low cost pull in opposite directions.
    • Conway's law matters: one team of six almost never needs ten services.
    • I record the choice in an ADR with the alternatives I rejected.

    The trade-off is always the same: the architecture that best serves the top two attributes will be worse at something else, and I want that cost written down.

🛠 Real-world problems: how you handle them

Stale wiki architecture replaced with ADRs, C4-as-code and fitness functions
Situation
A [quoting platform] team of [10] had architecture docs in a [Confluence page last updated two years ago]; new engineers took about [four weeks] to become productive, and module boundaries were eroding.
Signals
Repeated debates about past decisions in PRs, new code calling other modules' internals, an Application Insights application map that didn't match any diagram, and onboarding feedback naming 'no idea why things are like this'.
Investigation
I compared the wiki diagrams with the application map and the solution's project references, ran a one-off ArchUnitNET scan that found [30+] cross-module dependencies, and interviewed long-serving engineers to recover key decisions.
Resolution
Immediate: documented the top five decisions as ADRs and drew C4 Context and Container diagrams in Structurizr DSL in the repo. Long-term: an ADR question in the PR template, ArchUnitNET tests referencing ADR numbers, and the existing violations burned down over [two] sprints.
Prevention
Fitness functions in CI (architecture tests, vulnerable package check, load test with pass/fail criteria), a quarterly 30-minute review of diagrams against the application map, revisit triggers in each ADR.

How to tell it (STAR)

**S:** At [company] our architecture docs were two years out of date, onboarding took about [four weeks], and modules were calling each other's internals. **T:** I volunteered to make the architecture understandable and enforceable. **A:** I recovered [12] key decisions with the team as ADRs in the repo, drew C4 Context and Container diagrams as code, and linked the main decisions to ArchUnitNET tests and pipeline checks. I added an ADR prompt to the PR template so new decisions get recorded. **R:** Onboarding dropped to about [two weeks], and the tests caught [nine] boundary violations in the first quarter before they merged.

↩ Usually asked after

More in Senior-Level Architecture

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me