How stavomidnite661/sovr-protocol works
Purpose and Entry Points
SOVR is a spec-first, event-sourced financial protocol: frozen YAML defines governance, financial domains, execution rules, and integration boundaries; a TypeScript compiler materializes selected runtime artifacts. Primary entry points are 00_protocol-manifest.yaml (protocol/layer manifest), compiler.yaml (compiler contract), and packages/compiler/src/cli.ts (compile, verify, boot commands). The example client boundary is packages/runtime/src/sdk/client.ts.
Constitutional Specification Layer
Protocol authority flows from immutable governance and shared vocabulary into executable constraints. 01_constitution.yaml defines invariants such as event immutability, double-entry integrity, authority gating, and agent restrictions. 02_domain-model.yaml, 03_command-catalog.yaml, and 04_event-catalog.yaml define entities, commands, and immutable event envelopes. This is the primary source-of-truth boundary: runtime and generated output should derive from these files rather than independently define finance behavior.
Domain and Financial Control Model
Nine domain specifications partition responsibility: custody/value (domains/vault.yaml), immutable accounting (domains/ledger.yaml), and controlled value movement (domains/treasury.yaml) are core financial authorities. Identity, policy, intent, agents, payments, and governance provide authorization, interpretation, execution, and oversight through domains/identity.yaml, domains/policy.yaml, domains/payment.yaml, and related domain files. Cross-domain dependencies and coupling rules are centralized in 12_domain-contracts.yaml and DEPENDENCY_GRAPH.yaml.
Command-to-Event Execution Boundary
Commands are intended to pass identity, capability, scope, policy, constitutional, execution, and publication gates before producing events. State validity and distributed failure handling are specified in 05_state-machines.yaml and 09_saga-orchestration.yaml; capability authorization originates in 08_security-capabilities.yaml. Generated execution-facing modules include generated/src/execution/execution-context.ts, generated/src/policy/engine.ts, and generated/src/security/capability-engine.ts. The repository’s runtime package exposes a thinner integration boundary via packages/runtime/src/execution/index.ts and packages/runtime/src/adapters/boundary.ts.
Compiler Pipeline and Generated Contract
@sovr/compiler parses YAML, validates it, builds an intermediate representation, generates artifacts, and supports reproducibility verification. Core stages reside in packages/compiler/src/pipeline/parse.ts, packages/compiler/src/pipeline/validate.ts, and packages/compiler/src/ir/builder.ts; generators are under packages/compiler/src/generators/. Compiler behavior is governed by compiler/PASS_REGISTRY.yaml and compiler/GENERATOR_REGISTRY.yaml. Outputs committed under generated/ include OpenAPI, Prisma schema, Kafka/Redis configuration, typed commands/events, protocol manifests, and boot attestation artifacts.
Boot, Runtime Trust, and Read Models
Boot is a trust gate, not an application server entry point: packages/compiler/src/boot/bootloader.ts, packages/compiler/src/boot/kernel-init.ts, and packages/compiler/src/boot/post.ts validate manifest/build state, initialize constitutional context, and emit attestations. Outputs include generated/boot-manifest.json and generated/boot-attestation.json. Event-derived read-model rules are specified in projection-engine.yaml; projections are non-authoritative relative to the event log. The runtime SDK should verify the expected build hash before financial command use.
Infrastructure and External Boundaries
Material runtime technologies declared by the protocol are Node.js 20+ and TypeScript, with intended Fastify, Prisma/PostgreSQL, Kafka, Redis, and Temporal integrations. Generated infrastructure contracts are generated/prisma/schema.prisma, generated/config/kafka/topics.yaml, and generated/config/redis/streams.yaml. External execution boundaries—payment rails, blockchain/hybrid settlement, oracles, and regulatory interfaces—are defined by hybrid-boundary.yaml and the payment domain. Deployment evidence is limited in the active tree to deployment/docker-compose.production.yml; broader Kubernetes assets are archived under _archive/.
Assurance, Governance, and Release Control
Certification and governance are first-class repository artifacts rather than runtime services. certification/COMPILER_TRUST_PACKAGE.yaml, certification/RUNTIME_AUTHORITY_BOUNDARY.yaml, and certification/PRODUCTION_GATE.yaml capture evidence and operational gates. Protocol evolution and canonical snapshots are controlled through governance/ and snapshots/; CI invokes the build/release controls in .github/workflows/ci.yml and .github/workflows/ci-production.yml.
Main entry points: validate.ts Parse and validate · 01_constitution.yaml Constitution · typescript.ts Artifact generators · manifest.yaml Generated contract
Components 20
Protocol Specification
Frozen YAML is the authoritative protocol definition.
- Protocol manifest
00_protocol-manifest.yaml - Constitution · Defines non-negotiable financial and authority invariants.
01_constitution.yaml - Domain command-event model · Defines entities, commands, and immutable event envelopes.
02_domain-model.yaml - Financial authorities · Vault, ledger, and treasury own value, accounting, and movement.
domains/ledger.yaml - Identity and policy domains · Authorize, interpret, execute, and oversee commands.
domains/identity.yaml - Domain contracts
12_domain-contracts.yaml - Execution gate specs · State machines, sagas, and capabilities constrain command execution.
05_state-machines.yaml - Projection rules · Read models are derived and non-authoritative.
projection-engine.yaml - External settlement boundary · Defines payment rails, settlement, oracle, and regulatory boundaries.
hybrid-boundary.yaml
Compiler & Generated Contract
The compiler materializes and verifies runtime artifacts.
- Compiler CLI · Runs compile, verify, and boot commands.
packages/compiler/src/cli.ts - Parse and validate
packages/compiler/src/pipeline/validate.ts - Intermediate representation
packages/compiler/src/ir/builder.ts - Artifact generators · Produces runtime, schema, infrastructure, and manifest contracts.
packages/compiler/src/generators/typescript.ts - Generated contract · Includes typed APIs, OpenAPI, Prisma, and Kafka/Redis contracts.
generated/manifest.yaml
Boot & Runtime
Runtime enforces trusted execution and integration boundaries.
- Trust bootloader · Validates build state, initializes constitutional context, and attests boot.
packages/compiler/src/boot/bootloader.ts - Generated execution gates · Capability, policy, and execution context enforce command gates.
generated/src/execution/execution-context.ts - Runtime integration boundary · Thin adapter and execution boundary for integrations.
packages/runtime/src/adapters/boundary.ts - Runtime SDK client · Verifies expected build hash before financial command use.
packages/runtime/src/sdk/client.ts
Governance & Release
Certification and CI control protocol evolution and release.
- Trust and production gates
certification/COMPILER_TRUST_PACKAGE.yaml - Release CI · Build and production workflows enforce release controls.
.github/workflows/ci-production.yml
Connections 24
- Protocol manifest → Constitution: declares
- Constitution → Domain command-event model: constrains
- Constitution → Execution gate specs: governs
- Domain command-event model → Financial authorities: defines shared model for
- Financial authorities → Domain contracts: coupled by
- Identity and policy domains → Execution gate specs: supplies authorization
- Domain contracts → Parse and validate: validated by
- Execution gate specs → Parse and validate: validated by
- Projection rules → Artifact generators: generates projection contract
- External settlement boundary → Artifact generators: generates integration contract
- Compiler CLI → Parse and validate: runs
- Protocol manifest → Parse and validate: input
- Constitution → Parse and validate: input
- Parse and validate → Intermediate representation: validated specs
- Intermediate representation → Artifact generators: IR
- Artifact generators → Generated contract: writes
- Generated contract → Generated execution gates: provides
- Generated contract → Trust bootloader: manifest and build evidence
- Trust bootloader → Runtime integration boundary: establishes trust
- Generated execution gates → Runtime integration boundary: enforces command gates
- Runtime integration boundary → Runtime SDK client: exposes to clients
- Trust and production gates → Release CI: evidence for
- Release CI → Compiler CLI: invokes verification
- Release CI → Trust bootloader: requires attestation