vysotskyi.dev

Constantine Vysotskyi

I design and build medical imaging software.

From system design to the interface, with AI in the loop.

Chicago ·
Book a 30-min call
Case report · (0009,1004) ·

Use-case-driven development for AI coding agents

Environment (0008,1010)
DICOM and HL7 gateway: Go backend, web UI, protocol tests
Area (0008,1030)
Engineering process
Period (0008,0020)
Autumn 2026 · in daily use
My role (0008,1070)
Method, templates and CI check; used with the team
Stack (0018,1030)
Claude Code · Markdown use cases · Go · CI
Status (0040,0252)
COMPLETED

Background

A use case describes one goal of one actor and everything that can happen on the way to it. The classic form, from Alistair Cockburn's Writing Effective Use Cases, has a main success scenario, the one path where everything works, and extensions: each place where something can go differently, what the condition is and how it ends.

In medical imaging the actor is often not a person. A modality opens a DICOM association, a RIS sends an HL7 order, a PACS answers a C-FIND, a timer fires a retry. Each of them can send bad input, answer late or not answer at all, and each of those cases needs a defined behavior: what the sender gets back, what changes in the system, and what support can find in the logs later.

Spec-driven development with AI coding agents means the agent works from a written specification instead of from a chat message. An agent reads files well and fills gaps by guessing. A specification that names every scenario removes the gaps; a specification that is linked to tests and checked in CI cannot quietly drift away from the code. Traceability is that link: from a requirement to the scenario that covers it, and from the scenario to the tests that prove it.

Indication

The product is a DICOM and HL7 gateway: listeners and access rules, routing, query/retrieve, Modality Worklist, tasks from a cloud platform, and a web UI for operators. Most of the work on it is done with AI agents.

Documents described what the system was, not how a feature behaves for the people and systems that use it, or how that behavior changed over time. That knowledge lived in tickets and in people's heads.

Every test run could find bugs, and each bug went one of three ways. It became a ticket. It slipped through. Or it was quietly fixed, without anyone writing down what the right behavior was. Creating a ticket every time is overhead nobody keeps up with, and a silent fix teaches the next person, or the next agent, nothing.

Technique

Step 1: one use case per goal. Each use case is one goal of one actor: an operator, an external system such as a modality, PACS or HL7 sender, the platform, a timer, or another use case. It lives in the code repository next to the code, grouped by bounded context: HL7 and worklist, DICOM sources, routing, query/retrieve and so on, each with its own glossary. It says what happens, never how: no tables, types or endpoints. Every edge case is its own file with its own ID, so a test can carry that ID. IDs are never renumbered or reused.

# <Verb + object>

ID: UC-<context>-<nn>
Status: draft | ready | in-development | implemented | deprecated
Level: user goal | subfunction | summary
Actor: operator | external system | platform | timer | system
Trigger: <what the actor does>
Outcome:
- Actor receives: <the response>
- System state: <what is different afterwards>
- Events: <domain events emitted, or "none">
Minimal guarantees:
- <what stays true whenever the goal is not reached>

## Stakeholders and interests
- <stakeholder> - <what they need from this use case>

## Requirements
- R1 <one testable statement>
- R2 [performance] <a bound the code enforces>
- R3 [errors] <what the actor gets, what support finds>
- R4 [recovery] <after a crash, restart or repeated request>
- R5 [security] <who may do it, which patient data is seen>
- R6 [compatibility] <peers outside our control>

## Main flow
Covers: R1, R2
Given: <state before the trigger>
When: <the trigger>
Steps:
1. <the actor does ...>
2. <the system answers ...>
Then: <the outcome>

## Edge cases
| At | Edge case | Condition | Ends | Covers |
|----|-----------|-----------|------|--------|
| 2  | EC-01 ... | <a fact>  | failure | R3  |

## Open questions
- <question> - <who can answer>

Step 2: brainstorm to ready. A use case starts as draft. To become ready it goes through a brainstorm with the team and AI to find every problem: for each step, what if the input is bad, a peer does not answer, data is stale, the system restarts, the same request comes twice. Quality attributes are decided explicitly: performance, error handling, recovery, security, and compatibility when a step talks to an outside system. Each one is either a tagged requirement or a line saying why it does not apply. A bound nobody has decided stays an open question, never a guessed number. No design and no code against a draft, and an agent that meets an open question stops and asks.

Every edge case states where it branches off, how it ends, and what is recorded for support. "Nothing" is a valid answer, and writing it down shows the gap.

# Unknown calling AE title

