# stavomidnite661/sovr-protocol architecture

> Architecture diagram of the GitHub repository stavomidnite661/sovr-protocol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stavomidnite661/sovr-protocol
- Repository: https://github.com/stavomidnite661/sovr-protocol

## Overview

#### 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: [`packages/compiler/src/pipeline/validate.ts`](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/pipeline/validate.ts) (Parse and validate), [`01_constitution.yaml`](https://github.com/stavomidnite661/sovr-protocol/blob/main/01_constitution.yaml) (Constitution), [`packages/compiler/src/generators/typescript.ts`](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/generators/typescript.ts) (Artifact generators), [`generated/manifest.yaml`](https://github.com/stavomidnite661/sovr-protocol/blob/main/generated/manifest.yaml) (Generated contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_spec["Protocol Specification"]
  node_manifest["Protocol manifest"]
  node_constitution["Constitution<br/>governance spec"]
  node_vocabulary["Domain command-event model<br/>canonical specs"]
  node_financial_domains["Financial authorities<br/>domain specs<br/>[ledger.yaml]"]
  node_control_domains["Identity and policy domains<br/>domain specs<br/>[identity.yaml]"]
  node_domain_contracts["Domain contracts<br/>dependency rules"]
  node_execution_specs["Execution gate specs<br/>state and security specs"]
  node_projection_spec["Projection rules<br/>read model spec"]
  node_hybrid_boundary["External settlement boundary<br/>integration spec"]
end

subgraph group_compiler["Compiler &amp; Generated Contract"]
  node_compiler_cli["Compiler CLI<br/>TypeScript entry point<br/>[cli.ts]"]
  node_parse_validate["Parse and validate<br/>compiler pipeline<br/>[validate.ts]"]
  node_ir_builder["Intermediate representation<br/>compiler IR<br/>[builder.ts]"]
  node_generators["Artifact generators<br/>compiler generators<br/>[typescript.ts]"]
  node_generated_contract["Generated contract<br/>committed artifacts<br/>[manifest.yaml]"]
end

subgraph group_runtime["Boot &amp; Runtime"]
  node_boot{{"Trust bootloader<br/>boot pipeline<br/>[bootloader.ts]"}}
  node_execution_modules["Generated execution gates<br/>execution modules"]
  node_runtime_boundary["Runtime integration boundary<br/>runtime package<br/>[boundary.ts]"]
  node_sdk["Runtime SDK client<br/>client boundary<br/>[client.ts]"]
end

subgraph group_assurance["Governance &amp; Release"]
  node_certification["Trust and production gates<br/>certification evidence"]
  node_release_ci["Release CI<br/>release control<br/>[ci-production.yml]"]
end

node_manifest -->|"declares"| node_constitution
node_constitution -->|"constrains"| node_vocabulary
node_constitution -->|"governs"| node_execution_specs
node_vocabulary -->|"defines shared model for"| node_financial_domains
node_financial_domains -->|"coupled by"| node_domain_contracts
node_control_domains -->|"supplies authorization"| node_execution_specs
node_domain_contracts -->|"validated by"| node_parse_validate
node_execution_specs -->|"validated by"| node_parse_validate
node_projection_spec -->|"generates projection contract"| node_generators
node_hybrid_boundary -->|"generates integration contract"| node_generators
node_compiler_cli -->|"runs"| node_parse_validate
node_manifest -->|"input"| node_parse_validate
node_constitution -->|"input"| node_parse_validate
node_parse_validate -->|"validated specs"| node_ir_builder
node_ir_builder -->|"IR"| node_generators
node_generators -->|"writes"| node_generated_contract
node_generated_contract -->|"provides"| node_execution_modules
node_generated_contract -->|"manifest and build evidence"| node_boot
node_boot -->|"establishes trust"| node_runtime_boundary
node_execution_modules -->|"enforces command gates"| node_runtime_boundary
node_runtime_boundary -->|"exposes to clients"| node_sdk
node_certification -->|"evidence for"| node_release_ci
node_release_ci -->|"invokes verification"| node_compiler_cli
node_release_ci -->|"requires attestation"| node_boot

