Hardware & Deployment Topology
Seven purpose-built Proxmox VMs on a home lab network — nothing runs on the laptop that writes the code.
Every VM has a static address pinned in two independent places, so a reboot can't silently hand a service a new address. Public traffic reaches this same core box through DNS and a firewall NAT rule, terminating TLS at Traefik rather than at the edge.
Domain Layer Stack
Six layers of increasing business meaning, each one built strictly on the layer below it.
The Hexagonal Service Pattern
One internal shape, repeated in all 29 services and enforced by ArchUnit at build time, not by convention.
Microservices & Event Backbone
Twenty-nine services in three planes. Facts that other services react to later travel as Kafka events; when a caller needs an answer before it can respond, it uses a synchronous REST call (Exhibit I).
Request Lifecycle — a Screening Call
One analyst action, traced through the synchronous request and the asynchronous fan-out it triggers.
Agent Tool Calling & Human-in-the-Loop Safety
Agents call platform tools over MCP, answer only from retrieved, cited sources, and can propose a case assignment — but cannot make one. A different human always has to say yes, and every guarantee is enforced in code, not in the prompt.
F.2 — Every agent run, stage by stage
Two agents ship today, built from the same shared enforcement layer (agent-security, ADR-0037). Each stage defends the next, and every guarantee lives in code that runs after the model answers — none of them depends on the model following its prompt.
| Stage | Copilot (grounded Q&A) | Export drafter (tool-calling) | Enforced by |
|---|---|---|---|
| 1 · authorize | Deny-by-default: the caller's profile must be explicitly allowed to use the tool, or the run stops with a 403 — never silently degraded. | authz · Pillar 1 | |
| 2 · fetch / retrieve | Hybrid vector + keyword search over OpenSearch, tenant derived from the caller's bearer | Calls the regulator-export tool with the analyst's own token | MCP · token propagation |
| 3 · ground | Retrieved text is fenced as data, not instructions (<<<LABEL:nonce>>> markers) and screened for prompt-injection patterns before it reaches the model; a chunk that matches is quarantined (kept out of the prompt, so it can't be cited) and logged in the trace. | datamarking · injection | |
| 4 · generate | Model-agnostic LlmPort → LiteLLM → on-prem Ollama (qwen2.5:7b). Swapping to Bedrock or a hosted model is one adapter. | agent-llm | |
| 5 · validate | Cite-or-abstain (F.4) — fabricated or missing citations become an abstention | Reject any number not present in the source package | output validators · Pillar 2 |
| 6 · fall back | Abstain: "the knowledge base doesn't contain this" — a retrieval or model failure surfaces as an error, never as a fake abstention | Deterministic template on a rejected draft, model error or timeout — the export is never degraded by AI | agent core |
| 7 · gate | Both agents are advisory (read-only tier). The only state-changing tool goes through the propose → approve queue in F.1. | hitl · Pillar 3 | |
| 8 · trace | One record per run to three failure-isolated sinks: the body to object storage, an index row to Postgres, an event to Kafka that audit-service consumes. MCP calls are traced too, digested rather than dumped. | trace · Pillar 4 | |
| 9 · observe | The same trace record also updates Prometheus metrics in-process: runs by outcome (answered / abstained / fallback), LLM latency and tokens, injection quarantines, MCP calls and errors, plus HTTP metrics on all five agent services. A Grafana “Agent Tier” dashboard and five alerts (abstain rate, fallback rate, MCP errors, LLM p95, 5xx) watch them, and a nightly canary asks the copilot six known-answer questions. The trace proves what an agent did; the metrics show whether it is healthy, fast and affordable. | metrics · ops | |
F.3 — Tool calling over MCP
Agents reach platform capabilities as tools on three first-party MCP servers (Streamable HTTP, internal network only; ADR-0039). MCP sits behind each agent's typed tool port, so a direct-HTTP adapter and an MCP adapter can coexist per tool.
| Server | Tools | Side effects | Used by |
|---|---|---|---|
| mcp-regulator-export | regulator_export | none — read-only proxy to the export package | export drafter |
| mcp-knowledge-retrieval | knowledge_retrieve | none — tenant taken from the bearer server-side, not a tool parameter, so a crafted argument can't read another tenant | copilot |
| mcp-case-action | assign_case, list_pending_assignments, approve_assignment, reject_assignment | one insert — assign_case only proposes; approve runs the assignment under the approver's token, approver ≠ proposer, and stale proposals expire (default 48 h) | copilot (via the admin-console BFF) |
Two non-negotiables. (1) Token propagation — every call carries the requesting user's bearer, so a tool acts as that user and never as a privileged service account (no confused deputy). (2) A closed allow-list — the client is constructed with a fixed map of server names to URLs, and that map is the allow-list: an off-list server raises McpServerNotAllowed before any network I/O, and there is no dynamic tool discovery to poison. A red-team harness (agent-redteam) mutates tool descriptions adversarially and asserts each attack is caught by detection, containment, or the approval gate.
F.4 — Cite-or-abstain is enforced in code, not the prompt
A prompt can ask a model to cite its sources; it can't guarantee it will. So each retrieved chunk carries a source id, the model is asked to cite ids as [source-id], and a validator checks the answer against the set of ids that were actually retrieved:
cited = extract_citations(answer) # every [source-id] token
fabricated = cited - retrieved_ids # cited, but never retrieved
if fabricated: → reject ("citation_not_retrieved")
if not cited and not explicit_abstain: → reject (an unsupported claim)
any rejection → the copilot returns an abstention,
with abstained=true and its citations
This caught a real failure in testing: the 7B model invented plausible-looking source ids. The same pattern carries over the export drafter's rule — reject any number not in the package — from figures to citations.
What this check does not do: it confirms that every cited id belongs to a source that was actually retrieved. It does not check that each sentence agrees with the content of the source it cites — a model can still cite a real, retrieved source and misstate what it says. That residual risk is why the copilot's output is analyst input, not a decision: answers come with their citations so a human can check the source, and nothing the copilot says changes a screening or case outcome. Checking each claim against its source (for example an NLI or LLM-judge pass) is a possible later layer, not something built today.
Package Layout, Realized
Exhibit C drawn as a diagram. This is the same rule as an actual filesystem — every folder below is real, from screening-engine-service, the platform's reference implementation.
com/infopole/dps/screening/ ├── ScreeningEngineApplication.java # @SpringBootApplication root — never in a sub-package ├── runtime/RuntimeStackValidator.java # fails fast at boot if Postgres/Kafka/Redis aren't reachable ├── web/CorrelationIdFilter.java # stamps traceId before Spring Security runs │ ├── domain/ # PURE JAVA — zero framework imports (see Exhibit C) │ ├── model/ 9 files ScreeningRequest · ScreeningResult · ScreeningMatch · MatchFactor … │ ├── enums/ 8 files ScreeningOutcome · ScreeningRequestStatus · ScreeningMatchType … │ ├── policy/ 2 files ScreeningAuthorizationPolicy · ScreeningTenantAccessDomainPolicy │ └── service/ 4 files MatchingEngine · ExactFieldMatchingEngine · MatchScoringService │ ├── application/ # orchestration only — no HTTP, no JDBC, no Kafka client │ ├── port/in/ 11 files SubmitScreeningUseCase · GetScreeningDetailsUseCase · PurgeScreeningsUseCase … │ ├── port/out/ 10 files ScreeningPersistencePort · WatchlistLookupPort · InferenceDecisionPort … │ ├── command/ 2 files SubmitScreeningCommand · DismissScreeningResultCommand │ ├── query/ 2 files RecentScreeningsQuery · ListScreeningResultsQuery │ ├── result/ 8 files SubmitScreeningResult · GetScreeningDetailsResult · PagedResult … │ ├── exception/ 5 files QuotaExceededException · ScreeningResultNotFoundException … │ ├── config/ 2 files MlRolloutMode · MlRolloutProperties │ └── service/ 19 files implements every port.in above — @Transactional lives only here │ ├── infrastructure/ # everything domain/ refuses to know about │ ├── persistence/ 15 files entity/ (3 @Entity) · repository/ (3 Spring Data) · ScreeningPersistenceAdapter │ ├── messaging/ 8 files ScreeningEventConsumer · ScreeningResultEventPublisher · payload/ (5 DTOs) │ ├── integration/ 7 files one sub-package per outbound call — watchlist/ · license/ · identitymanagement/ │ ├── security/ 3 files ScreeningAuthorizationService · SecurityConfig │ ├── scheduler/ 1 file ScreeningStuckSweepScheduler │ └── config/ 1 file ScreeningDomainBeansConfig │ └── api/ # HTTP inbound adapter only ├── dto/ 14 files SubmitScreeningRequest · ScreeningResultResponse · PagedResponse … ├── mapper/ 1 file ScreeningApiMapper (MapStruct) ├── ScreeningSubmissionController.java ├── ScreeningQueryController.java ├── ScreeningResultCommandController.java ├── InternalScreeningController.java # /internal/** — role-gated to internal-service callers only └── ScreeningApiExceptionHandler.java 140 files total in src/main — the layer a class lives in is a build-enforced fact, not a naming convention.
com/infopole/dps/screening/ (test) ├── arch/ 1 file ArchitectureTest # runs DpsArchitectureRules; fails the build on a layer violation ├── contract/ 3 files event schema round-trip # inbound watchlist candidates + outbound results ├── integration/ 2 files Testcontainers # real Postgres, real embedded Kafka ├── messaging/ 3 files consumer / publisher # behavior against an embedded broker ├── smoke/ 4 files ApplicationContextSmokeTest · SecurityBoundarySmokeTest … └── unit/ 21 files mirrors src/main package-for-package # domain logic tested with zero Spring context
Performance & Concurrency, Measured
Three questions — pool depth, cache placement, thread behavior — answered by instrumenting the lab rather than guessing, plus an honest ledger of what's still on the default.
- Kafka listener concurrency default
- No service sets concurrency= — every @KafkaListener processes its topic's partitions on a single thread, everywhere on the platform.
- @Async executor default
- reporting-service and batch-screening-service use @Async with no custom TaskExecutor bean, so both fall back to Spring's SimpleAsyncTaskExecutor — unbounded, unpooled, one raw thread per call.
- Java 21 virtual threads not adopted
- spring.threads.virtual.enabled is unset platform-wide, despite every service running on Java 21.
- Cross-worker outbox concurrency deliberate
- PostgresSkipLockedOutboxClaim — a FOR UPDATE SKIP LOCKED query — lets multiple outbox-relay ticks claim rows without blocking each other. The one place concurrency safety was engineered on purpose, and it's done at the Postgres layer, not the JVM.
Service Dependency Graph
Exhibit D drew the Kafka backbone. This is the other half — the 41 direct, synchronous REST calls between services that never touch a topic.
Watchlist Data Lineage
One sanctions-list entry, followed from a foreign government's server to a line in a regulator's PDF, weeks apart — the platform's actual time-travel-audit story.
Technology Choices & Trade-offs
What was picked, what was turned down, and why — pulled from the platform's own ADRs rather than reconstructed after the fact.
| Decision | Chosen | Rejected alternative | Why | Source |
|---|---|---|---|---|
| AI agent tier language | Python + FastAPI, standalone services | Spring AI / in-JVM Java agents | "Convention over merit" — Python is the AI-mainstream ecosystem and yields a cleaner polyglot boundary than bolting agents onto the Spring monorepo. | ADR-0035 |
| Agent orchestration | Hand-rolled loop + LiteLLM under a model-agnostic LlmPort | LangChain | A heavyweight framework "reintroduces the framework lock-in this decision exists to avoid, and obscures the learning goal." | ADR-0035 §2 |
| LLM hosting | Ollama, local on ml (open-weight, 7–8B) | Hosted-LLM-first (Claude / OpenAI) | Rejected on cost and data residency for a compliance product handling counterparty PII; kept as a drop-in LlmPort adapter for a later premium tier. | ADR-0035 §6 |
| Multi-tenancy model | Keycloak Organizations, single realm | Realm-per-tenant | "The operational cost of one Keycloak realm per individual-tier customer is absurd — N realms for hundreds of single-user accounts." Hard cryptographic isolation isn't what mid-market exporters ask for. | ADR-0019 |
| Service-internal structure | Hexagonal/DDD, ArchUnit-enforced (Exhibit C) | Convention-only layering, trusted to code review | Six ArchUnit rules run in CI on every service so the boundary can't erode one unreviewed PR at a time. | CLAUDE.md |
| Event streaming | Redpanda | Upstream Apache Kafka | Kafka-wire-compatible — every client library, config, and topic convention carries over unchanged — with a lighter footprint appropriate to a single-VM lab deployment. A pragmatic pick, not a numbered ADR. | CLAUDE.md |
| Fuzzy name matching | OpenSearch + Beider-Morse phonetic analyzer | Exact / token-overlap matching only | Catches transliteration variants exact matching misses — "Wladimir" ↔ "Vladimir" — by encoding phonetic variants across all-languages, generic name-type rules. | CLAUDE.md |
| Data ownership | One Postgres schema per service, zero cross-service reads | Shared database / shared schema | A schema change in one service can never silently break another — the API or an event is the only contract between them. | CLAUDE.md |
Three of eight rows cite CLAUDE.md rather than a numbered ADR — that's an honest distinction, not a gap filled in after the fact. Formally-ADR'd decisions went through an explicit alternatives-considered process; the CLAUDE.md rows are equally deliberate but were codified directly as platform rules rather than routed through the ADR process.
REST vs. Events — Where the Line Falls
Not an even split, and not accidental — one rule decides which side of the line any given interaction lands on, and it's enforced the same way the hexagonal boundary is.
L.3 — Every service, by how it talks
The same rule applied service by service. Nearly every service exposes a REST API to its clients, so the useful question is the dominant style: does it orchestrate synchronously, react to events, or take a command and fan the fact out? REST counts are service-to-service edges from Exhibit I (calls out · called by); Kafka shows topic domains consumed → published (Exhibit D).
| Service | REST out · in | Kafka in → out | Why it sits here |
|---|---|---|---|
| Synchronous orchestrators — REST in, REST out, no domain events (4) | |||
| admin-console | 8 · 0 | — | The operator BFF: assembles one response from many services and the agent tier. No database of its own. |
| support-agent | 8 · 0 | → agent | Java-native RAG agent: gathers context over REST; publishes only its own trace event. |
| ad-hoc-screening | 3 · 1 | — | A person is waiting at the screen: submit, poll to FINALIZED, evaluate policy, return one answer. |
| training-executor | 0 · 2 | — | Job runner: accepts a training job over REST and reports completion back over HTTP. |
| Pure event consumer — no business API (1) | |||
| notification | 0 · 0 | case, screening, policy → | Reacts to what happened and sends email / Slack / Teams. Nothing waits on it. |
| Event-built read models — Kafka in, read-only REST out (6) | |||
| audit | 0 · 3 | all 10 domain topics → | Append-only trail of every event, including agent runs. Never calls anyone. |
| analytics | 0 · 2 | case, screening, matching, identity → | Pre-aggregated KPI tables, read by the BFF and Grafana. |
| watchlist-content | 1 · 3 | watchlist → | Projects ingested entries into Postgres + the OpenSearch phonetic index; serves candidate lookups. |
| scoring-engine | 0 · 0 | screening → scoring | Turns finalized matches into risk scores. |
| billing | 0 · 1 | screening, case, batch, identity → billing | Usage counters built from the events that are billed. |
| entity-resolution | 0 · 0 | watchlist, pep → ai | Links records across sources that are the same entity. |
| Hybrid — a REST command, then the fact fans out as an event (17) | |||
| screening-engine | 7 · 6 | identity → screening, case-commands | Accepts the request and returns at once; the result arrives later as screening.result.finalized. Gates synchronously on policy, quota and candidates; calls matching-engine for shadow ML evaluation and, when enabled, inference for live ML scoring. |
| case-management | 1 · 4 | screening, scoring, case-commands, identity → case | Opens cases from events; decisions arrive over REST and leave through the transactional outbox. |
| batch-screening | 2 · 1 | screening, watchlist, identity → batch | Submits each row, completes the job as finalized events arrive; re-screens on list change. |
| policy-engine | 2 · 3 | identity → policy | Synchronous evaluate (callers wait, Redis-cached); publishes policy.evaluated. |
| license-entitlement | 1 · 4 | screening, billing, identity → license | Synchronous quota check before a screening is saved; counts usage from events. |
| identity-management | 0 · 6 | → identity | Most-called service (cached by callers); tenant and user changes go out as events. |
| data-retention | 4 · 1 | governance → retention | Consumes governance decisions, then runs the purge in each owning service over REST. |
| data-governance | 0 · 0 | identity, retention → governance | Retention and erasure decisions, published through the outbox. |
| config | 0 · 1 | → config | Feature flags and rule versions, published through the outbox. |
| watchlist-management | 1 · 0 | → watchlist-management | Customer-defined lists; changes published as events. |
| model-registry | 0 · 1 | → ai | Register / promote / deprecate; lifecycle events. |
| inference | 1 · 1 | ai → ai | Synchronous ML scoring for screening (feature-flagged, off in the lab); consumes training and feedback events. |
| training-orchestrator | 2 · 0 | case → ai | Case decisions become training labels; dispatches jobs to the executor over REST. |
| matching-engine | 0 · 1 | → matching | Called by screening-engine for shadow evaluation (live in the lab); canary and live modes; rollback and outcome-proof events. |
| pep-adverse-media | 0 · 0 | watchlist → pep | PEP and adverse-media profiles, kept separate from sanctions lists. |
| reporting | 0 · 0 | identity → reporting | A request starts generation; report.ready / failed comes back. |
| integration-gateway | 0 · 0 | → gateway | Turns external webhooks and CSV files into internal events. |
| Scheduled ingest — outbound HTTPS, then events (1) | |||
| watchlist-ingest | 0 · 0 | → watchlist | Fetches OpenSanctions and regulator lists on a schedule; REST is only an admin run-now trigger. |
Exhibit L.3. Four services are purely synchronous, and all four exist because someone is waiting: an operator, an analyst at the ad-hoc screen, or a job dispatcher. Everything that fans out — audit, analytics, billing, notifications, re-screening — is asynchronous, so a slow consumer can never hold up a screening. Writes that must not be lost (cases, config, governance, license) leave through a transactional outbox, so a Kafka outage cannot leave the database and the event stream disagreeing. The Python agent tier (Exhibit F) sits on the synchronous side: HTTP through the BFF and MCP over HTTP, with one asynchronous output, its trace event on dps.agent.events.
AWS Migration Map
The lab was deliberately built as a substrate-mirror of the AWS target, so the move is a substrate swap, not a redesign — every lab workload already has its managed counterpart named.
Grounded in the live container census and ADR-0024 (AWS target architecture) plus its three-plane amendment (ADR-0031). Snapshot date: 2026-06-29.
Lab container census — what moves
| VM | Containers | Count |
|---|---|---|
| core | JVM microservices, agent tier, Keycloak, Traefik, static SPAs/website, runner, exporters | ~41 |
| obs | prometheus, grafana, loki, promtail, alertmanager, otel-collector, tempo, blackbox-exporter, node-exporter | 9 |
| data | postgres, pgadmin, redis, redisinsight, opensearch, opensearch-dashboards, postgres-exporter, node-exporter | 8 |
| stream | redpanda, redpanda-console, node-exporter | 3 |
| objstore | minio | 1 |
| ci | native GitLab CE (omnibus) — no Docker | 0 |
| ml | native Ollama — no Docker | 0 |
Total ≈ 62 containers (~41 on core + 21 elsewhere). ci and ml run their workloads natively, not containerized.
Mapping by purpose
| Purpose | Lab today | AWS target | Notes |
|---|---|---|---|
| App services | JVM microservices (~29) · core | ECS Fargate — 1 task/service | Same one-container-per-bounded-context model; per-plane tags (data / operations / tenant) |
| Agent tier | export-drafter, copilot, 3 MCP servers · core | ECS Fargate tasks | Internal-only; reached via the admin-console BFF |
| Identity | Keycloak · core | ECS Fargate task | KC stays KC; RDS-backed |
| Web / static | frontend, frontend-admin, website nginx · core | CloudFront + S3 | Static SPAs/site; the marketing site could alternatively stay on Cloudflare Pages |
| Edge / routing / TLS | Traefik, Let's Encrypt · core | ALB + ACM (+ optional WAF) | oauth2-proxy not needed (per-service JWT validation) |
| Relational DB | postgres · data | RDS for PostgreSQL (Multi-AZ) | Same JDBC shape; schema-per-service |
| Cache | redis · data | ElastiCache for Redis | Same Redis API |
| Search | opensearch · data | Amazon OpenSearch Service | analysis-phonetic / BMPM plugin supported |
| Streaming | redpanda + console · stream | MSK or self-host Redpanda on Fargate/EC2 | Kafka-API compatible either way; decide on cost vs. managed at migration |
| Object storage | minio · objstore | S3 | Essentially free at this volume |
| AI / ML inference | Ollama, native · ml | EC2 GPU (self-host Ollama) or Bedrock | EC2-GPU preserves the on-prem privacy model + model-agnostic LlmPort; Bedrock = fully managed (one-adapter swap) |
| Observability | prometheus, grafana, loki, tempo, alertmanager · obs | self-host on Fargate or AMP + AMG + CloudWatch Logs + X-Ray | Self-host cheaper at this scale; managed at Tier 4 |
| Telemetry agents | otel-collector, promtail, node/blackbox/pg exporters · obs / core / data / stream | ADOT collector / Fluent Bit / CloudWatch agent | ECS service-discovery scraping replaces static targets |
| Admin UIs | pgadmin, redisinsight, opensearch-dashboards, redpanda-console · data / stream | drop (AWS consoles / OpenSearch Dashboards) | Dev convenience; not migrated |
| CI/CD + registry | GitLab CE + Runner · ci + core | ECR + CodePipeline/CodeBuild or GitHub Actions | GitLab is only the CI host; the platform doesn't depend on it. Tag convention unchanged |
| Secrets | .env.sops · core | SSM Parameter Store → Secrets Manager at scale | Same env-var names |
| DNS | firewall DNS overrides / Cloudflare | Route 53 |