Implementation plan / Session plan / Handover FN-S03
Handover FN-S03 Foundation: Service template¶
Card: FN-S03. Issue: cema-care/his#3. Branch: session/FN-S03.
What was built and where¶
All code is in services/_template/. Its README.md is the reference for build sessions: how to make a unit, what each part of a unit is, the duties of the kit and what a module does for each, headers, settings, the test layout and the check. The decisions are in ADR-HIS-044 Service template: the unit build, the service kit and its conventions.
- The template is a unit (
_template, domain codetpl) that builds and passes its tests. It is one Gradle build (Gradle 9.9.2 wrapper, Java 21, Spring Boot 4.1.3), laid out as follows: buildSrc/: the conventionshis.java-moduleandhis.service-app;service-kit/: the cross-cutting code, as a Spring Boot auto-configuration, with test fixtures;app/: the deployableunit.jar;mod-tpl-000/: the example module.
Every configuration is locked: gradle.lockfile in each subproject, buildSrc/gradle.lockfile and settings-gradle.lockfile.
- The kit (care.cema.his.kit) covers each duty of the card:
- health: Actuator liveness and readiness, which includes the database;
- token validation: Spring Security resource server against HIS_OIDC_ISSUER, with an optional audience check (HIS_OIDC_AUDIENCE);
- the policy decision call: PolicyEnforcer and HttpPolicyDecisionClient. It fails closed, refuses obligations the caller does not support, and audits every refusal. A policy Deny answers 403. An outage of the decision point (unreachable, timed out after 250 ms, or an unreadable answer) answers 503 "Authorization service unavailable" with Retry-After, as D02-ISE 9.1 and DEC-ESS-018 require, and is audited as access-check-unavailable;
- audit emission: AuditEmitter, through the outbox, with the DEC-ESS-018 behaviour when the buffer is full;
- the transactional outbox: DomainEventPublisher, OutboxStore and OutboxRelay, with a gapless per-aggregate sequence and one relay at a time;
- the idempotent inbox: InboxProcessor and SubscriptionRunner. It deduplicates on event_id, applies per-aggregate order with held events and a hold timeout, retries a bounded number of times, and has one dead-letter topic per subscription;
- the backbone abstraction: EventTransport, with a Kafka adapter;
- schema migrations: Flyway, one schema and history per module, with his_kit for the kit;
- telemetry and correlation identifiers: a correlation filter, the MDC, span tags, OTLP traces and metrics, ECS JSON logs, and traceparent carried across events;
- the error structure of IF-ISE-001: RFC 9457 problems with code and correlationId.
HisEnvironmentPostProcessor maps the HIS_* variables of his-env env to Spring properties, so a unit needs no settings to run in the integration environment.
- Test layout:
- @HisServiceTest gives each test context a scratch database in the session's PostgreSQL, test tokens, a loopback backbone (redeliverAll() replays duplicates) and a fake policy decision point that denies by default;
- module tests start the module alone with the kit;
- the app tests start the whole unit and check module boundaries with ArchUnit;
- the kit's tests are copied with the kit into every unit.
- Generator services/_template/new-unit.sh <unit> <MODULE-ID>.... It copies the build, kit, application and Dockerfile, writes gradle.properties, and makes one module per identifier from skeleton/module/. Each module gets its package, schema, Mod<nnn>Module declaration, migration folder and a start-up test that names the module. The unit folder's existing README is kept. --with-example adds the example module as MOD-<D>-000; --into <dir> writes elsewhere.
- Dockerfile: the image his/<unit>, built on Temurin 21 JRE pinned by digest, running as a non-root user.
- Check services/_template/check.sh (lib/template_check.py, Python standard library only): the "Ends when" check of this card, repeatable by any later session.
- CLAUDE.md section 3: the FN-S03 entry is marked as landed, with how to make a unit, the host prerequisite and the check.
- Decision record index: the row of ADR-HIS-044 and the count of 44, in the form build_adrs.py writes. This was checked by running the generator on a scratch copy and diffing; the result was identical. The plan build was not run in the checkout.
Checks and their result¶
Host: Docker 29.9.3 with Compose v5.7.1, 4 CPUs, 15 GB of memory. The host had no JDK, so OpenJDK 21.0.13 was installed with apt (openjdk-21-jdk-headless). Every environment ran under HIS_SESSION=FN-S03 (his-fn-s03).
| Check | Command | Result |
|---|---|---|
| Template builds, tests pass on the light profile | platform/dev-environment/his-env start light, then ./gradlew build in services/_template |
Passed after review round 1: 44 tests, 0 failed; the Kafka adapter test (one of the 44) is skipped on light |
| A unit generated outside the template builds and its tests pass | new-unit.sh --into <scratch>/cli-orders --with-example cli-orders MOD-CLI-006 MOD-CLI-007, then ./gradlew dependencies --write-locks && ./gradlew build |
Passed: 45 tests, 0 failed. Domain cli, packages, schemas, topics and the module specification links were all rewritten |
| Ends when: a service made from the template starts in the integration environment, publishes and consumes one test event idempotently, and its tests pass | HIS_SESSION=FN-S03 services/_template/check.sh |
Passed: 14 of 14 checks (list below). The run ends with the scratch database dropped and the environment reset; afterwards no container or volume with the session label was left |
| Image | docker build of the template, then id in the container |
Builds; runs as uid 10001. The test image was removed |
| Decision record index matches the generator | build_adrs.py on a scratch copy, then diff |
Identical |
Link check of docs/ |
python3 docs/implementation_plan/tools/check_links.py |
0 broken links, 0 duplicate anchors |
Links in CLAUDE.md and the template READMEs (outside docs/) |
A one-off script applying the same rule | 0 broken |
| Documentation site build | mkdocs build |
Builds |
The 14 checks of check.sh, each against the real backing services of the full profile:
- The unit
tpl-check, made from the template with the example module and one skeleton module, builds. Its 45 tests pass (after review round 1), including the Kafka adapter test against the session's Kafka. - It starts (
java -jar unit.jar) and reports ready. - Liveness answers without a token.
- A request without a token gets 401
unauthenticated. - A token comes from the Keycloak test realm (
dev.registrar). - With that token a probe is recorded (201).
- The correlation identifier is returned.
- The stub policy decision point received subject, action, facility and purpose.
- The test event went through the outbox, the relay and Kafka, and the unit's own subscription consumed it once.
- The event carries the envelope: type, sequence 1, facility, correlation identifier and actor kind.
- The same event was put on the topic a second time. The consumer group read it, its lag went back to 0, and its log-end offset had grown.
- The duplicate had no second effect: the receipt count is still 1, and the inbox holds one row.
- The action's audit event reached
his.ess.auditintake.v1with its decision identifier, and there was no denial. - One trace in Tempo runs from
POST /v1/probesthroughconsume his.tpl.TemplateProbeRecorded.
Two faults were found and fixed while making the check pass:
- The Kafka producer's delivery timeout was below its request timeout plus linger. The Kafka adapter test caught it.
- The check's stub policy decision point did not read chunked request bodies. The client then correctly denied the request, and the check reported the denial.
Requirements and test scenarios¶
The card implements no functional requirement and lists no test scenario. The tests are tagged FN-S03 and named by the interface or architecture rule they show. A gate session can find them by these tags:
| Rule | Tests |
|---|---|
| IF-ISE-002 events: outbox, sequence, envelope, inbox, order, dead letters | ProbeFlowTest (publish and consume once, envelope, per-aggregate sequence); OutboxTest (rollback, order, retriable and validation failures, guards, purge); InboxTest (duplicate, handler context, stale, gap held then filled, hold timeout, retry, dead letter, malformed); EnvelopeCodecTest; KafkaEventTransportTest (full profile) |
| IF-ESS-003 and architecture 8.1, 8.3: policy decision, fail closed | HttpPolicyDecisionClientTest; ProbeFlowTest tagged ARC-8.1 (request content, Deny audited and without effect, unsupported obligation refused) |
| D02-ISE 9.1, DEC-ESS-018: policy service outage | ProbeFlowTest "a policy service outage is answered as unavailable with a retry indication, not as a refusal, and audited as an outage"; HttpPolicyDecisionClientTest (errors, timeouts, unreadable answers and an unreachable point are marked as outages; a policy Deny is not) |
| Architecture 7.5: facility | ProbeFlowTest tagged ARC-7.5 (denial across facilities by policy, service-layer filter, facility required) |
| Architecture 8.2: token validation, service identity | ProbeFlowTest tagged ARC-8.2 (none, expired, wrong issuer, unknown signer, malformed; service account) |
| Architecture 8.4, DEC-ESS-018: audit | ProbeFlowTest tagged ARC-8.4; AuditBufferTest (inside the transaction only; buffer full: Tier 2 blocks, Tier 1 continues) |
| IF-ISE-001: correlation, errors | ProbeFlowTest tagged IF-ISE-001, and the problem bodies asserted throughout |
| Health, start-up, boundaries, settings | UnitApplicationTest, ModuleBoundaryTest, EnvironmentMappingTest, and in each generated module Mod<nnn>ModuleTest |
Differences from the card or specification¶
- Provisional contracts. No contract exists yet for the decision API of the policy decision service (IF-ESS-003), for the audit intake channel (IF-ESS-008), or for the envelope's wire form (FN-S04). The template uses its own shapes for all three. Each is in one class of the kit, listed in the README under "Provisional" and in ADR-HIS-044. No unit has been made from the template yet, so the template itself changes first when the contracts are fixed.
- Header names. IF-ISE-001 names the purpose of each header but not its spelling. The template uses
X-Correlation-Id,X-Facility,X-Purpose-Of-UseandIdempotency-Key, recorded in ADR-HIS-044. - The template's own database
service_templateis not created byhis-env, which skips_template. Tests never need it, since each test context makes a scratch database. The check runs a generated unit with its own database. - The policy decision point is not in the integration environment. Tests use the fake, and the check uses a stub that permits. A unit does not start without
HIS_POLICY_URL. - The outbox relay is inside each unit. Architecture 6.3 names CMP-ISE-014 as "the outbox relay". That component's description is "producer and consumer patterns", and the template implements that pattern in the unit (ADR-HIS-044 gives the reasons).
Questions for a person¶
None. ADR-HIS-044 awaits the approval of the Enterprise Architecture Board, which is given on the merged work.
Follow-ups outside the card¶
- ESS contract sessions (RC-1):
- fix the decision API (IF-ESS-003) and the audit intake (IF-ESS-008), then replace
HttpPolicyDecisionClient.Answer, thePolicyRequestwire form andAuditPropertiesin the template; - add Open Policy Agent to the integration environment (FN-S02 follow-up), so that
HIS_POLICY_URLcan come fromhis-env env. - FN-S04:
- fix the envelope and replace
EnvelopeCodec's mapping if it differs; - register schemas;
- put the contract test harness behind the
contracttag and the folder named in the README; - decide whether topics come from the contract, in place of
his.events.kafka.create-topics(FN-S02's question; the template answers it for the local environment only). - FN-S05:
- build Java units with JDK 21 (
actions/setup-java) and starthis-env start lightbefore./gradlew build; - run
services/_template/check.shwhenservices/_template/changes; - scan the Temurin base image of the Dockerfile and enter it in the software bill of materials;
- report drift between a unit's
service-kit/and the template's. - Not in the template yet, for the first card that needs each:
- replay of commands by
Idempotency-Key; - optimistic concurrency with
ETagandIf-Match, with the version and deprecation indication in responses (IF-ISE-001); - caching of policy decisions with invalidation on policy, identity and consent events (FR-ESS-AUZ-001 part 6.9);
- the policy-outage paths of D02-ISE 9.1 beyond the outage answer. These are the retry on another replica and the circuit breaker of CFG-ISE-031, and the Tier 1 clinical cached-Permit read path (up to 60 minutes) of CFG-ESS-025. The read path needs the decision cache, is never for restricted content, and audits each use;
- a required token audience, once the ESS identity contract names the audiences. The check exists behind
HIS_OIDC_AUDIENCE; today patient tokens are kept out by their separate issuer (DEC-ESS-001); - batch decisions and search filters;
- Break-the-Glass;
- mTLS between workloads;
- database credentials from OpenBao;
- the operator replay controls of architecture 6.3.
- Image name. Docker refuses
his/_template(a name may not start with an underscore). The template image is only ever built for testing; units' names are valid.