Skip to content

ADR: Live code samples

ADR: Live code samples

Status
accepted
Date
2026-09-02
Shipped as
1.0.0.16

In plain words

The code shown in these documents is not pasted in. It is read from the running build every time a page opens, with a link to the exact lines on GitHub.

What that is worth: a reader never sees out-of-date code, and the organization's documentation stays true without anyone remembering to update it.

Context

Steve's standing rule for this project: every change ships with its decision record, and the record links to the code and carries live code samples where possible. The records had the links, and they had samples, but the samples were copies, pasted in at the commit that shipped them. Copies rot. Within a day the phone-header record was showing a header block that no longer existed, because the sidebar had replaced it. A decision record that shows stale code is worse than one that shows none, since it reads as the truth.

Decision

A doc may hold an empty fenced block whose info string names a file and a region, and the API expands it at request time into the current lines of that file, read from inside the running image.

  • The block. Three backticks, the word live, then path= and region=. Nothing else in the doc changes. The served markdown carries an ordinary fenced block with a language tag chosen from the extension, then one italic line naming the file, the region, and the commit the build came from, with a link straight to those lines on GitHub at that commit. The word live never reaches the client.
  • The region. A comment pair in the source, #region NAME and #endregion NAME, in whatever comment syntax the file uses. Names beat line numbers because line numbers rot the moment a line is added above them. A named end marker lets regions nest.
  • The image carries the source. The Dockerfile copies src, .github/workflows, and the API's .cs, .csproj and .slnx files into the runtime image beside the docs it already carried. Photos and the built bundle were already there. The addition measured 279,121 bytes across 89 files when this was written; the whitelist has widened twice since (the addenda below), and the image now carries 367,822 bytes across 119 files, uncompressed, before Docker's layer compression.
  • The whitelist is code, checked before any filesystem touch. A path is allowed only when it is plain characters and forward slashes, has no empty, dot, or parent segment, and starts under one of the allowed roots (src/, api/, infra/, .github/ when this was written, plus tests/ and edge/ since) or is one of the named root files listed in the first addendum below. That is a string check. Only then does the expander resolve the full path, confirm it still sits inside the repo root, and read the file.
  • The fallback is a sentence, never a 500. A path off the roots, a missing file, a region that is not there, or a file that cannot be read renders one italic line beginning "Sample unavailable" with the reason. The rest of the doc serves normally. An unterminated block is left as it was written.
  • Every docs endpoint expands. One helper serves every markdown file under docs/, so any record can use a live block from now on, and a doc with no live blocks passes through untouched.

In the code

The whitelist, read from this build (api/TheYard.Api/Features/Docs/LiveSamples.cs):

/// <summary>
/// The only roots a live block may read from, relative to the repo root. The last one is the
/// sample's test folder and nothing else under samples/: the onion practices page shows the
/// sample's architecture tests whole, and the rest of the sample is served by its own site.
/// </summary>
public static readonly string[] AllowedRoots = ["src/", "api/", "infra/", ".github/", "tests/", "edge/", "scripts/", "render/", ".vscode/", "samples/theshed/tests/", "functions/jobhunt/", "server/JobHunt.Server.Application/Features/Archive/"];

/// <summary>The single files at the repo root a live block may read: the ones the records decide (ADR-017).</summary>
public static readonly string[] AllowedFiles = ["Dockerfile", "netlify.toml", "playwright.config.ts", "vite.config.ts", "package.json", "index.html", "tsconfig.json", "tsconfig.app.json", "tsconfig.node.json", ".editorconfig", ".coderabbit.yaml"];

