Corpus Library

The shared Rust crate for loading, parsing, and validating the YAML regulation corpus.

The corpus library is a shared Rust crate for loading and managing the regulation corpus. It abstracts over multiple source types (local filesystem and GitHub repositories) and handles YAML parsing, registry management, and scope checks on what each source provides.

Overview

  • Language: Rust
  • Location: packages/corpus/
  • Type: Library crate (used by other packages)

What it does

The corpus library provides a single API for loading ruleworks regardless of where they are stored. It reads the corpus-registry.yaml manifest, authenticates with remote sources, fetches YAML files, and parses them into typed Rust structures.

Other packages use it:

  • The editor-api uses it to serve ruleworks to the frontend
  • The admin uses it to proxy corpus data to the dashboard
  • The pipeline and the poc-portal use it as well

The engine does not depend on it. The engine reads ruleworks through regelrecht-law-model and gets them handed in by its caller.

Key modules

ModulePurpose
registry.rsCorpusRegistry - loads corpus-registry.yaml, merges local overrides
source_map.rsSourceMap - maps law IDs to parsed ruleworks
models.rsSource, SourceType (Local/GitHub), RegistryManifest
github.rsGitHubFetcher - fetches YAML via GitHub API (feature-gated)
validation.rsScope check: a ScopeWarning for each law that falls outside the jurisdictional scope its source declares
auth.rsToken management for private repositories
client.rsCorpusClient - higher-level read/write access used by editor-api
backend.rsThe RepoBackend trait and the factory that picks an implementation per source
github_api_backend.rsAPI-only backend: no local clone, reads through the Contents API, writes buffered in memory and flushed as one PUT or DELETE per file
implements_index.rsReads the committed implements-index, the precomputed artefact that replaces a full-corpus scan for IoC resolution
timing.rsRequest-scoped phase timings, surfaced as a Server-Timing header and as tracing spans
annotation_schema.rs, dto.rs, config.rs, error.rsAnnotation schema validation (JSON schema, behind the optional annotation-validation feature), transfer types, deployment config, and error types
bin/implements_indexer.rsThe implements-indexer binary that generates the committed implements-index from a corpus checkout

Usage

use regelrecht_corpus::CorpusRegistry; use std::path::Path; // load(manifest_path, local_override_path): the second argument merges a // corpus-registry.local.yaml override when present. let registry = CorpusRegistry::load(Path::new("corpus-registry.yaml"), None)?; // Local sources only; GitHub sources are skipped. `today` is the date // each law's versions are collapsed against. let local = registry.load_local_sources("2026-01-01")?; // index_all_sources_async includes GitHub sources. For those it builds a // metadata-only index; law bodies are fetched lazily on first read. Pass the auth file when // private repositories need a token, or None when all sources are public. // Sources that fail to enumerate are returned next to the map, not as an error. let (source_map, failures) = registry .index_all_sources_async(Some(Path::new("corpus-auth.yaml")), "2026-01-01") .await?; let law = source_map.get_law("wet_op_de_zorgtoeslag");

The github feature flag (on by default) enables remote fetching from GitHub repositories, including load_favorites_async, which fetches only a given set of law IDs. Without it, only local filesystem sources are available.

The HTTP calls themselves are not made here. Every GitHub REST request goes through packages/github/ (crate regelrecht-github), a small hand-written client covering only the endpoints in use (trees, contents, refs, compare, pulls and archive downloads), with ETag and rate-limit state kept in one place. The editor API calls it directly as well; the corpus library keeps the domain layer on top.

Further reading

RegelRecht

An exploration into transparent, executable legislation, and one of the three projects in the starting selection of the Nederlandse Digitale Dienst.

Links

GitHub repository
How it works
Stay informed
Roadmap (Dutch)
Documentation
Research

Contact

regelrecht@minbzk.nl

Part of

Nederlandse Digitale Dienst
Ministry of Economic Affairs and Climate Policy