# trivian-technologies/syzygy-rosetta-originbase architecture

> Architecture diagram of the GitHub repository trivian-technologies/syzygy-rosetta-originbase, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/trivian-technologies/syzygy-rosetta-originbase
- Repository: https://github.com/trivian-technologies/syzygy-rosetta-originbase

## Overview

1. **Overall shape**
   - This repo is a small Python 3.11 FastAPI service that acts as an AI governance middleware.
   - Its core job is to take an `input` plus optional `context`, run it through a deterministic policy/risk pipeline, and return a decision: `allow`, `rewrite`, or `escalate`.

2. **Primary runtime boundary**
   - The main deployment unit is the API process started from `app.py` or `run_api.py`.
   - The service is containerized with a `Dockerfile`, exposed on port 8000, and intended to be called by upstream AI systems rather than by end users directly.

3. **Request/response flow**
   - The central ingress is `POST /evaluate`.
   - That request is parsed, normalized, scored, and then converted into a fixed response shape with fields like `decision`, `risk_score`, `confidence`, `violations`, `rewrite`, `reasoning`, `field_notes`, and `timestamp`.
   - A successful evaluation also appends an audit entry to `logs/evaluations.json`.

4. **Governance engine**
   - `core/reflex.py` appears to be the orchestration layer for the evaluation pipeline.
   - It combines multiple stages: input parsing, structural analysis, safety tagging, policy matching, composite risk scoring, thresholding, and response assembly.
   - This is the main architectural center of the repo.

5. **Safety and policy subsystems**
   - `safety_layer.py` performs pre-classification and tags patterns such as authority, manipulation, dependency, and escalation.
   - `config/policy_rules.json` provides deterministic, industry-specific policy rules for sectors like finance, healthcare, and general use.
   - These rules act as hard or semi-hard risk floors before final decisioning.

6. **Risk scoring subsystem**
   - `core/risk_scoring.py` contains the composite scorer logic.
   - The README describes three scoring contributors: keyword-based scoring, feature-based scoring, and an optional LLM-based scorer.
   - `core/resonators_mock.py` suggests the project includes mock or placeholder components for some of these scoring/resonance behaviors.

7. **Domain constants and invariants**
   - `core/constants.py` and `core/invariants.json` define shared thresholds, fixed labels, or governance assumptions used by the evaluation engine.
   - These files likely keep policy logic and response semantics consistent across the service and tests.

8. **Audit and persistence**
   - The only persistent runtime artifact visible in the repo is `logs/evaluations.json`.
   - This file is append-only from the app’s perspective and functions as the audit trail for every evaluation request.
   - There is no evidence of a database or queue; persistence appears intentionally lightweight and file-based.

9. **External dependency boundary**
   - The repo is provider-agnostic by default, but the README mentions an optional Anthropic-backed LLM scorer activated through `ANTHROPIC_API_KEY`.
   - That means the architecture has a clean local-first path, with an optional external inference dependency that increases scorer sophistication without changing the API contract.

10. **Testing boundary**
   - `tests/test_evaluate.py` and `tests/test_healthz.py` cover the public API behavior, decision paths, schema validation, and health endpoint behavior.
   - This suggests the externally observable contract is tightly tested, while internal scoring/policy details remain implementation concerns.

11. **Developer and example surface**
   - `example/basic_usage.py` provides a minimal client-side integration example.
   - `docs/demo_checklist.md` and the PDF documentation indicate the repo is meant to be demoed as a governance product, not just run as a library.

12. **How to draw the architecture**
   - The key diagram should show an inbound AI output/request entering the FastAPI service, flowing through policy rules, safety tagging, and composite risk scoring, then exiting as a decision response.
   - A side path should show audit logging to `logs/evaluations.json`.
   - A dashed optional path should show the external LLM scorer, and a separate config boundary should show `policy_rules.json` and invariants/constants feeding the engine.

Main entry points: [`syzygy-rosetta/core/reflex.py`](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/reflex.py) (Reflex), [`syzygy-rosetta/app.py`](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/app.py) (App), [`syzygy-rosetta/core/risk_scoring.py`](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/risk_scoring.py) (Risk scoring), [`syzygy-rosetta/safety_layer.py`](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/safety_layer.py) (Safety)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_app_py["App<br/>[app.py]"]
  node_run_api_py["Run API<br/>launcher<br/>[run_api.py]"]
  node_dockerfile["Dockerfile<br/>container spec"]