/// <summary>
/// A relative path is allowed when it is plain (letters, digits, dot, dash,
/// underscore, forward slashes), starts under an allowed root, and has no
/// parent-directory segment anywhere. Pure string checks: no filesystem.
/// </summary>
// NotNullWhen is the whole fix for the one nullable warning this build
// carried: the guard inside already proves path is not null when it
// returns true, and the attribute is how that proof reaches the caller.
public static bool IsAllowedPath([NotNullWhen(true)] string? path)
{
    if (string.IsNullOrWhiteSpace(path) || !PlainPath().IsMatch(path))
    {
        return false;
    }
    if (path.Split('/').Any(segment => segment is "" or "." or ".."))
    {
        return false;
    }
    return AllowedFiles.Contains(path, StringComparer.Ordinal)
        || AllowedRoots.Any(root => path.StartsWith(root, StringComparison.Ordinal) && path.Length > root.Length);
}

Live from api/TheYard.Api/Features/Docs/LiveSamples.cs, region whitelist, read from this build at 99df7a8.

The expander, showing itself. This is the most self-referential sample in the building, and it is shown here with a straight face because it is the only sample that cannot possibly be stale:

/// <summary>
/// Replaces every live block in <paramref name="markdown"/> with the current
/// sample, or with a one-line note when the sample cannot be shown. Lines
/// outside live blocks pass through untouched.
/// </summary>
public static string Expand(string markdown, string repoRoot, string commit)
{
    string[] lines = markdown.Split('\n');
    var output = new List<string>(lines.Length + 16);
    for (int i = 0; i < lines.Length; i++)
    {
        var open = OpenFence().Match(lines[i].TrimEnd('\r'));
        if (!open.Success)
        {
            output.Add(lines[i]);
            continue;
        }
        int close = i + 1;
        while (close < lines.Length && lines[close].TrimEnd('\r') != "```")
        {
            close++;
        }
        if (close >= lines.Length)
        {
            // An unterminated block is left alone rather than guessed at.
            output.Add(lines[i]);
            continue;
        }
        var attrs = ParseAttributes(open.Groups["attrs"].Value);
        output.Add(Render(attrs.GetValueOrDefault("path"), attrs.GetValueOrDefault("region"), repoRoot, commit));
        i = close;
    }
    return string.Join('\n', output);
}

Live from api/TheYard.Api/Features/Docs/LiveSamples.cs, region expander, read from this build at 99df7a8.

The one endpoint every document goes through, since ADR: The staff review folded the per-document routes into a catalog (api/TheYard.Api/Features/Docs/DocumentationEndpoints.cs, api/TheYard.Api/Shared/Documentation/DocumentationCatalog.cs):

// One route for every document (ADR-017): the slug is looked up in the catalog
// (DocumentationCatalog.cs, the same slugs src/library/records.ts and pages.ts carry), the file
// is read from the repo root and its live blocks are expanded (ADR-014). A slug
// missing from the catalog is a 404, never a file read. The Bicep file and the
// resume keep their own routes below because they are not markdown; a literal
// route wins over the {slug} pattern.
app.MapGet("/api/docs/{slug}", Document)
    .WithName("GetDocument")
    .WithTags("Documents")
    .WithSummary("One of the served documents, as markdown with its code samples expanded")
    .WithDescription("The slug is one the sidebar offers: readme, architecture, a record such as adr-openapi. "
        + "Every live block is read from this build at request time.")
    .Produces<string>(StatusCodes.Status200OK, "text/markdown")
    .ProducesProblem(StatusCodes.Status404NotFound);

Live from api/TheYard.Api/Features/Docs/DocumentationEndpoints.cs, region docs-endpoint, read from this build at 99df7a8.

The rejection cases the tests hold the whitelist to, read from this build (api/TheYard.Tests/LiveSamplesTests.cs):

[Theory]
[InlineData("../README.md")]
[InlineData("/etc/passwd")]
[InlineData("src/../docs/secret.md")]
[InlineData("docs/secret.md")]
[InlineData("api\\TheYard.Api\\Program.cs")]
[InlineData("src/")]
[InlineData("")]
[InlineData(".env")]
[InlineData("package-lock.json")]
[InlineData("docs/CHANGELOG.md")]
[InlineData("Dockerfile.bak")]
[InlineData("samples/theshed/Program.cs")]
public void Paths_off_the_roots_or_with_escapes_are_rejected_as_strings(string path)
{
    Assert.False(LiveSamples.IsAllowedPath(path));
}

