Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,5 @@ $RECYCLE.BIN/
appsettings.*.local.json
# Personal Claude Code settings (shared skills in .claude/skills are committed)
.claude/settings.local.json
# Schema contract output of a failed run: review it, never commit it (ADR 0036)
*.received.json
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ The host runs one Wolverine bus ([ADR 0017](docs/adr/0017-wolverine-wiring.md)).
- **Dispatch:** `.Api` and `.Mcp` call `IMessageBus.InvokeAsync<Result<T>>(…)` and use no other Wolverine type (`adapters-dispatch-through-the-message-bus`).
- **Idempotency:** every command record implements `ICommand` and so carries an `IdempotencyKey IdempotencyKey`. `AddServiceDomainStore` wraps every command handler with the idempotency policy ([ADR 0018](docs/adr/0018-idempotency-keys-for-commands.md)): the same key and payload return the stored acknowledgement and the handler does not run again; the same key with another payload returns `shared.idempotency-key-reused`; a key still being handled returns `shared.idempotency-key-in-use`; a missing key returns `shared.idempotency-key-missing`. Only successful results are stored, so a rejected command can be retried with the same key. Keys are scoped to the caller: two callers with the same key never replay or block each other, and messages no caller sent share the system scope ([ADR 0019](docs/adr/0019-authentication-baseline.md)). The handler never reads the key. A `.Subscriptions` adapter builds the key from the requesting record's identifier (`IdempotencyKey.From(...)`).
- **HTTP:** every `.Api` endpoint that dispatches a command requires the header with `RequireIdempotencyKey()` from `RimBank.Api` (on the endpoint or its route group), takes an `IdempotencyKeyHeader idempotency` parameter and passes `idempotency.Value` into the command. `Retrieve` (query) endpoints take no key.
- **Published language** ([ADR 0036](docs/adr/0036-party-published-language.md)): an integration event other contexts consume is a BCL record in the context's `.PublishedLanguage` project, with `public const string Channel` (its BIAN AsyncAPI channel) and `public const string MessageIdentity` (`<record>.<event>.v<N>`), which is its name on the wire. A pure mapper in the core builds it from the decided domain events, never from a view, and the command handler returns it as `(Result<TAcknowledgement>, TEvent?)`.
- **Changing a published event:** you may only add a field. Removing, renaming or retyping a field, or changing its meaning, needs a new type with the next `.v<N>` identity, published next to the old one until its consumers move. Each event's schema is pinned by `Publication/Approved/<identity>.approved.json` in the context's `.Postgresql.Tests`. When the contract test fails, it writes `<identity>.received.json` next to it (git-ignored). Review it, and copy it over the approved file only for an additive change, in the same pull request.
- **Host message store:** Wolverine keeps its own bookkeeping in schema `wolverine` (role `rimbank_wolverine`, `ConnectionStrings:Wolverine`). Without that connection string, as before the first context, messages stay in memory.

### BIAN conformance
Expand Down
1 change: 1 addition & 0 deletions RimBank.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</Folder>
<Folder Name="/src/">
<Project Path="src/Party/RimBank.Party.PartyReferenceDataDirectory.Postgresql/RimBank.Party.PartyReferenceDataDirectory.Postgresql.csproj" />
<Project Path="src/Party/RimBank.Party.PartyReferenceDataDirectory.PublishedLanguage/RimBank.Party.PartyReferenceDataDirectory.PublishedLanguage.csproj" />
<Project Path="src/RimBank.Api/RimBank.Api.csproj" />
<Project Path="src/RimBank.AppHost/RimBank.AppHost.csproj" />
<Project Path="src/RimBank.Core/RimBank.Core.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions docs/adr/0024-party-reference-data-directory-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ The exact names are fixed by the phase that adds each event, within this list. E

### Integration channels

Integration events are mapped from domain events, never from views (tech-stack §8.4). Each one carries the state its consumers need.
Integration events are mapped from domain events, never from views (tech-stack §8.4). Each one carries the state its consumers need. [ADR 0036](0036-party-published-language.md) fixes their shape, identity, versioning and contract test.