ID: UC-access-01/EC-02
At: step 2
Ends: failure
Covers: R3
Given: no access rule lists the calling AE title
When: an external system opens an association with it
Then:
- Actor receives: an association rejection
- System state: unchanged
- Events: AssociationRejected
- Recorded: a rejected-association log line naming the calling AE title

Step 3: the test carries the scenario ID. The specification never names a test file. The test names the scenario, in its name or a one-line comment, and a search for the ID lists the spec, the entry point in the code and every test of that scenario. A scenario counts as validated when at least one passing test carries its ID.

// UC-access-01/EC-02
func TestAccessPolicy_UnknownAETitle(t *testing.T) {

Step 4: the status is a claim CI checks. A small check written in Go runs in CI on every change and fails the pipeline when the files don't back up the status: an ID that doesn't match its folder, an open question in a ready use case, a requirement no scenario covers, an undecided quality attribute, an implemented scenario without a test, or a test carrying the ID of a scenario that doesn't exist. The same check lists every scenario with the tests that carry its ID.

Step 5: a bug is a missing or wrong scenario. When a test run finds a bug, the first question is which scenario it contradicts. If the scenario is right and the code breaks it, the reproducing test carries that ID. If no scenario describes the case, a new edge case is added. If the scenario itself is wrong, it is corrected. The spec, the test and the fix go in one merge request. A ticket is created only when the bug belongs to another scope.

Step 6: review the behavior, not only the code. Claude Code review on the remote repository reviews each change. Because the behavior is written down next to the code, the review can check what the application does, not only how the code looks.

flowchart TB
  need["Need or ticket"] --> exists{"Use case<br/>exists?"}
  exists -->|no| draft["Write use case<br/>status: draft"]
  exists -->|yes| change["Change the use case first"]
  draft --> storm["Team + AI brainstorm<br/>every edge case, every quality attribute"]
  change --> storm
  storm --> open{"Open<br/>questions?"}
  open -->|yes| ask["Agent stops and asks"] --> storm
  open -->|no| ready["Status: ready<br/>branch, in-development"]
  ready --> tests["Agent writes a test per scenario<br/>carrying its ID"] --> code["Agent writes the code"]
  code --> run{"Test run"}
  run -->|bug in scope| ec["New or corrected edge case<br/>+ reproducing test"] --> code
  run -->|bug in another scope| ticket["Ticket"]
  run -->|pass| mr["Merge request<br/>use case + tests + code"]
  mr --> check["CI use-case check"] --> review["Claude Code review<br/>behavior and code"] --> done["Status: implemented"]
  classDef people stroke:#eef0f2,color:#eef0f2
  classDef agent stroke:#38bdf8,color:#eef0f2
  classDef auto stroke:#646b73
  class need,storm,ready people
  class draft,change,ask,tests,code,ec agent
  class check,review,done,mr auto
Workflow for people and agents. White: the team decides. Blue: the agent works. Grey: checks run on their own. A bug in scope becomes an edge case, not a ticket.

Findings

  1. Coverage of business logic, not only code. Every requirement is covered by a scenario, and every scenario by a test that carries its ID. The check lists which scenarios are tested and which are not.
  2. Behavior you can read. What the gateway does when a peer refuses, times out or sends garbage is written down, with what the sender gets and what support finds in the logs.
  3. Bugs become scenarios. A bug found in a test run is fixed together with the edge case it was missing. Tickets are left for bugs that belong to another scope.
  4. Agents catch errors on their own. An agent stops at an open question instead of guessing, and the CI check fails a change whose files don't match its status.
  5. Automatic behavior review. Claude Code review on the remote repository reviews each change with the use cases next to the code.
  6. Fewer bugs, clean release notes. Behavior changes start in the use case, so what changed for users is clear.

Impression

TagData
(0040,A30A)Where behavior is describedTickets and memory → use cases in the repository
(0040,A30A)Bug found in a test runTicket, missed or silent fix → edge case + test with its ID
(0040,A30A)TicketsOnly for bugs in another scope
(0040,A30A)What coverage measuresCode → business logic scenarios
(0040,A30A)Status checked byPeople → CI check
(0040,A30A)ReviewCode → behavior and code
(0040,A30A)PeriodAutumn 2026

Lessons

  1. Write the use case before the code, especially for agents. An agent fills every gap by guessing. A named scenario leaves nothing to guess.
  2. Treat a bug as a missing scenario. Adding the edge case keeps the fix, the test and the reason in one place. A ticket alone keeps none of them next to the code.
  3. Link tests by ID, not by file path. The spec never names a test file, so refactoring tests doesn't break the link.
  4. Make the status a claim a machine checks. "Implemented" means every scenario has a passing test, and CI says so, not a person.
  5. Ask what gets recorded. Writing down what support finds for each failure exposes missing logs before production does.