Live from api/TheYard.Tests/LiveSamplesTests.cs, region rejection, read from this build at 99df7a8.

The copy lines are in the Dockerfile, which the first addendum below added to the whitelist, so other records now show it live.

What this replaced

Copied excerpts in ADR: The deploy pipeline, ADR: The phone header, ADR: The changelog, and ADR: The sidebar. Each now holds live blocks, and each keeps its prose as the statement of intent while the block shows the current truth. Where a record described code that no longer exists, the prose says so and the block shows what stands today.

The alternative considered was fetching samples from GitHub in the browser at view time. It would have kept the image smaller and tied the sample to main rather than to the running build, which is the wrong binding: the site should show the code it is running, not the code someone merged an hour ago.

Consequences

  • A record can no longer show stale code without saying so; the sample is the build's own file, and the link beside it lands on the same lines at the same commit.
  • The image grew by 279,121 bytes (273 KB) of text. The photo set alone is fifty times that.
  • Adding a sample costs two comment lines in the source and one fenced block in the doc. Renaming a region without updating the doc renders the "Sample unavailable" line, visibly, which is the point.
  • The expander is a parsing surface on a public endpoint. It reads only whitelisted text files inside the image, writes nothing, and answers with a note on every failure, and the tests hold it to that.

Where it sits

Live samples are a host concern and sit in the Api: LiveSamples.cs holds the whitelist and the expander, and DocumentationEndpoints.cs passes every served document through it. LiveSamples has one reason to change (how a fenced block becomes source text), which is single responsibility; the endpoint stays a caller that knows nothing about regions. The price is source code shipped inside the runtime image and a parser on a public endpoint; LiveSamplesTests and LiveSampleCoverageTests hold both to their limits. A private codebase would change the call, since this design publishes its own source to anyone who opens a record.

Files

Addendum, 2026-09-02: the whitelist widened for the references pass

The original four roots were not enough once every record was to show the files it decided: the Dockerfile, the edge, the end-to-end specs and the root configuration files sit outside them. The whitelist now also allows tests/, edge/ and six named root files (Dockerfile, netlify.toml, playwright.config.ts, vite.config.ts, package.json, index.html), the image copies them, and the rejection tests gained cases for the neighbors that stay out (.env, the lock file, anything under docs/). The string check still runs before any filesystem touch.

Addendum, 2026-09-02: whole files, for the ones that cannot carry a marker

The two records written for a new developer (ADR: Program.cs, explained and ADR: The React configuration, explained) show package.json, index.html and the three tsconfig files. package.json is strict JSON and cannot hold a comment marker, and the others are small enough that a region would be the whole file anyway. A live block may now say region=*, which renders the whole file with a link to its first line; the star can never collide with a real region because names are letters, digits, dots and dashes. The three tsconfig files joined the named root files, .editorconfig followed when the style rules were written down (ADR: App Architecture section), the image copies them all, and the tests gained the whole-file case. Ten named root files now, beside the six roots. The test itself is not shown here on purpose: its source spells out a live fence, and a record that showed it would fail the check that no fence is left in a served document.

// region=* is the whole file, for files that cannot carry a comment marker
// (package.json, the tsconfig files); everything else is a marked region.
bool wholeFile = region == "*";
// region=header is a file's opening three-line header (Does, Does not, Used by), which comes
// before anything else in the file and so cannot sit inside a marker (ADR-019, the addendum on
// the stylesheets).
bool header = region == "header";
int headerClose = header ? Array.FindIndex(source, line => line.Trim() == "*/") : -1;
if (header && !(source.Length > 0 && source[0].Trim() == "/**" && headerClose > 0))
{
    return Note($"`{path}` does not open with a header.");
}
int start = wholeFile || header ? -1 : Array.FindIndex(source, line =>
{
    var m = RegionStart().Match(line);
    return m.Success && m.Groups["name"].Value == region;
});
// A named end marker wins, so regions may nest; a bare #endregion closes the nearest open one.
int end = wholeFile ? source.Length : header ? headerClose + 1 : -1;
if (start >= 0)
{
    end = Array.FindIndex(source, start + 1, line =>
    {
        var m = RegionEnd().Match(line);
        return m.Success && m.Groups["name"].Value == region;
    });
    if (end < 0)
    {
        end = Array.FindIndex(source, start + 1, line =>
        {
            var m = RegionEnd().Match(line);
            return m.Success && m.Groups["name"].Value.Length == 0;
        });
    }
}
if (!wholeFile && !header && (start < 0 || end < 0))
{
    return Note($"region `{region}` was not found in `{path}`.");
}

