# daiss216/safety-testing-prototype architecture

> Architecture diagram of the GitHub repository daiss216/safety-testing-prototype, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/daiss216/safety-testing-prototype
- Repository: https://github.com/daiss216/safety-testing-prototype

## Overview

Bayora is a secure adversarial AI testing broker: operators create evaluations and issue separate team tokens; red and blue teams submit sealed artifacts; red can trigger model evaluation; and users can inspect findings and a tamper-evident ledger. The broker mediates access and worker calls, while isolated workers seal or score data. The excerpts show the red-to-gateway-to-blue sequence and key broker operations; some broker routing and gateway internals are omitted, so uncertain connections are not asserted.

Main entry points: [`backend/red_worker.py`](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/red_worker.py) (Red Worker), [`backend/blue_worker.py`](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/blue_worker.py) (Blue Worker), [`backend/main.py`](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/main.py) (Broker API), [`backend/database.py`](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/database.py) (SQL Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_console["Team Console"]
  node_ui["Evaluation Console<br/>[App.jsx]"]
end

subgraph group_broker["Evaluation Broker"]
  node_broker_api["Broker API<br/>[main.py]"]
end

subgraph group_workers["Isolated Workers"]
  node_red["Red Worker<br/>[red_worker.py]"]
  node_blue["Blue Worker<br/>[blue_worker.py]"]
  node_gateway["Model Gateway<br/>[model_gateway.py]"]
  node_policy["Reply Scoring<br/>[policy.py]"]
end

subgraph group_security["Storage and Integrity"]
  node_db[("SQL Database<br/>[database.py]")]
  node_models["Evaluation Records<br/>[models.py]"]
  node_keys["Tenant Key Derivation<br/>[keys.py]"]
  node_auth["Internal Auth<br/>[internal.py]"]
  node_audit["Signed Ledger<br/>[audit.py]"]
end

node_user(("Operator or Team"))

node_user -->|"uses"| node_ui
node_ui -->|"calls API"| node_broker_api
node_broker_api -->|"seals payload"| node_red
node_red -->|"requests inference"| node_gateway
node_red -->|"submits reply"| node_blue
node_blue -->|"scores reply"| node_policy
node_broker_api -->|"reads and writes"| node_db
node_red -->|"reads payloads"| node_db
node_blue -->|"reads payloads"| node_db
node_models -->|"uses ORM base"| node_db
node_red -->|"derives keys"| node_keys
node_blue -->|"derives keys"| node_keys
node_red -->|"checks internal access"| node_auth
node_blue -->|"checks internal access"| node_auth
node_broker_api -->|"creates and verifies entries"| node_audit

click node_ui "https://github.com/daiss216/safety-testing-prototype/blob/main/frontend/src/App.jsx"
click node_broker_api "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/main.py"
click node_red "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/red_worker.py"
click node_blue "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/blue_worker.py"
click node_gateway "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/model_gateway.py"
click node_policy "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/policy.py"
click node_db "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/database.py"
click node_models "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/models.py"
click node_keys "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/keys.py"
click node_auth "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/internal.py"
click node_audit "https://github.com/daiss216/safety-testing-prototype/blob/main/backend/audit.py"

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_ui toneBlue
class node_broker_api toneAmber
class node_red,node_blue,node_gateway,node_policy toneMint
class node_db,node_models,node_keys,node_auth,node_audit toneRose
class node_user toneIndigo
```

## Components

### Team Console

- [Evaluation Console](https://github.com/daiss216/safety-testing-prototype/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`

### Evaluation Broker

- [Broker API](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/main.py): `backend/main.py`

### Isolated Workers

- [Red Worker](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/red_worker.py): `backend/red_worker.py`
- [Blue Worker](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/blue_worker.py): `backend/blue_worker.py`
- [Model Gateway](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/model_gateway.py): `backend/model_gateway.py`
- [Reply Scoring](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/policy.py): `backend/policy.py`

### Storage and Integrity

- [SQL Database](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/database.py): `backend/database.py`
- [Evaluation Records](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/models.py): `backend/models.py`
- [Tenant Key Derivation](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/keys.py): `backend/keys.py`
- [Internal Auth](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/internal.py): `backend/internal.py`
- [Signed Ledger](https://github.com/daiss216/safety-testing-prototype/blob/main/backend/audit.py): `backend/audit.py`

### Other components

- **Operator or Team**

## Connections

- Operator or Team → Evaluation Console: uses (evidence: `frontend/src/App.jsx`)
- Evaluation Console → Broker API: calls API (evidence: `frontend/src/App.jsx`)
- Broker API → Red Worker: seals payload (evidence: `backend/main.py`)
- Red Worker → Model Gateway: requests inference (evidence: `backend/red_worker.py`)
- Red Worker → Blue Worker: submits reply (evidence: `backend/red_worker.py`)
- Blue Worker → Reply Scoring: scores reply (evidence: `backend/blue_worker.py`)
- Broker API → SQL Database: reads and writes (evidence: `backend/main.py`)
- Red Worker → SQL Database: reads payloads (evidence: `backend/red_worker.py`)
- Blue Worker → SQL Database: reads payloads (evidence: `backend/blue_worker.py`)
- Evaluation Records → SQL Database: uses ORM base (evidence: `backend/models.py`)
- Red Worker → Tenant Key Derivation: derives keys (evidence: `backend/red_worker.py`)
- Blue Worker → Tenant Key Derivation: derives keys (evidence: `backend/blue_worker.py`)
- Red Worker → Internal Auth: checks internal access (evidence: `backend/red_worker.py`)
- Blue Worker → Internal Auth: checks internal access (evidence: `backend/blue_worker.py`)
- Broker API → Signed Ledger: creates and verifies entries (evidence: `backend/main.py`)