| AsyncAPI channel | From | Phase |
|---|---|---|
| `PartyReferenceDataDirectoryEntry/Created` | `PartyRegistered` | 1.13 |
| `PartyReferenceDataDirectoryEntry/Updated` | `PartyReferenceDataDirectoryEntryUpdated` | 1.13 |
| `PartyReferenceDataDirectoryEntry/Created` | `PartyRegistered`, published as `PartyReferenceDataDirectoryEntryCreated` (`party-reference-data-directory-entry.created.v1`) | 1.13 |
| `PartyReferenceDataDirectoryEntry/Updated` | `PartyReferenceDataDirectoryEntryUpdated`, published as `PartyReferenceDataDirectoryEntryUpdated` (`party-reference-data-directory-entry.updated.v1`) | 1.13 |
| `Demographics/Created`, `Demographics/Updated` | The first / a later `DemographicsUpdated` or `DemographicsExchanged` of an entry | deferred |
| `Reference/Created`, `Reference/Updated` | The first / a later `PartyReferenceUpdated` of an entry | deferred |
| `Associations/Created`, `Associations/Updated` | `PartyAssociationRegistered` / `PartyAssociationUpdated` | deferred |
Expand Down
73 changes: 73 additions & 0 deletions docs/adr/0036-party-published-language.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 0036. Party Reference Data Directory: published language

- Status: Accepted
- Date: 2026-11-08
- Roadmap phase: 1.13

## Context