Live from api/TheYard.Api/Features/Docs/LiveSamples.cs, region whole-file, read from this build at 99df7a8.

The look, from the live site

This record open in the app, scrolled to its first sample: the whitelist read from the running build, with the Live from line naming the file, the region and the commit

Addendum, 2026-09-09: coverage, or the note nobody was reading

A live block that cannot be shown renders a one-line note instead of an error. That was the right decision for the reader, and it had a cost that took a week to surface: nothing was reading the notes. On the morning of 2026-09-09 a sweep of every served document on both live sites (eighty slugs, read as the sidebar reads them) found the measuring record showing "Sample unavailable" where its method should have been. The block named scripts/measure_stores.py, and scripts/ was not one of the roots, so the expander declined it exactly as designed, on every machine, from the day the record was written. Every gate had been green the whole time, because a sentence is not a failure.

Three things changed. scripts/ is the seventh root, and the runtime stage of the Dockerfile copies it, so the block renders on the live site as it does here. And two tests now read what the reader would have read: LiveSampleCoverageTests expands every served document against the checkout and fails on any note, and, separately, parses the runtime stage of the Dockerfile and fails on any live block whose path that stage never copies, because a glob like api/TheYard.Api/*.cs reaches the files beside it and none in a folder below, which is a second way for a sample to be present on every developer's machine and "not in this build" on the domain. That second check is the same class as the second manifest (ADR: The second manifest), and this is its third instance in this repository: an explicit list that nothing compared with the thing it described.

The tests are not shown live here, for the reason the whole-file addendum gives: their source spells out the note and the fence they look for.

Addendum, 2026-10-04: one folder from the sample beside the app

The onion practices page shows The Shed's architecture tests whole, because they are the example of the rings drawn as folders in one project. The Shed lives under samples/theshed, which none of the seven roots reached, so samples/theshed/tests/ is the eighth. It is the sample's test folder and nothing more: the rest of the sample is served by its own site, and the rejection tests gained samples/theshed/Program.cs to keep it that way. The runtime stage of the Dockerfile copies the one file the page names, and the coverage test above already fails any live block whose file the image does not carry.

One consequence is written down rather than fixed. A push that changes only the sample does not redeploy TheYard, so TheYard's sites show the sample's tests as they were at TheYard's last deploy. The line under the block names the commit it was read from, so the copy says how old it is.

Addendum, 2026-10-06 (1.0.3.85): the page that shows them

Steve asked for a page that teaches how the documents are styled, for a developer who wants to copy the idea. It is How the documents are styled, under Style (docs/style/DOCUMENT-STYLE.md), and it shows each feature by using it: its own status line drawn as a reading, its sections as panels, a link to one of its own sections, a swatches fence, a readouts fence and five live blocks, one of them the expander this record decided on. It ends with the five steps to try the pattern in another repository, the last of which is the coverage test this record's earlier addendum added.

The page opens on how many live blocks the library carries and in how many documents, and both numbers are placeholders like the Style guide's. Two measures were added for them, live-blocks and live-documents (LiveCounts.cs): each counts the lines that open a live fence in the documents the catalogue serves, the way the expander finds them. StyleSectionTests counts the same fences by hand and holds the two measures to its count.

Addendum, 2026-10-09 (1.0.3.112): the pages that describe the machine show it

Seventeen of the thirty pages outside the records carried no live block on 9 October, among them the four that describe how the site is hosted and rolled. The rule for filling one is the rule this record set: a live block goes where a sentence talks about that code, and nowhere else, so a page is never padded to clear a count. Under it, Hosting now shows the edge's rules where the chain names them and the rendering service's web app where the design section names it; the Infrastructure overview shows the plan's size as the template declares it, the one line AppServiceTemplateTests holds every page to; CI/CD shows Deploy Render's roll and its readiness check, and the edge's ignore rule beside the sentence about the edge deploying itself; and the Web overview shows the font preload plugin its type row describes, with its table of pieces brought up to the build that runs (the script is 305 KB built and the renderer chunk 144 KB; the edge keeps the catalogue's two reads). The pages that still carry no block say why in the story of this work: the changelog and the Author page are exempt, and the rest describe decisions or measurements with no code behind the sentences.

Addendum, 2026-10-09 (1.0.3.113): the pages that describe the code show it

The same rule, on the five pages that describe the code itself. Data flow shows the overlay its read path's fourth step names, the fetch seam its sixth step names, and the sold rule its write path's second step names. Projects shows the rings as OnionTests reads them from the compiled assemblies, where the Tests section names that test. Start here shows the loaders, the one file on its "where a change goes" list a new developer has not met. Security shows the signing key's rule, the lockout, and the check that a session bids only where its account is, each under the paragraph that describes it. Style's one pasted example, the comment above the store write in PlaceBidAsync, is now the method itself, read from the build, so the page shows the comment as it stands and the record's own rule about pasted code holds on the page that teaches it.

Addendum, 2026-10-09 (1.0.3.114): the records that explain a piece of code show it

Twenty-four of the ninety-six records carried no live block. Twelve of them explain one piece of code and name its file, so each now shows that piece from the build, in a region the file already carried, above its Where it sits section: the interceptor (ADR-044), the SQL log port (ADR-043), the Dockerfile's first manifest (ADR-047), the lockout (ADR-050), the registration window (ADR-054), the broken-windows markers (ADR-055), the listing's refresh timer (ADR-056), the document slug (ADR-057), the sitemap held both ways (ADR-053), the versions test (ADR-089), the exception slot (ADR-045) and the page sweep's second look (ADR-077). The other twelve stay as they are, under this record's rule: ADR-032, 046, 048, 049, 052, 058, 065, 082, 084 and 090 decided a method or a place rather than a piece of code, and the code behind them is shown on the record or page that owns it; ADR-041 and 051 would each need a hundred-line block to say what one paragraph already says.

Addendum, 2026-10-09 (1.0.3.115): the kept log's one function

What is kept, under Site traffic, says every string passes through one function on its way in, bounded in length and with every at sign turned into %40. The sentence now shows the function, LogText.Clean in api/TheYard.Application/Shared/History/Logs.cs, behind a new log-text region, the way the rule above asks: where a sentence talks about the code, and nowhere else.

Enforced by

One rule in the rulebook cites this record, each held by a test on every release.

The rule What holds it In the last gate
Code shown in a document is read from the build at request time, never pasted LiveSamplesTests, LiveSampleCoverageTests 84 of 84 passed
Store

The Yard, home

Steven StoutStaff .NET engineerRemote

Production .NET that stays up. Built with AI, measured on every version.

Steven Stout

Hi, I'm Steve. I build the systems that make delivery boring in the best way, then coach people inside them.

  • 200+

    production releases, none took the platform down

    Conway Investment Research, 2019 to 2024. Sole engineer for the first three years on a live financial advisory platform.

    See how
  • 50%

    shorter release cycle

    Storee Construction, 2024 to 2026. Four ASP.NET applications onto one .NET 10 platform on Azure, with a four-person team I hired and mentored.

    See how

01Verified

Steven Stout

A real person, and the work is mine.

  • Identity

    Checked by LinkedIn, not by me.

    LinkedIn verified my government ID.

  • Running system

    You are looking at it.

    Version 1.0.5.273 is live. Nothing ships unless it passes the automated gates first.

That's who I am. Here's how I work.

02Strengths

Ten strengths, each with the proof beside it. The numbers match my resume and LinkedIn, and the live ones are read from this site as you look.

  • 01

    Keeps production alive

    200+ releases on a live financial platform, and none took it down. Sole engineer for the first three years.

    See the Conway work

  • 02

    Simplifies messy systems

    Four ASP.NET applications onto one .NET 10 platform on Azure, and a release cycle 50% shorter.

    See the Storee work

  • 03

    Marries dev and infrastructure

    Blue-green releases at Storee that flipped in about 5 seconds with nobody signed out, and Azure Front Door at two employers.

    See this site's cloud

  • 04

    Designs data that holds up

    White-label clients on one shared database, the isolation built into the data, and no cross-client issues.

    See the Conway work

  • 05

    Keeps AI-written code honest

    15 quality numbers that may only improve: 273 releases in a row with none worse.

    See the quality numbers

  • 06

    Resourceful

    $30,000+ cut from Azure and vendor spend at Conway. This site's Azure bill is public, resource by resource.

    See the bill

  • 07

    Builds people up

    Hired and mentored a four-person team. 13 colleagues recommend me by name.

    Read the recommendations

  • 08

    Takes ideas to production

    This site: designed, built and run solo, with 352 versions measured through one gate.

    How it was built

  • 09

    Writes clearly

    Posts on real engineering problems, in plain words.

    Read the blog

  • 10

    Owns decisions

    153 decision records, each with its tradeoff and the call I made.

    See the decision records

Built with AI. Gated so quality never slides.

Steven Stout’s showcase: a used-vehicle auction on .NET and React, built and run by one engineer, live on Azure, with its decisions written down.

No quality number has gotten worse at any release since 1.0.5.1 on 10 November: 273 releases in a row.

One engineer, an AI agent and a gate that checks 15 quality numbers on every release. 352 versions measured, with every result public, the worst days included.

82 releases in the last 7 days, each through the same gate.

Async methods with no CancellationToken, may only fall

11091.0.3.1391.0.5.2731.0.4.115, the ratchet
Every number, on the Quality page

TheYard, right nowLive

Answering in

unread

02505007501,000

server time at p95, the usual five minutes of the last day.

Azure this month

unread

the bill, by resource, read from Azure. The Admin tab shows every line.

Since the last roll

unread

 

rolled in place by the pipeline, behind one gate.

People who have visited

unread

30 days agotoday

Scanners, my own tools' and my own reads left out.

03Start here

04Where teams are heading

How I see engineering with AI, and the setup on this site that backs it.

AI-augmented teams · Architecture and ownership

AI writes more of the code. Someone still has to own what ships.

Teams are going to be heavily AI-augmented. That moves the senior job toward architecture and technical ownership: deciding what to build in pieces small enough to verify, and owning what ships.

  • Task tracking will get automated too. Judgment stays human: seeing a design fail at scale before it does.
  • On this site the AI's first design held the whole catalogue in memory. I caught it when the App Service plan hit 82 per cent and moved the work to the store.

What the AI wrote, what I decided

07Tech stack

  •    
  •    
  •    

Read from the build, never typed by hand

What TheYard runs on

What we use, where it runs, its AWS twin, the version as built, and the file that proves it.

Cloud patterns, not one vendor: every Azure piece in this stack has a named AWS twin. Mapped, not yet run on AWS.

  • .NET 1114 projects
  • React 19.3TypeScript 7.0
  • Azure9 Bicep files
  • 11GitHub Actions workflows
The whole stack, with the file that proves each line

The last release the gate stopped was 1.0.5.258 on 2 December, at its browser 1 of 2 job.

08How it is built

09How it is run

10Who and why

Next step

11What has to work, where is it today, and what does success look like?

Book 20 minutes opens an email to me with those three questions in it, and I answer with a time.

Book 20 minutes

Your email app should have opened with this message. If it did not, copy it and send it from any mailbox.

Or message me on LinkedIn