08Boundaries drawn by risk
Domain-Driven Design tells you where to draw the lines in a system. With an AI writing the code, those lines matter more: they limit the blast radius of every change, and of every mistake.
Every article on this site comes back to Domain-Driven Design: bounded contexts, each with its own model and its own language, and a ubiquitous language that makes the business and the code say the same thing. For critical products, bounded contexts are also risk boundaries. With an AI writing the code, they do one more thing: within a clear boundary, an agent can be given everything it needs to get a story right. Domain-Driven Design is the practice that draws those boundaries, and this project put it to the test with an AI writing the code.
Why do boundaries matter more with an AI?
An AI developer works from the context it is given: the story, the requirements, the decisions, the code it can see. Within a clear boundary, that context is small and complete. Across a blurred one, it is large, and something is always missing. Boundaries make a story small enough for an agent to get right, and a mistake small enough to contain.
They also decide what a change costs. In a regulated product, anything inside the medical device falls under the strictest software process, with its verification and its change control, and anything outside it does not. Where the device boundary runs decides what every future change will cost, whoever writes the code, and the last word on it belongs to the notified body.
Five modules, three questions
The product is made of five modules: the clinical application itself; an interoperability module that exchanges data with the hospital's other systems; an access-control module to which all authentication and authorisation are delegated; the configuration tool; and an operational module that supports the clinical work. It is tempting to rank them by importance. That turned out to mix three different questions, and keeping them apart was one of the most useful things the design work produced.
| Module | Does it differentiate the product? | How critical is it to the hospital? | Is it part of the medical device? |
|---|---|---|---|
| Configuration tool | Yes: the core domain. Every other module behaves as its configuration says. | Load-bearing | Designed to sit outside; treated as part of it until the notified body decides |
| Clinical application | Core | Critical | Yes |
| Interoperability | No: it translates other systems' models so they never leak into ours | Critical | Yes |
| Operational support | Possibly; it could be a product in its own right | Critical: the clinical work depends on it | No: it has no medical purpose of its own |
| Access control | No: a standard problem, delegated to a standard protocol | Critical | Designed to sit outside; same caveat |
Figure 9. Three questions for every module. Critical is not the same as core, and critical is not the same as regulated.
In Domain-Driven Design terms, the configuration tool is the core domain, the part that makes the product worth having. It is also, to borrow a builder's term, a load-bearing wall. I designed it to sit outside the device, with the device protecting itself whatever configuration it receives, as chapter 09 explains, and I designed access control to sit outside too, a decision that came from one of the design sessions of chapter 05. That is a design intent, and the classification is not mine to make. A tool that decides how a medical device behaves may well be regulated as part of it, and the notified body will rule. Until it does, both are developed under the same process as the device, which every story followed anyway. The domain boundaries stay where they are; only the regulatory boundary is drawn wider, on the safe side.
One database, deliberately
The prologue's experiment settled the database question. Each module has its own database, but the clinical application keeps all its domains in one: patients, care planning and execution, and those to come. A Domain-Driven Design purist may see a breach of the rules, but a database per bounded context is a microservices convention, which Domain-Driven Design does not require. Inside the device, a patient's record and the care given to that patient must never disagree, and a single database enforces that in every transaction. Between modules, where data crosses the device boundary, the device checks what it receives. For configuration, the contract is the Baseline, which the application reads when it starts and refuses to run without. Deploy still writes the Baseline straight into the application's database; making that a versioned contract, as the architecture's own rule asks, is still to be done. The database boundary follows the risk boundary.
Inside the application, each domain owns its tables, and any other domain reaches them only through an interface that hides how they are stored: a modular monolith, whose boundaries are enforced by the code itself.
What one database buys, and what it costs
- What it buys: integrity enforced by the database across domains; one hash-chained history of every change, with no seams between databases; one consistent point to restore from; one database for the hospital's IT to run.
- What it costs: the domains cannot be deployed independently; any change to the data model needs the application stopped, during a planned window; and future teams working on different domains will share one schema. The database is a single shared dependency, made highly available by running it as a cluster.
Where did the AI need the boundaries written down?
Boundaries that live only in the architect's head do not bind an AI; chapter 07 shows what happened to a rule I had stated but not enforced. The rule that each domain owns its tables is, at the time of writing, a principle I hold, still to be written down as a decision and backed by a check. Only one domain has been built so far, so nothing has crossed it. As soon as a second one exists, an AI will write the shortest query, whatever the ownership rule says, unless the rule is written where it reads and checked where it cannot skip. I have decided to write it as a decision record and back it with a build check before the second domain is built. Where the lines run, and making sure the AI cannot cross them unnoticed, stays with the team.
The ubiquitous language works better. As Drawing the Lines argues, it is what keeps requirements, tests and code saying the same thing. A glossary of about fifty-five terms was written at the very start, each marked as confirmed, proposed or needing confirmation, and Claude flagged the ambiguous terms for me to settle. The language travels from there into the requirements, the architecture, the stories and the code, and when a term was renamed, the glossary kept the old name alongside the new one. Tactical Domain-Driven Design is still ahead: the walking skeleton is organised by technical layer, because its one domain did not need more.
For your own project
- Draw boundaries before you let an AI write across them, and ask three separate questions of every component: does it differentiate, how critical is it, and is it regulated or audited?
- Put the database boundary where the risk boundary is, and write ownership rules where the AI reads them, backed by a check that runs on every build.
- Keep a glossary from the first day, and let the AI flag the terms it finds ambiguous.