8 Cross-cutting Concepts¶
Each concept has a page of its own in concepts/ (docs/architecture/concepts/); this chapter numbers them and says
in a few sentences what each one covers. The rules, tables and identifiers are on the pages.
8.1 AI use — the dividing line¶
AI at run time only where a core function needs it — extraction (KF-1), matching and classification (KF-3), the MCP tool (KF-5) — each behind a port, under the guardrails and measured by the evaluation; AI classifies and never decides, integrity is checked before any model sees a document, and the assistance only reads. AI in development follows its own rules. Only the run-time use is a product function.
8.2 Guardrails (binding)¶
The guardrails G-1 to G-7 bound every LLM call: the contract is untrusted input, PII is minimised, the MCP tool serves released findings only, nothing is released without a person, every call is recorded, no contract content reaches a log, and every model response is validated. Each names where it is enforced and the log event that shows a violation; OWASP LLM06:2025 is their reference.
8.3 Persistence¶
One relational database, PostgreSQL with pgvector, holds the case, the case engine's tables and
the outbox of the event backbone, so that they commit in one transaction; on Google Cloud a
shared-core Cloud SQL instance (ADR-0013 (docs/adr/adr-0013-postgresql-on-cloud-sql.md)), reached
through Spring Data JDBC (ADR-0019 (docs/adr/adr-0019-spring-data-jdbc-for-the-relational-store.md)), its schema changed only by new Flyway migrations. A transaction
writes one aggregate, and the others catch up through domain events; the case's change history,
written with the case, is the one exception. The uploaded PDF stays in a
private object store for as long as its case exists, so a person can read it from the case. PostgreSQL is authoritative for everything that belongs to a case;
a document database keeps derived copies only, each rebuildable at any time
(ADR-0018 (docs/adr/adr-0018-postgresql-authoritative-document-database-derived.md)). No event sourcing.
Consistency is strong inside that database — ACID, one instance without a replica, so no stale read
and no failover — and eventual between the stores, with no distributed transaction.
8.4 Testing and quality gates¶
./gradlew build is the offline gate before every commit and on every pull request: formatting,
Error Prone, the architecture tests, the tests, JaCoCo line coverage per class, PIT mutation
testing (in the local gate only; CI skips it, and it runs in full nightly) and the web app's checks, each with its threshold. The integration tests against real models and Docker stay outside
it on purpose.
8.5 Evaluation¶
The target is a small, versioned set of anonymised contracts with target values, measured for quality, latency and cost. Until it exists, the four cases of the extraction tests on three of the fixture documents stand in for it.
8.6 Rules for AI-assisted generation¶
Seven numbered rules state what generated code must not do — among them confirming a value without verified evidence, logging contract content, giving an agent direct database access, and reaching a provider SDK from the domain. Code that violates one is corrected or rejected, and the decision is recorded; the ADRs measure themselves against these rules by number.
→ Rules for AI-assisted generation
8.7 Extraction rules¶
A summary of the binding extraction rules of CLAUDE.md: a fixed schema of candidates with their
passages, an empty field as a valid result, validation of every answer, confidence derived from the
citation check rather than reported, and several values for one field reported as ambiguous. It
also says where the per-field confidence comes from.
8.8 Security — the gateway as the only public entry¶
FeeCheck's security layer by layer, with each layer's status: the Cloudflare edge login, IAM-only Cloud Run services, the sign-in with Google and an allowlist, the token check on the queue's push, the secrets in Secret Manager — and the API gateway of ADR-0010 as the only public entry, which takes the sign-in over and makes the backend a resource server.
→ Security — the gateway as the only public entry
8.9 API contract¶
ADR-0010 decides a code-first OpenAPI contract: derived from the controllers, committed as a snapshot the build checks, validated by the MockMvc tests and the one source the web app's client is generated from.
8.10 Extension axes — verification packs, core and adapters¶
ADR-0001's two independent extension axes: verification modules decide what is checked, adapters where the data comes from, and a verification core between them knows documents, attributes and findings but no fees. The page carries the layer view, the narrow code SPI and the litmus test for where the boundary is drawn.
8.11 Domain model¶
The case and what happens to it in the terms of domain-driven design: the subdomains, the bounded contexts and their context map, the aggregates and value objects each context keeps, and the domain events within and between them. The same things as entities with keys are the entity model (8.19).
8.12 User interface¶
What applies to every screen of the web app is in docs/frontend/ — design and conventions; a
screen's own spec is in docs/specs/.
8.13 Configuration and adapter selection¶
Every port that reaches outside the process has a stub and at least one real adapter, and which one runs is configuration, never a branch in domain code; the stub is the default, so the offline build needs no network, key or Docker. The same pattern is the template for every service on Google Cloud and is how ARC-Q4's switchability is met.
→ Configuration and adapter selection
8.14 Error handling and operations¶
How FeeCheck fails and how it is operated: every failure from the upload to the event backbone with its response and where it is recorded, and the operations mechanisms — health probes, logs without contract content, model-call telemetry, the event backbone's alerts; the metrics and trace sink is open.
→ Error handling and operations
8.15 Onion architecture — rings per component¶
Each component is a package below the application's root package with its own domain, application and infrastructure rings, declared on each ring's package and enforced by the build — the rings by ArchUnit with jMolecules, the module boundaries by Spring Modulith's module verification and the published types. The page covers the rings, the dependency direction, ports and adapters in the rings and how they map to Spring and jMolecules, the build's checks, the shared kernel and the modules that are adapters only.
→ Onion architecture — rings per component
8.16 Modules with Spring Modulith¶
Each package below the application's root package is a Spring Modulith module. Modules meet through a published application service, called synchronously, through published domain types, or — planned — through Spring Modulith events, the one event backbone: a stage's work as a request and its reply, facts into and out of the case engine, facts between modules; kept in an outbox and carried to other deployables by Spring Cloud Stream — Pub/Sub in production, the emulator in end-to-end tests, in memory in development. The page maps each kind to jMolecules and Spring Modulith, lists which ring of which module is published as a named interface, and states the event rules.
→ Modules with Spring Modulith
8.17 Spring AI patterns — the extraction and the MCP server¶
How the extraction and the MCP server use Spring AI — structured output, advisors, the tool loop, prompt handling, MCP tools — and the reason wherever FeeCheck departs from the common pattern; the comparison with Spring AI's examples is a guide of its own.
→ Spring AI patterns — the extraction and the MCP server
8.18 Case management with CMMN¶
The FeeCheck case is modelled in CMMN and runs on Flowable's open-source CMMN engine inside the
cases module. The page lists the stereotypes chapter 6's diagrams use for CMMN's elements, how
plan items relate to the case's business state, and why CMMN rather than a BPMN process, a state
machine or logic written by hand — and what it costs.
8.19 Entity model¶
The case and what happens to it — intake, conversion and extraction, review, decision, audit and
assistance — as entities with their keys and relations, the records that hold any business model's
extracted values and their checks, and the tables the case is stored in. A business model's
concrete attributes are its business data model in docs/model/feecheck/data-model.md, which is not
published.
8.20 Business-model catalogue — LinkML and SSSOM¶
A business model is edited as a LinkML schema in the repository, with an SSSOM table for the mappings that need a reason. The page lists the catalogue's files and what each element carries, the two layers it keeps apart, how a catalogue is linted and validated, and what a catalogue could do for the extraction.
8.21 Value kinds and contract standards¶
The value kinds a contract's data falls into, each with its normalised form and the standard for it, and the published standards surveyed for naming a contract's parts and typing its values — clause taxonomies, document structure, norms, contract data models and the financial standards.