end

subgraph group_core["Core engine"]
  node_reflex{{"Reflex<br/>pipeline orchestrator<br/>[reflex.py]"}}
  node_safety_layer["Safety<br/>tagger<br/>[safety_layer.py]"]
  node_risk_scoring{{"Risk scoring<br/>composite scorer<br/>[risk_scoring.py]"}}
  node_resonators_mock["Mock resonators<br/>stub module<br/>[resonators_mock.py]"]
end

subgraph group_config["Policy config"]
  node_constants["Constants<br/>shared settings<br/>[constants.py]"]
  node_invariants["Invariants<br/>governance rules<br/>[invariants.json]"]
  node_policy_rules["Policy rules<br/>deterministic policy<br/>[policy_rules.json]"]
end

subgraph group_persistence["Audit trail"]
  node_evaluations_log[("Eval log<br/>audit file<br/>[evaluations.json]")]
end

subgraph group_integration["External integration"]
  node_anthropic_api(("Anthropic API<br/>optional llm"))
end

subgraph group_verification["Verification"]
  node_test_evaluate["Eval tests<br/>api tests<br/>[test_evaluate.py]"]
  node_test_healthz["Health tests<br/>endpoint tests<br/>[test_healthz.py]"]
end

subgraph group_docs["Docs and examples"]
  node_basic_usage["Usage example<br/>client example<br/>[basic_usage.py]"]
  node_demo_checklist["Demo guide<br/>demo docs<br/>[demo_checklist.md]"]
  node_readme["README<br/>overview docs<br/>[README.md]"]
end

node_run_api_py -->|"starts"| node_app_py
node_app_py -->|"POST /evaluate"| node_reflex
node_reflex -->|"tag"| node_safety_layer
node_reflex -->|"match"| node_policy_rules
node_reflex -->|"score"| node_risk_scoring
node_risk_scoring -->|"fallback"| node_resonators_mock
node_risk_scoring -.->|"optional LLM"| node_anthropic_api
node_reflex -->|"thresholds"| node_constants
node_reflex -->|"semantics"| node_invariants
node_safety_layer -->|"seed"| node_policy_rules
node_risk_scoring -->|"calibrate"| node_constants
node_risk_scoring -->|"constrain"| node_invariants
node_reflex -->|"append"| node_evaluations_log
node_app_py -->|"audit"| node_evaluations_log
node_app_py -->|"package"| node_dockerfile
node_test_evaluate -->|"covers"| node_app_py
node_test_healthz -->|"covers"| node_app_py
node_basic_usage -->|"calls"| node_app_py
node_demo_checklist -->|"supports"| node_readme

