This document provides a comprehensive, current-state architectural overview of the TRUSTINT system. All described components and flows have been verified through a full pipeline execution.
- Core Function: TRUSTINT is a deterministic, CLI-driven system for managing trust and entity data through a configuration-as-code approach. It ingests YAML files, validates them against strict rules, and populates a local, tamper-evident SQLite database.
- Key Principle: The architecture is founded on provenance and idempotency. All significant actions are recorded in a cryptographically chained ledger, ensuring a verifiable, immutable audit trail. The system guarantees that repeated operations with the same inputs produce the identical state.
- Primary Outputs: The system generates auditable reports (CSV, JSONL, Markdown) and compliance artifacts. Each export is bundled into a verifiable "provenance pack" containing the reports, a checksum manifest, and a link to the specific state in the ledger.
- Technology Stack: Python 3.12+ with SQLite (in WAL mode). Data definitions, rules, and configurations are managed in YAML and JSON Schema.
- Operational Status: All systems are nominal. Linting, type checks, and unit tests pass. The data pipeline (ingest, export, verify) executes successfully, confirming the system's health and readiness.
graph TD
subgraph Actors
A[Trustees]
B[Secretariat]
C[Auditors]
D[Rūnanga/Cultural Forum]
end
subgraph "TRUSTINT System (Bronze Gate)"
CLI(CLI: `trustint`)
TIS[TIS: Substrate / DB]
TIL[TIL: Lattice / Rules]
TIM[TIM: Matrices / Exports]
Ledger(Provenance Ledger)
Configs(YAML Configs)
end
B -- Manages --> Configs
B -- Runs --> CLI
CLI -- Triggers --> TIL
CLI -- Triggers --> TIS
CLI -- Triggers --> TIM
Configs -- Read by --> TIL
TIL -- Validates & Passes to --> TIS
TIS -- Appends to --> Ledger
TIS -- Is read by --> TIM
TIM -- Generates --> Exports(Exports: CSV, MD, JSONL)
Ledger -- Guarantees Integrity of --> TIS
A & D -- Consume --> Exports
C -- Audits --> Ledger
C -- Audits --> Exports
C -- Audits --> TIS
-
TIS (TRUSTINT Substrate): The data persistence layer.
- DB Schema: Defined in
schema.sql. It usesINTEGER PRIMARY KEYfor internal references andUNIQUEconstraints on natural keys (e.g.,trusts.slug) to enforce data integrity and idempotency. Foreign keys useON DELETE CASCADE. - Ingestion: The
core/substrate.py:ingest_from_configfunction reads validated data from YAML files. It usesINSERT OR IGNOREto ensure that re-running ingestion does not create duplicate records, as verified by the pipeline run. - WAL (Write-Ahead Logging): Enabled via
PRAGMA journal_mode=WALon every connection, ensuring high concurrency and durability. Checkpointing is explicitly performed on export to flush the WAL file to the main database. - FTS5: A
contentlessvirtual table (search_idx) provides full-text search capabilities. It uses theunicode61 remove_diacritics 2tokenizer for precise, accent-insensitive searching.
- DB Schema: Defined in
-
TIL (TRUSTINT Lattice): The validation and business logic layer.
- Schema Validation:
core/lattice.py:validate_allusesjsonschemato validate the structure of input YAMLs against strict, pre-defined schemas. - Business Rules: It enforces semantic rules beyond schema checks, such as ensuring every trust has at least one trustee and that "air" assets have appropriate jurisdiction and boundary descriptors.
- Schema Validation:
-
TIM (TRUSTINT Matrices): The reporting and export layer.
- Exporters:
core/matrices.pycontains functions to generate reports in various formats:export_csv,export_jsonl, andexport_markdown. These read directly from the SQLite database to produce the artifacts in thedist/directory. - Checksums: The
write_checksumsfunction generates adist/SHA256SUMSfile, a manifest of SHA256 hashes for all exported files, which is crucial for verifying the integrity of an export batch.
- Exporters:
-
Utils & Provenance:
- Provenance (
utils/provenance.py): Implements the append-only event ledger (vault/events.jsonl). Theappend_eventfunction creates HMAC-SHA256 signed entries, chaining each new event to the previous one's signature. Its integrity was confirmed by thechain-verifyscript. - Logging (
utils/logger.py): Provides structured, timestamped output for operational diagnostics, separate from the permanent provenance ledger.
- Provenance (
- Event Model: Each event in
vault/events.jsonlis a JSON object containing a UTC timestamp (ts), the previous event's signature (prev), the current event's signature (mac), and a payload describing the action (e.g.,ingest,export). - Chain-Verify Flow: The
scripts/prov_tools.py chain-verifycommand reads the ledger sequentially, recalculating the HMAC of each entry and ensuring the chain is unbroken. The successful execution of this script confirms the ledger is intact. - Export Integrity: The
dist/SHA256SUMSfile acts as a manifest for a given set of exported reports. An auditor can verify the integrity of the reports by hashing them and comparing the results to the values in the manifest. - Forensic Replay: The system state can be fully rebuilt from source. An operator can delete
vault/trustint.dband re-runmake ingest. The resulting database will be identical to the previous state, and the provenance ledger can be re-verified against it.
- Lint & Test:
make lintandmake testwere run, confirming code quality, type safety, and correctness of the logic. All checks passed. - Ingest:
make ingestwas run. Thetrustint ingestcommand initialized the database fromschema.sqland populated it from theconfig/*.yamlfiles. Idempotency was confirmed by theDB_INGEST_CONFLICT_IGNOREDlog messages. - Ledger Append (Ingest): An
ingestevent was appended tovault/events.jsonl, permanently recording the action. - Export:
make exportwas run. Thetrustint exportcommand queried the database and generatedboard_report.md,trustint_export.csv, andtrustint_export.jsonlin thedist/directory. - Ledger Append (Export):
exportandchecksumsevents were appended to the ledger. - Chain Verification:
python scripts/prov_tools.py chain-verifywas run, which validated the entire event history in the ledger, confirming no tampering occurred during the pipeline execution.
- Determinism: Given the same input configuration, the system will always produce the exact same database state and exported reports.
- Idempotency: As demonstrated by the
ingestlogs, re-running operations with the same data does not create duplicate records or alter the system state. - Tamper-Evidence: The successful
chain-verifycommand proves the HMAC-chained provenance ledger is a secure and effective mechanism for detecting unauthorized modifications. - Recovery Policy: In case of corruption, the policy is to rename the affected file (e.g.,
trustint.db->trustint.db.corrupt) and rebuild from the source configurations. Data is never silently deleted.
A trust can use the Bronze implementation today to:
- Establish a Single Source of Truth: Codify the trust's complete structure—including entities, roles, assets, and legal jurisdiction—in version-controllable YAML files.
- Generate Verifiable Board Reports: Create point-in-time reports (
dist/board_report.md) that are guaranteed to reflect the state of the underlying data, suitable for board meetings and official records. - Satisfy Audit Requirements: Provide auditors with a time-capsule of trust data, complete with a manifest of file checksums and an immutable, cryptographically-signed ledger of every action taken by the system.
- Track Key Obligations: Formally list and categorize all compliance and covenant obligations tied to the trust, providing a clear reference for trustees and administrators.