Registry stack documentation: machine-readable Markdown.
Index of all pages: https://docs.registrystack.org/llms.txt
Full corpus: https://docs.registrystack.org/llms-full.txt

# GovStack Consultation and Write

> Configure the Registry Adapter's GovStack facade, with Retrieve, Lookup, List, and Search reads, direct Create and conditional Update writes, schemas, capabilities, cursors, and the source guarantees a write needs.

If you expose a registry through the Registry Adapter's GovStack facade, this page states what the
facade serves, what your pack and project must declare for each operation, and which refusals and
limits apply.
The facade implements a profile of the unratified GovStack Digital Registries draft: selected Read
operations and direct Write operations, served by maintained Rust protocol code over the shared
Adapter engine.
It makes no general GovStack conformance claim.
The basis is a draft that no body has ratified, and nothing here is a certification against it.
The reads are bounded, and the writes are synchronous direct Create and conditional Update.
The API basis is the
[unified draft contract](https://jeremi.github.io/bb-digital-registries/api/openapi.yaml);
its `write.openapi.yaml` URL is an alias for that document.

## What the pack, the project, and the host own

A source pack owns source operations, authentication requirements, bounded requests, native errors,
identity resolution, and source continuation.
A source operation declares only the semantics and prerequisites its implementation can support.
A source brand, a timestamp, or a successfully decoded page is not proof of history, temporal
selection, uniqueness, or traversal guarantees.

A project selects source operations and supplies its transformation, versioned output schema,
collection and Registry identifiers, named inputs, and access policy.
Transformations are reviewed, digest-covered artifacts with the existing script and execution limits.
Their output is validated before disclosure.
A transformation cannot grant source authority, read secrets, or create source-backed guarantees.
Shared mapping parameters and scripts can be reused without a separate transformation-package format.

The GovStack host owns the canonical `/govstack/registries` mount, versioned HTTP paths, methods,
request and response shapes, problem mapping, headers, cursor context, and capability annotations.
Generated OpenAPI uses `/govstack/registries` as `servers.url` and keeps its operation paths relative
under `/v1/...`.
The host adds no separate service or project-specific runtime configuration; it reuses the facade's
authentication, access admission, bounded engine, and durable journal.
Authentication and scope denial precede any source effect, and a required audit failure releases no
protected result.

Evidence consumes the same source pack through its listener-free engine binding and keeps its own
facts contract, assertion evaluation, authorisation, signing, and release audit.
It does not need to construct a GovStack Record.
An Evidence Source can select a package-owned projection of matched native facts and its own
versioned facts schema without changing its pack.
No-match, ambiguous, and unresolved outcomes are preserved, and projection failures prevent
derivation under the original acquisition deadline.

{/* Evidence: crates/registry-adapter/src/govstack/mod.rs;
    crates/registry-adapter/tests/govstack_namespace_served.rs
    builtin_discovery_and_reads_live_only_under_the_public_mount,
    openapi_capabilities_and_runtime_contract_resolve_the_same_public_operations;
    crates/registry-adapter/tests/consultation_builtin_served.rs
    authorization_and_collection_denials_happen_before_source_io. */}

## Schemas and capabilities

Each Consultation collection selects its public data schema once through `dataSchema`, referencing
the project artifact inventory.
Its `view` defaults to the `dataSchema` identifier.
A collection `transform` names the script that every Retrieve, Lookup, List, and Search binding of
that record type follows; a `bindingTransforms` entry overrides it for one binding.

The schema is JSON Schema with a stable versioned identity and an exact artifact digest.
It supports nested objects, bounded arrays, and local schema definitions.
Schemas are self-contained reviewed artifacts: `$ref` references stay inside the selected document.
Build and load verify the exact pin, and serving performs no remote schema fetch.
The compiler wraps the data schema in the fixed protocol envelopes and emits the concrete OpenAPI
contract.
An input schema describes each enabled selector or named Search separately from the response schema,
so the public contract never implies that every payload field is searchable.

Pack support, project enablement, and caller-visible availability are distinct.
The loaded plan derives the effective operation set from the selected Rust protocol, source bindings,
transformations, schema checks, and deployment policy.
Source-dependent features require declared source semantics and verified prerequisites.
Host-provided features do not require an upstream feature of the same name.
Unsupported capabilities and feature declarations fail explicitly instead of being advertised or
silently ignored.

The facade serves a caller-filtered `GET /govstack/registries/v1/capabilities` with
`Cache-Control: no-store`.
Entries reference stable operation identifiers in a version-specific HTTPS OpenAPI contract and
identify their Registry and Collection.
Read entries select a view; Write entries use `family: write`.
Every Create and Update entry carries `write.idempotencyReplayWindow` (integer seconds), and Update
also identifies its companion Retrieve operation and view.
A deployment with no Write entries publishes no replay window.
The contract supplies input and output schemas and the selected features.
Discovery does not grant access to any Record or replace authorisation at invocation.
No credentials, source addresses, private configuration, or unsupported pack operations enter this
response.

{/* Evidence: crates/registry-adapter/tests/consultation_schema_served.rs;
    crates/registry-adapter/tests/consultation_builtin_served.rs
    capabilities_expose_only_the_three_schema_bound_views_the_caller_can_read,
    capabilities_are_not_released_when_the_audit_append_fails;
    crates/registry-adapter-core/src/project.rs read_data_schema. */}

## Reads

The facade implements Retrieve, exact Lookup, List, and named Search where the project binds an
eligible source route.
The initial binding supports one exact identifier selector and one declared scalar-equality Search per
Collection.
Composite selectors, additional comparisons, and multiple named operations require corresponding
checked source and input bindings before they can be advertised.
Lookup resolves at most one permitted Record and preserves declared uniqueness and protected-existence
outcomes.

A Lookup naming a selector the Collection does not declare returns 422 `invalid-content` with the
pointer `/selector`.
A Search naming an undeclared search returns the pointer `/search`.
A refused value points at `/values` or `/criteria`.
Generated OpenAPI declares the bounds the facade enforces:

- A `recordId` path parameter is one canonical path segment of at most 256 characters, with no `.` or
  `..`, no `/`, `\`, `?`, `;`, `:`, `%`, control, or invisible formatting characters.
- `Idempotency-Key` is a quoted Structured Field String of 1 to 200 printable ASCII characters.
- Lookup values follow the project-owned input schema.

List and Search require a declared deterministic source order with a unique tie-breaker, bounded pages,
and explicit completion.
A cursor is opaque, excludes personal data, and binds the operation, Registry, Collection, query, view,
page size, and applicable caller and access context.
The caller context is the verified issuer, the subject, and the verified client the caller acts
through (`azp` or `client_id`).
A cursor issued to one client is therefore refused when the same subject presents it through another,
with the same `invalid-cursor` problem as any other mismatch.
The token instance is not bound, so a refreshed token for the same subject and client continues a
traversal.
No purpose is bound, because Consultation carries none.
A malformed, expired, or mismatched cursor is refused before source execution.
Every page applies current authorisation.
An empty advancing page is permitted; an unavailable source guarantee is never reported as completion.

The maintained DHIS2 example exercises the selected baseline reads with an explicit unique order.
The maintained OpenCRVS example exercises exact reads through documented synthetic fixtures.
Retrieve and Lookup were also checked live against an OpenCRVS test environment in November 2026;
the OpenCRVS version could not be read, so no tested version is recorded.
Neither example advertises retained revisions, recorded-time, effective-time, complete traversal, or
snapshot traversal without source-backed implementation and evidence.
Unsupported optional features are rejected in authoring and requests.
A generated frontend can discover operations and schemas; it does not infer domain workflows or field
meanings.

{/* Evidence: crates/registry-adapter/tests/govstack_consultation_served.rs
    a_lookup_refuses_what_its_closed_shape_does_not_name,
    a_search_refuses_undeclared_criteria_and_unknown_searches,
    a_cursor_is_bound_to_its_client_and_survives_a_refreshed_token,
    a_cursor_refuses_a_different_page_size_and_a_forged_text,
    a_retrieve_identifier_that_cannot_be_one_path_segment_is_not_found_before_any_upstream_call;
    crates/registry-adapter/tests/consultation_builtin_served.rs
    opencrvs_retrieve_and_lookup_use_the_same_exact_native_read_with_oauth,
    lookup_list_and_search_use_native_inputs_and_the_stable_source_order. */}

{/* TODO[evidence]: no test names the 256 character recordId bound or the 1 to 200 character
    Idempotency-Key bound in the generated OpenAPI; the live OpenCRVS check has no recorded run. */}

## Writes

The GovStack Write path through the Adapter is experimental: its behaviour and configuration may change
before release.
The maintained write source is the Base Registry Engine (BReg).

### Create

`POST /govstack/registries/v1/collections/{collectionId}/records` accepts a closed `{"data": ...}`
input.
It returns 201 with `Location`, a strong `ETag`, and a receipt containing `collectionId`, `recordId`,
and the same ETag.
The source assigns the durable Record identifier.
An upsert with a client-selected identifier is not this Create guarantee.

### Update

`PATCH /govstack/registries/v1/collections/{collectionId}/records/{recordId}` accepts
`application/merge-patch+json` and a nonempty domain merge patch under `data`.
Null removes an optional member under RFC 7396; the selected input schema refuses a null for a
required field.
Update validates its domain patch before any effect.

The merge patch is flat.
A member whose value is an object returns 422 `invalid-content` with one `errors` pointer per such
member (for example `/data/address`), whatever the input schema admits, because a source applies each
member as one whole-member change rather than a recursive merge.
An array value replaces the whole member, as RFC 7396 specifies.

One strong `If-Match` is required.
A missing one returns 428, a malformed one returns 400, and a mismatched guard returns a generic 412
without a mutation.
A synchronous commit returns a bodyless 204, no `Content-Type`, and a new strong ETag.
The source must compare and commit atomically; a preliminary read followed by a timestamp comparison
is insufficient.

A retry of an Update that already has a stored answer under the same key and fingerprint replays that
answer even when its guard can no longer be opened, after a redeploy changed the guard's closure or
its sealing key was rotated out.
A retry while the first attempt still runs gets 409 `idempotency-in-flight` with `Retry-After`.
Authentication and authorisation are still checked first, and a changed fingerprint under a stale
guard still returns 412.

An Update does not negotiate `Accept`: its success has no body and its Problems are always
`application/problem+json`, so it never returns 406.
Create and reads still return 406 when `Accept` admits neither `application/json` nor
`application/problem+json`.

{/* Evidence: crates/registry-adapter/tests/govstack_write_replay.rs
    fixed_write_replay_renders_create_and_conditional_update_semantics,
    fixed_conditional_write_replay_maps_native_412_to_precondition_failed;
    crates/registry-adapter/tests/postgres_govstack_write_audit.rs
    a_retry_under_a_stale_guard_is_answered_in_flight_while_its_update_runs,
    a_bodyless_update_does_not_negotiate_accept_but_create_still_does;
    crates/registry-adapter/tests/govstack_consultation_served.rs
    a_method_the_path_does_not_serve_is_405_and_an_unacceptable_accept_is_406;
    crates/registry-adapter/tests/govstack_breg_write.rs
    real_breg_and_adapter_preserve_write_receipts_conditions_and_exact_recovery. */}

{/* TODO[evidence]: no test names the flat merge patch refusal pointer per object member, the 428 for
    a missing If-Match, or the 400 for a malformed one. */}

### What the project declares for a write

The project selects `write.collections`, a Create input schema, an Update input schema, and a
`bindingTransforms` entry for each enabled write binding.
A collection `transform` does not cover write bindings.
These transformations receive only validated domain data and produce the native route input; they are
not inferred by reversing the read projection.

A matching Consultation collection supplies the Registry, the view, and the read data schema once.
A Write-only Update supplies those facts and a `writable-read` binding.
`companionRead` is inferred when exactly one Retrieve or `writable-read` binding serves the record
type, and is required only when that choice is ambiguous.
A `writable-read` binding that no Update names is refused by check and at load.
Both arrangements expose one companion Retrieve path, not a second writable-record resource.

The companion read must acquire its body and native validator under the same authoritative source
evaluation and source access context that the mutation uses.
The facade seals the native validator as authenticated opaque state.
The state is bound to the Registry, Collection, Record, view, and a closure of these:

- The served record shape: the record schema, item projection, output transformation, and response
  shape.
- The companion read's route: its steps, the direct routes they call, and the pinned digests of the
  scripts they name.
- The pack's code maps.
- The configured source endpoints.

Changing any of these invalidates outstanding ETags.
Access, listener, audit, and retention settings stay outside the closure, so admitting a client or
rotating OIDC configuration keeps outstanding ETags valid.

Fixed Write deployments supply the existing 32-byte `cursorKeyRef`.
A separately derived key and nonce domain protect guards, and previous-key opening supports rotation.
The public tag reveals equality, not encoded native values.
Native conditions can be opaque revision tokens rather than HTTP ETags; their strength comes from the
source compare-and-commit guarantee.
The pack validates any source-specific syntax.
A native condition over 128 bytes is outside this initial bounded profile.
The receipt and a later companion GET share an ETag only while the source guard state, read currency,
and effective context remain identical.

{/* Evidence: crates/registry-adapter/src/govstack/write/metadata.rs selected_companion_read;
    crates/registry-adapter-core/src/write.rs;
    crates/registry-adapter/tests/govstack_breg_write.rs
    maintained_breg_pack_and_project_declare_the_exact_single_record_guarantees. */}

{/* TODO[evidence]: no test names the closure of the sealed validator (which settings invalidate an
    ETag and which do not), the 32-byte key, or the 128 byte native condition limit. */}

### What the pack declares for a write

The reusable source route declares `writeSupport`.
Its value is `create-one` for a source-assigned Create or `conditional-update-one` for a strong atomic
conditional Update, each with its exact keyed `replayWindowSeconds`.
This explicit declaration is a source-author obligation; parsing the pack does not establish it.

The initial execution plan admits deterministic preparation and one source-idempotent HTTP POST inside
an idempotent consumer.
A source pack can normalise a known native rejection through a pure, terminal `onException` predicate
and a typed outcome:

- Not found maps to 404.
- Invalid domain input maps to 422.
- A source rejection of the generated request maps to 502.

These settle without reissuing a mutation.
Unknown delivery or unclassified source outcomes remain recoverable.

Native source keys include the trusted caller, logical deployment, method, and target, so clients
sharing a source service credential cannot collide on a raw key.
They also include a random generation drawn when the claim is inserted.
Every resend of one claim repeats its native key, and a key reused after the replay window is processed
as a new request under a new native key.

The host retains status, exact body, optional `Content-Type`, `Location`, and `ETag` together with the
terminal audit transaction.
A retry rechecks current facade authorisation; canonical JSON, method, URI, media type, and `If-Match`
determine request equality.
It preserves the original Problem body while generating per-attempt trace headers.
A matching in-flight request returns 409 and a changed fingerprint returns 422.
The configured facade response-retention window cannot exceed the declared native replay window.

Capability discovery publishes the deployment's response retention as `write.idempotencyReplayWindow`
(integer seconds) on every Create and Update entry, and the generated OpenAPI describes the member in
the capability schema.
The value is computed from runtime policy; it is not repeated in the project or in the generated
OpenAPI, which compiles from the authored project alone.
After the window a reused key is processed as a new request.
The separate external-gateway effective contract keeps its read-only scope; GovStack Write discovery
comes from the canonical capability endpoint and generated OpenAPI.
No domain request payload is persisted to recover an uncertain source send, so the client must resubmit
the same request and the source can return its original receipt.

{/* Evidence: crates/registry-adapter/tests/govstack_write_replay.rs
    fixed_write_replay_normalizes_native_404_without_source_detail,
    fixed_write_replay_normalizes_native_422_as_invalid_content,
    fixed_write_replay_maps_native_shape_rejection_to_bad_gateway;
    crates/registry-adapter/tests/govstack_breg_write.rs
    a_key_reused_after_the_replay_window_is_a_new_write_at_the_source,
    fixed_write_stays_out_of_the_read_only_external_effective_contract,
    assert_derived_source_key;
    crates/registry-adapter-core/src/pack.rs. */}

### The BReg source

The [BReg HTTP example](https://github.com/registrystack/registry-stack/tree/main/products/adapter/examples/breg-govstack)
supplies explicit schemas and transformations for a flat contact payload, using native server
identifiers, batch receipts, and atomic source preconditions.
The source pack stays ordinary HTTP and introduces no BReg runtime or client
dependency into the Adapter engine or facade.

### What a source must offer to back a write

A source can back Create and Update only if it offers all three of the following.
The pack declares them in `writeSupport`, and the route shape admitted for the resend (one POST with a
fixed URI, no query parameters, and no endpoint request headers) exists to protect them.

- Replay safety: a repeated request carrying the same derived key (key-based replay) or the same
  identity (identity-based replay) returns the original outcome and never a second effect, for at
  least the deployment's response retention.
- An atomic conditional update: the source compares a bounded validator (at most 128 bytes) and
  commits in one step.
  A read followed by a timestamp comparison does not qualify.
- A receipt: the source returns the assigned identifier and the new validator for the write it
  performed, so the facade can answer 201 or 204 without a second read.

BReg is the one maintained source that meets all three, which is why `breg-records` is the only Write
pack.

DHIS2 does not, for three reasons, so DHIS2 Write is unavailable in this profile:

- Update has no atomic compare-and-commit; the maintained tracker import is an upsert with no
  precondition.
- Replay safety needs a client-supplied UID, and canonical Create forbids a client-selected
  identifier.
- It offers no readback receipt for the write it made.

Deriving the DHIS2 UID from the derived native key would make a retry of Create upsert the same
object.
That would address the replay gap only; Update and the receipt would remain open, and it is not
implemented.

`SourceReference` is refused until a selected source implements its evidence validation.
Named transitions, governed Proposals, and asynchronous Write are not supported.

{/* Evidence: crates/registry-adapter/tests/govstack_breg_write.rs
    maintained_breg_pack_and_project_declare_the_exact_single_record_guarantees;
    crates/registry-adapter/tests/postgres_dhis2_pack_write.rs. */}

## Next

- [adapter effective operation contract](../../reference/adapter-effective-contract/)
- [adapter job packs](../../configure/adapter-packs/)
- [operate the adapter](../../operate/adapter/)