feat(backend): expand stamdata + OpenZaak-ready cases seam (WP-49)
CI / frontend (push) Successful in 2m59s
CI / backend (push) Successful in 1m27s
CI / semgrep (push) Successful in 58s
CI / e2e (push) Successful in 2m30s
CI / api-client-drift (push) Canceled after 1m14s
CI / storybook-a11y (push) Canceled after 29m8s
CI / frontend (push) Successful in 2m59s
CI / backend (push) Successful in 1m27s
CI / semgrep (push) Successful in 58s
CI / e2e (push) Successful in 2m30s
CI / api-client-drift (push) Canceled after 1m14s
CI / storybook-a11y (push) Canceled after 29m8s
Stamdata: add beroepen, opleidingen (temporal), and specialismen tables to the schema-driven catalog (zero UI code). opleidingen.beroep and specialismen.beroep both reference beroepen.code — the first stamdata->stamdata references, enforced by two new StamdataRef entries in the CI gate. OpenZaak/ZGW (WP-49, slice 1 — read-only zaken): introduce IZaakSource as the cases read seam. Default LocalZaakSource reads the local SQLite store (offline); an OpenZaakZaakSource (Zgw/ client: HS256 per-call JWT, ZGW->existing-DTO mapper, paginating HTTP source) is selected behind Zgw:Enabled (default false). The FE never changes — same ApplicationSummaryDto, no api-client drift. Unit-tested with fixtures + a stub HttpMessageHandler; no live OpenZaak needed. Docs: ADR-0005, reference/openzaak-integration.md, WP-49..52 roadmap, stamdata.md update, README index rows. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# ADR-0005 — OpenZaak (ZGW APIs) behind the BFF
|
||||
|
||||
Status: Accepted · Date: 2026-07-24
|
||||
|
||||
## Context
|
||||
|
||||
The POC serves cases (aanvragen) from a local SQLite store. To grow toward production it must
|
||||
be able to source cases from a real Dutch **Zaakgericht Werken (ZGW)** backend — **OpenZaak**,
|
||||
the VNG reference implementation. ZGW is not one API but five separate services (Zaken/ZRC,
|
||||
Documenten/DRC, Catalogi/ZTC, Besluiten/BRC, Notificaties/NRC), each on its own base URL, with
|
||||
traits that make raw responses unfit to hand to a browser:
|
||||
|
||||
- resources are identified by **full URLs**, not bare ids;
|
||||
- references between resources are **URLs into other services** (a zaak's `zaaktype` lives in
|
||||
Catalogi), so a single screen means joining across services;
|
||||
- lists use a uniform `{count,next,previous,results}` pagination envelope;
|
||||
- auth is a short-lived **HS256 JWT** signed with a client secret (no OAuth refresh), which
|
||||
OpenZaak rejects an hour past `iat`.
|
||||
|
||||
Two constraints shaped the decision: the **frontend must not change** (BFF-lite, ADR-0001 —
|
||||
the FE renders decision DTOs and never recomputes rules), and the POC must **still run fully
|
||||
offline** (no OpenZaak needed for local dev/CI).
|
||||
|
||||
The backend, however, had **no data-access abstraction** — endpoints called concrete static
|
||||
stores directly — and no outbound HTTP or JWT machinery. So there was no injection point to
|
||||
swap a data source behind.
|
||||
|
||||
## Options
|
||||
|
||||
1. **FE talks to OpenZaak directly.** Rejected: leaks ZGW shapes + the client secret to the
|
||||
browser, and contradicts BFF-lite.
|
||||
2. **Rewrite the static stores in place to call OpenZaak.** Rejected: no seam, no offline mode,
|
||||
all-or-nothing, untestable without a live server.
|
||||
3. **Introduce a data-source interface behind the existing DTO contract, select the
|
||||
implementation by config.** Chosen.
|
||||
|
||||
## Decision
|
||||
|
||||
Put the OpenZaak anti-corruption layer **in the .NET BFF**, never in the browser. Introduce a
|
||||
per-domain source interface (starting with `IZaakSource` for the cases read path) whose default
|
||||
implementation reads the local SQLite store and whose alternate implementation calls OpenZaak —
|
||||
selected by a config flag (`Zgw:Enabled`, default false). Each implementation maps into the
|
||||
**existing** wire DTO (`ApplicationSummaryDto`), so the `/api/v1` contract and the FE are
|
||||
untouched. The BFF holds the client secret and **mints a fresh JWT per outbound call**.
|
||||
|
||||
This is deliberately a **thin vertical slice** (read-only zaken, WP-49); create/documents/
|
||||
notifications follow the same seam in later slices (WP-50/51/52) rather than being scaffolded
|
||||
up front — the migration stance ADR-0001 already prescribes.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **+** The FE is production-ready as-is: swapping to OpenZaak is backend-only, behind one
|
||||
config flag, with zero DTO/api-client drift. The POC still runs offline (default = local).
|
||||
- **+** The seam is unit-testable without a live server: the JWT minter, the ZGW→DTO mapper,
|
||||
and the paginating source are all covered with fixtures + a stub `HttpMessageHandler`.
|
||||
- **+** URL-as-identity and cross-service joins are contained in one mapper; nothing downstream
|
||||
sees a ZGW shape.
|
||||
- **−** Only the cases **read** path has a source interface today; other endpoints still call
|
||||
static stores directly. Each future slice introduces its own seam as needed (not a big-bang
|
||||
repository refactor).
|
||||
- **−** `IZaakSource` is synchronous (matching the existing sync endpoint + local store), so
|
||||
`OpenZaakZaakSource` does sync-over-async; fine under ASP.NET Core (no sync-context), to be
|
||||
made async if OpenZaak becomes the default. Marked with a `ponytail:` note at the call site.
|
||||
- **Shipped with this ADR (WP-49):** `IZaakSource` + `LocalZaakSource` (default) +
|
||||
`OpenZaakZaakSource` (config-gated), the `Zgw/` client (`ZgwOptions`, `ZgwTokenProvider`,
|
||||
`ZgwZaakMapper`), and the reference guide [openzaak-integration.md](../openzaak-integration.md).
|
||||
- **Deferred:** real inbound OIDC/JWT auth (still header-stubbed), create-zaak (WP-50),
|
||||
Documenten/DRC upload + link (WP-51), Notificaties/NRC webhooks (WP-52), adding OpenZaak to
|
||||
docker-compose.
|
||||
@@ -0,0 +1,88 @@
|
||||
# OpenZaak / ZGW integration — how the BFF connects (& how to extend)
|
||||
|
||||
How the BFF sources cases from a real **OpenZaak** (ZGW APIs) while the frontend stays
|
||||
unchanged. For the _why_, see [ADR-0005](architecture/0005-openzaak-behind-bff.md); this page
|
||||
is _how the seam is built and how to add the next slice_. Built in
|
||||
[WP-49](../project/backlog/WP-49-openzaak-zaken-read-seam.md) (read-only zaken).
|
||||
|
||||
## The one rule: OpenZaak sits behind the BFF, never in the browser
|
||||
|
||||
The Angular app only ever sees the BFF's decision DTOs (BFF-lite, ADR-0001). All ZGW
|
||||
awkwardness — URL-as-identity, cross-service joins, JWT auth, pagination — is absorbed by the
|
||||
.NET BFF. Flipping the data source from local SQLite to OpenZaak is a **backend config change**
|
||||
with **zero frontend change and no api-client drift**.
|
||||
|
||||
## The seam (data source by config)
|
||||
|
||||
- `Data/IZaakSource.cs` — the cases READ interface. Returns the existing
|
||||
`ApplicationSummaryDto`, so each implementation owns its own mapping.
|
||||
- `Data/LocalZaakSource.cs` — **default**; reads the local SQLite `ApplicationStore`
|
||||
(offline, unchanged behaviour).
|
||||
- `Zgw/OpenZaakZaakSource.cs` — the OpenZaak client; selected only when `Zgw:Enabled=true`.
|
||||
- Wiring (`Program.cs`): `if (Zgw:Enabled) AddHttpClient<IZaakSource, OpenZaakZaakSource>()
|
||||
else AddSingleton<IZaakSource, LocalZaakSource>()`. The `/admin/cases` endpoint resolves
|
||||
`IZaakSource` from DI — routes + DTOs untouched.
|
||||
|
||||
## The ZGW client (`backend/src/BigRegister.Api/Zgw/`)
|
||||
|
||||
- `ZgwOptions.cs` — bound from the `Zgw` appsettings section: `Enabled`, per-service base URLs
|
||||
(`ZrcBaseUrl`, `ZtcBaseUrl`), `ClientId`, `Secret`, `UserId`, `UserRepresentation`. The five
|
||||
ZGW APIs are separate base URLs; slice 1 needs only Zaken (ZRC) + Catalogi (ZTC).
|
||||
- `ZgwTokenProvider.cs` — mints an **HS256 JWT per call** (`iss`/`client_id`/`iat`/`user_id`/
|
||||
`user_representation`). No refresh flow — OpenZaak expires tokens 1h past `iat`, so per-call
|
||||
minting is the recommended pattern. Hand-rolled (no `Microsoft.IdentityModel.*` dependency).
|
||||
- `ZgwZaakMapper.cs` — the anti-corruption map: ZGW Zaak → `ApplicationSummaryDto`. This is
|
||||
where **URL identity** becomes the trailing uuid and the **zaaktype URL** is resolved to a
|
||||
human label (the cross-service join).
|
||||
- `OpenZaakZaakSource.cs` — follows `{count,next,previous,results}` pagination, resolves +
|
||||
caches zaaktype labels, attaches `Authorization: Bearer <jwt>`.
|
||||
|
||||
## The five ZGW APIs (context for later slices)
|
||||
|
||||
| API | Component | Used by |
|
||||
| ------------ | --------- | --------------------------------------------------- |
|
||||
| Zaken | ZRC | slice 1 (read), WP-50 (create) |
|
||||
| Catalogi | ZTC | slice 1 (zaaktype label; also type URLs for create) |
|
||||
| Documenten | DRC | WP-51 (upload + zaak↔document link) |
|
||||
| Besluiten | BRC | later (formal decisions) |
|
||||
| Notificaties | NRC | WP-52 (live status via webhooks, not polling) |
|
||||
|
||||
## How to add the next slice
|
||||
|
||||
1. **Read** — extend `IZaakSource` (or add a sibling interface, e.g. `IDocumentSource`) with
|
||||
the new operation; implement it on both `LocalZaakSource` and the OpenZaak source. Keep the
|
||||
return type the existing DTO so the FE never changes.
|
||||
2. **Write** (create-zaak, WP-50) — a create needs a `zaaktype` URL from Catalogi (OpenZaak
|
||||
validates it by fetching), then usually a follow-up `status` + `rol`. Route it through the
|
||||
existing submit/mutation seam.
|
||||
3. **Enforce server-side** for anything the FE gates — a config value the FE echoes is never
|
||||
the authority (ADR-0001).
|
||||
|
||||
## Coupling
|
||||
|
||||
Low and one-directional. Consumer coupling is near zero — `IZaakSource` is injected at one
|
||||
endpoint, and the FE is fully decoupled by the DTO. The producer side is contained in `Zgw/`:
|
||||
add a slice by adding a source method + a mapper case, not by touching the FE or the contract.
|
||||
Watch the **sync-over-async** `ponytail:` note in `OpenZaakZaakSource` — make the cases read
|
||||
path async if OpenZaak becomes the default.
|
||||
|
||||
## Config
|
||||
|
||||
```jsonc
|
||||
// appsettings.json — off by default (POC runs offline on the local store)
|
||||
"Zgw": {
|
||||
"Enabled": true,
|
||||
"ZrcBaseUrl": "https://open-zaak.example/zaken/api/v1",
|
||||
"ZtcBaseUrl": "https://open-zaak.example/catalogi/api/v1",
|
||||
"ClientId": "big-register", "Secret": "<from a secret store>",
|
||||
"UserId": "<session user>", "UserRepresentation": "<session name>"
|
||||
}
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [ADR-0005 — OpenZaak behind the BFF](architecture/0005-openzaak-behind-bff.md) — the decision.
|
||||
- [ADR-0001 — BFF-lite + decision DTOs](architecture/0001-bff-lite-decision-dtos.md) — why the FE doesn't change.
|
||||
- [WP-49](../project/backlog/WP-49-openzaak-zaken-read-seam.md) (this), WP-50/51/52 (later slices).
|
||||
- `backend/src/BigRegister.Api/Zgw/` — the client; `Data/IZaakSource.cs` — the seam.
|
||||
- [ZGW standard (VNG)](https://vng-realisatie.github.io/gemma-zaken/) · [OpenZaak auth docs](https://open-zaak.readthedocs.io/en/stable/client-development/authentication.html).
|
||||
@@ -6,6 +6,11 @@ build**, not a runtime-editable database. For the _why_, see
|
||||
[ADR-0004 — Stamdata as code](architecture/0004-stamdata-as-code.md); this page is _how the
|
||||
code is laid out and how to add a table without coupling_. Built in WP-29, hardened in WP-48.
|
||||
|
||||
Tables today: `professions` (opleiding-program → beroep), `beroepen` (the BIG professions master
|
||||
list), `opleidingen` (temporal; `beroep` → `beroepen.code`) and `specialismen` (`beroep` →
|
||||
`beroepen.code`). The last two are **stamdata → stamdata** references — one table keyed on by two
|
||||
others — enforced by the CI gate below.
|
||||
|
||||
## The one rule that shapes everything: no runtime write path
|
||||
|
||||
The catalog is the source of truth and lives in code. The admin editor **downloads** an
|
||||
@@ -50,8 +55,11 @@ component**. This is the payoff of the schema-driven design.
|
||||
|
||||
`backend/tests/BigRegister.Tests/StamdataValidationTests.cs`. `Every_catalog_table_is_valid`
|
||||
covers every registered table generically; the `StamdataRef` list catches dangling
|
||||
references (today: `Diploma.Opleiding → professions.program`). A bad edit, an orphaning
|
||||
delete, or a premature expire **fails the PR build** — never prod.
|
||||
references — both seed → stamdata (`Diploma.Opleiding → professions.program`) and
|
||||
stamdata → stamdata (`Opleiding.beroep → beroepen.code`, `Specialisme.beroep →
|
||||
beroepen.code`). A bad edit, an orphaning delete, or a premature expire **fails the PR
|
||||
build** — never prod. Adding a cross-table FK is one `StamdataRef` entry: the referencing
|
||||
keys + a resolver against the target table's (valid-today) keys.
|
||||
|
||||
## Coupling
|
||||
|
||||
|
||||
Reference in New Issue
Block a user