Architecture for contributors
The implementation is a Python core with thin CLI and MCP adapters around one SQLite-backed resolver layer.
Component flow
Section titled “Component flow”sources -> docbook -> parsers -> ir -> db importers and migrations -> query repositories and resolvers -> CLI / Python / MCPThe evaluation package exercises tool routing across the public resolver surface.
Source acquisition
Section titled “Source acquisition”dicom_kb.sources owns:
- official current and archive URL discovery;
- concrete-edition validation;
- local artifact registration;
- cache destinations;
- SHA-256 calculation;
- source-manifest persistence;
- cache and database verification.
Do not add a download path that stores a mutable current label as the
edition.
Generic DocBook parsing
Section titled “Generic DocBook parsing”dicom_kb.docbook preserves reusable structural information before semantic
interpretation.
A part-specific parser should consume this representation rather than reimplement XML traversal independently when the generic structure is sufficient.
Preserve:
- stable anchors;
- row ordering;
- cross-references;
- source locations;
- warning information;
- bounded text content.
Part-specific parsers
Section titled “Part-specific parsers”dicom_kb.parsers converts relevant structures into canonical semantic
records.
A parser should:
- recognize narrowly defined structures;
- normalize identifiers deterministically;
- retain raw or explanatory text needed for review;
- emit warnings for unsupported variants;
- avoid guessing a link from weak name similarity;
- attach a source reference to every normative record.
Intermediate representation
Section titled “Intermediate representation”dicom_kb.ir decouples parsing from persistence. Models should be typed,
edition aware through import context, and explicit about optional or unresolved
fields.
Identifier validation belongs close to shared IR/query boundaries so CLI, Python, and MCP receive consistent behavior.
Database layer
Section titled “Database layer”dicom_kb.db owns:
- schema migrations;
- transactional imports;
- build metadata;
- repository queries;
- relationship records.
Add a migration rather than mutating an old schema in place. Keep edition and source-reference keys on semantic tables.
The reviewed source uses SQLite only. Do not introduce PostgreSQL behavior into documentation or public APIs until implemented and tested.
Resolver layer
Section titled “Resolver layer”dicom_kb.query.resolver is the public behavioral core. Resolvers should:
- validate and normalize inputs;
- query repositories;
- traverse graph relationships deterministically;
- preserve candidates or ambiguity;
- construct official references;
- assign the shared response classification and confidence;
- return a
ToolResponsefor normal outcomes.
Do not place independent business logic in CLI or MCP adapters.
Public adapters
Section titled “Public adapters”Typer commands resolve configuration and paths, open SQLite read-only, call one resolver, and serialize JSON.
Python
Section titled “Python”Callers import resolver functions directly and manage the connection.
The adapter registers typed functions, maps MCP arguments to one resolver call, and serializes the same public response. Keep the edition and database fixed at server startup.
Adding a new structured query
Section titled “Adding a new structured query”A typical sequence is:
- identify the official DocBook structure and source-reference strategy;
- add or extend canonical IR models;
- add a schema migration and repository record;
- implement transactional import;
- add synthetic parser fixtures;
- add parser and importer tests;
- add the resolver and result contract;
- define evidence classification and confidence behavior;
- add CLI exposure;
- add MCP metadata, registration, and dispatch if agent-facing;
- add Python, CLI, MCP, and JSON-schema tests;
- add agent-regression cases when routing changes;
- update coverage, reference, legal, and release documentation;
- run offline and applicable official-edition gates.
Invariants to protect
Section titled “Invariants to protect”- no official bulk content enters the package or repository;
- every normative fact can identify its official source;
- query connections are read-only;
- build and import paths remain deterministic;
- warnings remain observable;
- public adapters remain behaviorally aligned;
- text retrieval remains bounded;
- a new tool cannot silently downgrade ambiguity into a guessed answer.