Until 1.13, nothing left Party Reference Data Directory. Current Account (roadmap 4.1) will need to know that a party exists, without querying Party ([mission](../../specs/mission.md) principle 7, consumers own their copy). [Tech-stack §8.4](../../specs/tech-stack.md#84-read-models-across-contexts-loose-coupling) sets the producer rules: integration events are mapped from domain events through the outbox, never from read models; they carry the state consumers need; they are versioned and change only in backwards-compatible ways; and a contract test pins each schema.

[ADR 0024](0024-party-reference-data-directory-mapping.md#integration-channels) maps the two Control Record channels of the [BIAN AsyncAPI](../../doc-0/release14.0.0/apis-iso20022_ext-ddd/asyncapi-3.x/yamls/PartyReferenceDataDirectory.yaml) to phase 1.13: `PartyRegistered` maps to `PartyReferenceDataDirectoryEntry/Created`, and `PartyReferenceDataDirectoryEntryUpdated` maps to `…/Updated`. It defers the 8 BQ channels. The BIAN payload is the Control Record schema: `PartyReference`, `PartyType`, `DirectoryEntryDateType` (`OpenDate` / `RefreshDate`) and `DirectoryEntryDate`.

Constraints:
- `.PublishedLanguage` is BCL only ([tech-stack §4](../../specs/tech-stack.md#4-dependency-rules-enforced-by-architecture-tests)), so it cannot use Wolverine's `[MessageIdentity]` attribute.
- The core uses no Wolverine type ([ADR 0017](0017-wolverine-wiring.md)).
- No new package is allowed without a reason ([ADR 0013](0013-warning-and-package-governance.md)).

## Options considered

**Payload**
1. **The Control Record state plus a small envelope** (`EventId`, `OccurredAt`, `Version`). Consumers can order and deduplicate. There is no PII.
2. The same, with the Behavior Qualifier ids. No consumer needs them yet.
3. Only the id and party type. Too thin: a consumer could not order events.

**Versioning**
1. **A stable message identity declared on the type as a constant** (`MessageIdentity`), given to Wolverine by a naming strategy in the adapter wiring. Changes may only add fields.
2. A `V1` suffix on the CLR type. Simpler, but the wire name would be the CLR name, so a rename or a move would break consumers.
3. A version field in the payload. It does not say which type to deserialise to.

**Mapping and delivery**
1. **A pure mapper in core, cascaded by the command handler** as `(Result<Ack>, Event?)`, the 0.11 pattern. The event commits with the domain events in one transaction.
2. Marten event forwarding in `.Postgresql`. Handlers stay unchanged, but the business mapping moves into an adapter, and the transaction behaviour depends on more wiring.

**Contract test**
1. **A JSON schema exported with `System.Text.Json.Schema.JsonSchemaExporter` (BCL), compared to a committed approved file.**
2. A snapshot package (Verify). It needs a new package for little gain.

## Decision

- **Project:** `src/Party/RimBank.Party.PartyReferenceDataDirectory.PublishedLanguage` (namespace `RimBank.Party.PartyReferenceDataDirectory.PublishedLanguage`, BCL only). It holds `PartyReferenceDataDirectoryEntryCreated` and `PartyReferenceDataDirectoryEntryUpdated`, with the fields:
- `EventId` (Guid v7);
- `OccurredAt`;
- `PartyReferenceDataDirectoryEntryId`;
- `Version` (the entry's stream version after the event);
- `PartyType`;
- `DirectoryEntryDateType`;
- `DirectoryEntryDate`.

`PartyType` and `DirectoryEntryDateType` are strings, with the allowed values in `PartyTypes` and `DirectoryEntryDateTypes`. They are not enums, so a value added later never breaks an older consumer. There is no PII and no BQ id.
- **Identity:** each event declares `public const string Channel` (its BIAN channel) and `public const string MessageIdentity`: `party-reference-data-directory-entry.created.v1` and `…updated.v1`.
- `RimBank.Postgresql.PublishedLanguageMessageNaming` gives any type in a `*.PublishedLanguage` namespace the identity it declares. It is registered once, ahead of Wolverine's own naming, by `AddServiceDomainStore`, through `WolverineMessageNaming.InsertFirst`. Every other message keeps Wolverine's default name.
- **Compatibility:** a field may be added; a field is never removed, renamed or retyped. A breaking change is a new type with a `.v2` identity, published next to v1 until consumers move.
- **Mapping:** `PartyReferenceDataDirectoryPublication` (core, `Publication/`) maps a decided `PartyRegistered` or `PartyReferenceDataDirectoryEntryUpdated` to its integration event. `OccurredAt` and `DirectoryEntryDate` are the open or refresh date, so the mapper is pure. `RegisterPartyHandler` and `UpdatePartyReferenceDataDirectoryEntryHandler` return `(Result<…Acknowledged>, <event>?)`, with the event id from their `TimeProvider`. An error returns `null`, so a refused command publishes nothing by construction. An idempotent replay does not run the handler (ADR 0018), so it publishes nothing again. Behavior Qualifier commands publish nothing.
- **Delivery:** the cascaded event goes to the context's durable local queue (ADR 0017's namespace rule also covers the child namespace `.PublishedLanguage`). Its envelope is saved in `party_reference_data_directory.wolverine_incoming_envelopes` in the same transaction as the events. Until a consumer exists (4.1), no handler receives it, and Wolverine logs it and discards it (`UnknownMessageBehavior.LogOnly`, the default). Events are not replayed for entries registered before 1.13, because there is no consumer to replay for. 4.1 decides how a new consumer catches up.
- **Wire format:** Wolverine's default System.Text.Json serializer, so property names are camelCase on the wire (`partyType`). Reads are case-insensitive, and an unknown field is ignored. BIAN names the same fields in PascalCase; 1.14 compares them without regard to case.
- **Contract:** `PartyPublishedLanguageSchemaTests` (Party `.Postgresql.Tests`, `Publication/`) exports each event's schema with the wire settings and compares it, with its channel and identity, to `Publication/Approved/<identity>.approved.json`. On a mismatch it writes `<identity>.received.json` (git-ignored). The test also checks:
- Wolverine writes the same property names;
- an event survives the wire round trip;
- a v1 reader tolerates an added field;
- every published type goes on the wire under its declared identity.

## Consequences

- Any change to a published event shows up in review as a diff of the approved file. Updating that file on purpose is the only way to change the contract, and a removal or rename must be a new versioned type instead.
- `PartyReferenceDataDirectoryCatalogue` (conformance) gives each 1.13 channel its event type. Its tests check that each event's `Channel` matches its row, that only deferred channels have no event, and that the addresses exist in the AsyncAPI.
- Integration tests (`PublishedLanguageOutboxTests`) prove:
- exactly one event per accepted Register or Update, with the right version and payload;
- the stored envelope carries the v1 identity and the expected JSON;
- nothing for a conflict, an unknown entry, a replay or a BQ update;
- one envelope per committed Control Record event, all in the context's own schema.
- Next contexts follow the same pattern: a BCL `.PublishedLanguage` whose types declare `Channel` and `MessageIdentity`, a pure mapper in core, a handler cascade and an approved schema per event. The naming strategy needs no per-context wiring.
- **4.1** must decide how Current Account receives these events (its handler in `.Subscriptions` will run on Party's queue unless it routes them to its own), and how a new consumer catches up on parties registered before it existed.
- Wolverine's message naming is process-wide (static). The naming strategy only answers for `*.PublishedLanguage` types, so it changes no other message name.
46 changes: 46 additions & 0 deletions specs/2026-11-08-party-published-language/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Plan: Party Reference Data Directory: published language

The solution builds and every test passes after each group.

## 1. Published language project and events
- [ ] Create `src/Party/RimBank.Party.PartyReferenceDataDirectory.PublishedLanguage/` (csproj with no package reference, `packages.lock.json`), add it to `RimBank.slnx`, and reference it from `RimBank.Core`.
- [ ] `PartyReferenceDataDirectoryEntryCreated` and `PartyReferenceDataDirectoryEntryUpdated` sealed records (fields in requirements.md), with XML docs naming the BIAN channel and the v1 identity.
- [ ] `PartyTypes` and `DirectoryEntryDateTypes` constants classes.
- [ ] Run the architecture tests: the existing `.PublishedLanguage` rules (BCL only, no views, only own core and `.Subscriptions` may use it) now apply to a real project and stay green.

## 2. Mapper in core
- [ ] `RimBank.Core/Party/PartyReferenceDataDirectory/Publication/PartyReferenceDataDirectoryPublication.cs`: `Created(PartyRegistered, version, eventId)` and `Updated(PartyReferenceDataDirectoryEntryUpdated, version, eventId)`. `PartyType` is mapped to its published string with a switch expression (IDE0066).
- [ ] `tests/RimBank.Core.Tests/Party/PartyReferenceDataDirectory/Publication/PartyReferenceDataDirectoryPublicationTests.cs`:
- Register maps to Created with `OpenDate`;
- Update maps to Updated with `RefreshDate`;
- every party type has a published value, and an unknown one is refused;
- the `PartyType` string, the version and `OccurredAt` are carried.

## 3. Handler cascade and Wolverine wiring
- [ ] `RegisterPartyHandler` returns `(Result<RegisterPartyAcknowledged>, PartyReferenceDataDirectoryEntryCreated?)`, and `UpdatePartyReferenceDataDirectoryEntryHandler` returns `(…, PartyReferenceDataDirectoryEntryUpdated?)`. The event id is `Guid.CreateVersion7(time.GetUtcNow())`, and the event is `null` on every error path.
- [ ] Update the handler tests in `RimBank.Core.Tests`:
- success yields exactly one event, with version 1 after Register and N+1 after Update;
- not found, version conflict and decision errors yield `null`.
- [ ] Check the API and MCP callers that `InvokeAsync<Result<…>>` still gets the acknowledgement. `RimBank.Api` should need no change.
- [ ] `RimBank.Postgresql/PublishedLanguageMessageNaming.cs`: an `IMessageTypeNaming` that reads the `MessageIdentity` constant of `*.PublishedLanguage` types, registered once in `AddServiceDomainStore` (`WolverineMessageNaming.InsertFirst`), with unit tests in `RimBank.Postgresql.Tests`.
- [ ] Confirm the events are persisted in the party schema's `wolverine_incoming_envelopes` (durable local queue). With no handler, Wolverine discards them with a log entry. That is accepted until 4.1.

## 4. Outbox integration tests (Testcontainers)
- [ ] `tests/Party/RimBank.Party.PartyReferenceDataDirectory.Postgresql.Tests/Publication/PublishedLanguageOutboxTests.cs`, using a Wolverine tracked session and a test-only subscriber handler:
- Register publishes exactly one Created with the right id, type, date and version 1;
- Update publishes exactly one Updated with version 2;
- a stale `ExpectedVersion` publishes nothing;
- an unknown entry publishes nothing;
- a replayed `Idempotency-Key` publishes nothing again;
- a BQ Update (Demographics) publishes nothing;
- the stored envelope carries the v1 identity and the expected JSON payload;
- there is exactly one envelope per committed Control Record event, and none in the host's `wolverine` schema.

## 5. Schema contract
- [ ] `tests/Party/RimBank.Party.PartyReferenceDataDirectory.Postgresql.Tests/Publication/PartyPublishedLanguageSchemaTests.cs` (it references Wolverine, so it can check the real serializer): export each event's JSON schema with `JsonSchemaExporter` and Wolverine's wire settings. Compare it, with the event's channel and identity, to `Publication/Approved/<identity>.approved.json`. On a mismatch, the test writes `*.received.json` (git-ignored) and fails with a message pointing to ADR 0036.
- [ ] Also test: Wolverine writes the same property names, an event survives the wire round trip, a v1 reader tolerates an added field, and each type goes on the wire under its declared identity.

## 6. Catalogue, ADRs and docs
- [ ] `PartyReferenceDataDirectoryCatalogue`: give each CR channel its CLR type, and add a test that every channel catalogued for a done phase has a type and that its address exists in the AsyncAPI YAML.
- [ ] ADR 0036 (Party published language), ADR 0024 integration-channel table, tech-stack §3 tree and §8.4 link, and the CONTRIBUTING "changing a published event" note.
- [ ] Tick roadmap 1.13. Then run `dotnet format --verify-no-changes` and the full `dotnet test`.
Loading
Loading