click node_manifest "https://github.com/stavomidnite661/sovr-protocol/blob/main/00_protocol-manifest.yaml"
click node_constitution "https://github.com/stavomidnite661/sovr-protocol/blob/main/01_constitution.yaml"
click node_vocabulary "https://github.com/stavomidnite661/sovr-protocol/blob/main/02_domain-model.yaml"
click node_financial_domains "https://github.com/stavomidnite661/sovr-protocol/blob/main/domains/ledger.yaml"
click node_control_domains "https://github.com/stavomidnite661/sovr-protocol/blob/main/domains/identity.yaml"
click node_domain_contracts "https://github.com/stavomidnite661/sovr-protocol/blob/main/12_domain-contracts.yaml"
click node_execution_specs "https://github.com/stavomidnite661/sovr-protocol/blob/main/05_state-machines.yaml"
click node_projection_spec "https://github.com/stavomidnite661/sovr-protocol/blob/main/projection-engine.yaml"
click node_hybrid_boundary "https://github.com/stavomidnite661/sovr-protocol/blob/main/hybrid-boundary.yaml"
click node_compiler_cli "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/cli.ts"
click node_parse_validate "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/pipeline/validate.ts"
click node_ir_builder "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/ir/builder.ts"
click node_generators "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/generators/typescript.ts"
click node_generated_contract "https://github.com/stavomidnite661/sovr-protocol/blob/main/generated/manifest.yaml"
click node_boot "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/boot/bootloader.ts"
click node_execution_modules "https://github.com/stavomidnite661/sovr-protocol/blob/main/generated/src/execution/execution-context.ts"
click node_runtime_boundary "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/runtime/src/adapters/boundary.ts"
click node_sdk "https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/runtime/src/sdk/client.ts"
click node_certification "https://github.com/stavomidnite661/sovr-protocol/blob/main/certification/COMPILER_TRUST_PACKAGE.yaml"
click node_release_ci "https://github.com/stavomidnite661/sovr-protocol/blob/main/.github/workflows/ci-production.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manifest,node_constitution,node_vocabulary,node_financial_domains,node_control_domains,node_domain_contracts,node_execution_specs,node_projection_spec,node_hybrid_boundary toneBlue
class node_compiler_cli,node_parse_validate,node_ir_builder,node_generators,node_generated_contract toneAmber
class node_boot,node_execution_modules,node_runtime_boundary,node_sdk toneMint
class node_certification,node_release_ci toneRose
```

## Components

### Protocol Specification

Frozen YAML is the authoritative protocol definition.

- [Protocol manifest](https://github.com/stavomidnite661/sovr-protocol/blob/main/00_protocol-manifest.yaml): protocol manifest · `00_protocol-manifest.yaml`
- [Constitution](https://github.com/stavomidnite661/sovr-protocol/blob/main/01_constitution.yaml): governance spec · Defines non-negotiable financial and authority invariants. · `01_constitution.yaml`
- [Domain command-event model](https://github.com/stavomidnite661/sovr-protocol/blob/main/02_domain-model.yaml): canonical specs · Defines entities, commands, and immutable event envelopes. · `02_domain-model.yaml`
- [Financial authorities](https://github.com/stavomidnite661/sovr-protocol/blob/main/domains/ledger.yaml): domain specs · Vault, ledger, and treasury own value, accounting, and movement. · `domains/ledger.yaml`
- [Identity and policy domains](https://github.com/stavomidnite661/sovr-protocol/blob/main/domains/identity.yaml): domain specs · Authorize, interpret, execute, and oversee commands. · `domains/identity.yaml`
- [Domain contracts](https://github.com/stavomidnite661/sovr-protocol/blob/main/12_domain-contracts.yaml): dependency rules · `12_domain-contracts.yaml`
- [Execution gate specs](https://github.com/stavomidnite661/sovr-protocol/blob/main/05_state-machines.yaml): state and security specs · State machines, sagas, and capabilities constrain command execution. · `05_state-machines.yaml`
- [Projection rules](https://github.com/stavomidnite661/sovr-protocol/blob/main/projection-engine.yaml): read model spec · Read models are derived and non-authoritative. · `projection-engine.yaml`
- [External settlement boundary](https://github.com/stavomidnite661/sovr-protocol/blob/main/hybrid-boundary.yaml): integration spec · Defines payment rails, settlement, oracle, and regulatory boundaries. · `hybrid-boundary.yaml`

### Compiler & Generated Contract

The compiler materializes and verifies runtime artifacts.

- [Compiler CLI](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/cli.ts): TypeScript entry point · Runs compile, verify, and boot commands. · `packages/compiler/src/cli.ts`
- [Parse and validate](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/pipeline/validate.ts): compiler pipeline · `packages/compiler/src/pipeline/validate.ts`
- [Intermediate representation](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/ir/builder.ts): compiler IR · `packages/compiler/src/ir/builder.ts`
- [Artifact generators](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/generators/typescript.ts): compiler generators · Produces runtime, schema, infrastructure, and manifest contracts. · `packages/compiler/src/generators/typescript.ts`
- [Generated contract](https://github.com/stavomidnite661/sovr-protocol/blob/main/generated/manifest.yaml): committed artifacts · Includes typed APIs, OpenAPI, Prisma, and Kafka/Redis contracts. · `generated/manifest.yaml`

### Boot & Runtime

Runtime enforces trusted execution and integration boundaries.

- [Trust bootloader](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/compiler/src/boot/bootloader.ts): boot pipeline · Validates build state, initializes constitutional context, and attests boot. · `packages/compiler/src/boot/bootloader.ts`
- [Generated execution gates](https://github.com/stavomidnite661/sovr-protocol/blob/main/generated/src/execution/execution-context.ts): execution modules · Capability, policy, and execution context enforce command gates. · `generated/src/execution/execution-context.ts`
- [Runtime integration boundary](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/runtime/src/adapters/boundary.ts): runtime package · Thin adapter and execution boundary for integrations. · `packages/runtime/src/adapters/boundary.ts`
- [Runtime SDK client](https://github.com/stavomidnite661/sovr-protocol/blob/main/packages/runtime/src/sdk/client.ts): client boundary · 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](https://github.com/stavomidnite661/sovr-protocol/blob/main/certification/COMPILER_TRUST_PACKAGE.yaml): certification evidence · `certification/COMPILER_TRUST_PACKAGE.yaml`
- [Release CI](https://github.com/stavomidnite661/sovr-protocol/blob/main/.github/workflows/ci-production.yml): release control · Build and production workflows enforce release controls. · `.github/workflows/ci-production.yml`

## Connections

- 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