click node_app_py "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/app.py"
click node_run_api_py "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/run_api.py"
click node_reflex "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/reflex.py"
click node_safety_layer "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/safety_layer.py"
click node_risk_scoring "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/risk_scoring.py"
click node_resonators_mock "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/resonators_mock.py"
click node_constants "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/constants.py"
click node_invariants "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/invariants.json"
click node_policy_rules "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/config/policy_rules.json"
click node_evaluations_log "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/logs/evaluations.json"
click node_test_evaluate "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/tests/test_evaluate.py"
click node_test_healthz "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/tests/test_healthz.py"
click node_basic_usage "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/example/basic_usage.py"
click node_demo_checklist "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/docs/demo_checklist.md"
click node_readme "https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/README.md"
click node_dockerfile "https://github.com/trivian-technologies/syzygy-rosetta-originbase/tree/main/syzygy-rosetta/Dockerfile"

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_app_py,node_run_api_py,node_dockerfile,node_basic_usage,node_demo_checklist,node_readme toneBlue
class node_reflex,node_safety_layer,node_risk_scoring,node_resonators_mock toneAmber
class node_constants,node_invariants,node_policy_rules toneMint
class node_evaluations_log toneRose
class node_anthropic_api toneIndigo
class node_test_evaluate,node_test_healthz toneTeal
```

## Components

### Runtime

API process and startup entrypoints

- [App](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/app.py): fastapi app · Defines the API service and request handling surface · `syzygy-rosetta/app.py`
- [Run API](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/run_api.py): launcher · Process entrypoint for running the service · `syzygy-rosetta/run_api.py`
- [Dockerfile](https://github.com/trivian-technologies/syzygy-rosetta-originbase/tree/main/syzygy-rosetta/Dockerfile): container spec · Container image definition for the API service · `syzygy-rosetta/Dockerfile`

### Core engine

Governance orchestration, safety, and scoring

- [Reflex](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/reflex.py): pipeline orchestrator · Coordinates parse, analyze, score, decide, and assemble · `syzygy-rosetta/core/reflex.py`
- [Safety](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/safety_layer.py): tagger · Pre-classifies risky patterns and safety signals · `syzygy-rosetta/safety_layer.py`
- [Risk scoring](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/risk_scoring.py): composite scorer · Combines keyword, feature, and optional LLM scoring · `syzygy-rosetta/core/risk_scoring.py`
- [Mock resonators](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/resonators_mock.py): stub module · Placeholder or mock scoring/resonance behavior · `syzygy-rosetta/core/resonators_mock.py`

### Policy config

Deterministic rules and shared invariants

- [Constants](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/constants.py): shared settings · Fixed thresholds and governance labels · `syzygy-rosetta/core/constants.py`
- [Invariants](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/core/invariants.json): governance rules · Static assumptions and response semantics · `syzygy-rosetta/core/invariants.json`
- [Policy rules](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/config/policy_rules.json): deterministic policy · Industry-specific rule set for evaluation floors · `syzygy-rosetta/config/policy_rules.json`

### Audit trail

Append-only evaluation logs

- [Eval log](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/logs/evaluations.json): audit file · Append-only evaluation audit trail · `syzygy-rosetta/logs/evaluations.json`

### External integration

Optional provider-backed scoring

- **Anthropic API**: optional llm · External scorer used when enabled by API key

### Verification

Public API tests

- [Eval tests](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/tests/test_evaluate.py): api tests · Validates decisions, schema, and response behavior · `syzygy-rosetta/tests/test_evaluate.py`
- [Health tests](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/tests/test_healthz.py): endpoint tests · Validates health endpoint behavior · `syzygy-rosetta/tests/test_healthz.py`

### Docs and examples

Usage and demo surface

- [Usage example](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/example/basic_usage.py): client example · Minimal integration example for upstream callers · `syzygy-rosetta/example/basic_usage.py`
- [Demo guide](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/docs/demo_checklist.md): demo docs · Checklist for presenting the governance workflow · `syzygy-rosetta/docs/demo_checklist.md`
- [README](https://github.com/trivian-technologies/syzygy-rosetta-originbase/blob/main/syzygy-rosetta/README.md): overview docs · Repository overview and operating instructions · `syzygy-rosetta/README.md`

## Connections

- Run API → App: starts · Launches the API process
- App → Reflex: POST /evaluate · Sends incoming requests into the governance pipeline
- Reflex → Safety: tag · Derives safety signals before scoring
- Reflex → Policy rules: match · Applies deterministic policy floors and sector rules
- Reflex → Risk scoring: score · Computes composite risk and confidence
- Risk scoring → Mock resonators: fallback · Uses mock resonance behavior where applicable
- Risk scoring → Anthropic API: optional LLM · Delegates to external scorer when configured
- Reflex → Constants: thresholds · Reads shared decision thresholds and labels
- Reflex → Invariants: semantics · Uses governance invariants for response assembly
- Safety → Policy rules: seed · Feeds tagged risk patterns into rule evaluation
- Risk scoring → Constants: calibrate · Uses shared scoring constants and cutoffs
- Risk scoring → Invariants: constrain · Conforms to fixed scoring semantics
- Reflex → Eval log: append · Writes audit entry after evaluation
- App → Eval log: audit · Exposes the persisted evaluation trail indirectly through the pipeline
- App → Dockerfile: package · Runs inside the containerized deployment unit
- Eval tests → App: covers · Exercises the evaluation API contract
- Health tests → App: covers · Exercises the health endpoint contract
- Usage example → App: calls · Demonstrates client-side integration
- Demo guide → README: supports · Guides demo and walkthrough usage
