# blackholeinfiverse106-creator/text-risk-scoring-service architecture

> Architecture diagram of the GitHub repository blackholeinfiverse106-creator/text-risk-scoring-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/blackholeinfiverse106-creator/text-risk-scoring-service
- Repository: https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service

## Overview

Text Risk Scoring Service exposes deterministic text scoring and a multi-signal aggregation API, alongside a documented sovereign enforcement workflow. Text requests enter through FastAPI and reach keyword scoring; DGIC-enabled requests validate and adapt epistemic input before scoring. The sovereign path routes registered agents through governance, validation, enforcement, and core execution, with bucket storage and telemetry as separate outcomes. The README documents these responsibilities; sampled excerpts confirm selected API calls and module behavior, but not every internal dispatch, so some documented links are retained and unsampled internals are not elaborated.

Main entry points: [`app/main.py`](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/main.py) (FastAPI Routes), [`app/layer4_core.py`](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer4_core.py) (Core Execution), [`app/sutradhara_control_plane.py`](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/sutradhara_control_plane.py) (Sūtradhāra Routing), [`app/layer1_sarathi.py`](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer1_sarathi.py) (Sarathi Governance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Contracts"]
  node_api["FastAPI Routes<br/>[main.py]"]
  node_contracts["Request Contracts<br/>[schemas.py]"]
  node_enforcement_schemas["Enforcement Schemas"]
  node_contract_enforcement["Contract Checks"]
  node_jwt["JWT Authentication<br/>[jwt_auth.py]"]
end

subgraph group_risk["Risk and Epistemics"]
  node_text_scoring["Text Risk Scoring"]
  node_rule_categories["Risk Rule Sets<br/>[aiaic_rules.py]"]
  node_dgic["DGIC Epistemic Adapter<br/>[layer3_dgic.py]"]
  node_aggregation["Signal Aggregation"]
end

subgraph group_governance["Governance and Execution"]
  node_control_plane["Sūtradhāra Routing"]
  node_sarathi["Sarathi Governance<br/>[layer1_sarathi.py]"]
  node_enforcement_gate["Enforcement Gate"]
  node_rajya["Authority Validation"]
  node_core["Core Execution<br/>[layer4_core.py]"]
  node_execution_controller["Action Controller"]
  node_cet_validator["CET Validator"]
end

subgraph group_records["Storage and Telemetry"]
  node_bucket[("Bucket Ledger<br/>[layer5_bucket.py]")]
  node_insightbridge["Telemetry Emission"]
  node_streamer["Niyantran Streamer"]
end

node_caller(("API Client"))

node_caller -->|"submits requests"| node_api
node_api -->|"scores text"| node_text_scoring
node_api -->|"validates and adapts"| node_dgic
node_api -->|"aggregates signals"| node_aggregation
node_text_scoring -->|"uses risk categories"| node_rule_categories
node_api -->|"routes invocation"| node_control_plane
node_control_plane -->|"routes governance"| node_sarathi
node_control_plane -->|"routes enforcement"| node_enforcement_gate
node_sarathi -->|"requires approval"| node_rajya
node_core -->|"validates authority"| node_rajya
node_core -->|"checks enforcement token"| node_sarathi
node_core -->|"executes or blocks"| node_execution_controller
node_core -->|"writes records"| node_bucket
node_core -->|"emits telemetry"| node_insightbridge
node_dgic -->|"provides epistemic signals"| node_insightbridge
node_api -->|"validates requests"| node_contracts
node_api -->|"checks contracts"| node_contract_enforcement
node_api -->|"uses structured contracts"| node_enforcement_schemas
node_api -->|"submits validation"| node_rajya
node_control_plane -->|"references validator"| node_cet_validator
node_api -->|"lists and replays entries"| node_bucket
node_api -->|"uses authentication"| node_jwt

click node_api "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/main.py"
click node_contracts "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/schemas.py"
click node_enforcement_schemas "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/enforcement_schemas.py"
click node_contract_enforcement "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/contract_enforcement.py"
click node_text_scoring "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer0_intelligence.py"
click node_rule_categories "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/aiaic_rules.py"
click node_dgic "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer3_dgic.py"
click node_aggregation "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer6_insightbridge.py"
click node_control_plane "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/sutradhara_control_plane.py"
click node_sarathi "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer1_sarathi.py"
click node_enforcement_gate "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer4_enforcement.py"
click node_rajya "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/rajya_validation_engine.py"
click node_core "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer4_core.py"
click node_execution_controller "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/execution_controller.py"
click node_cet_validator "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer7_cet_validator.py"
click node_bucket "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer5_bucket.py"
click node_insightbridge "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer6_insightbridge.py"
click node_streamer "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/niyantran_streamer.py"
click node_jwt "https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/jwt_auth.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_api,node_contracts,node_enforcement_schemas,node_contract_enforcement,node_jwt,node_caller toneBlue
class node_text_scoring,node_rule_categories,node_dgic,node_aggregation toneAmber
class node_control_plane,node_sarathi,node_enforcement_gate,node_rajya,node_core,node_execution_controller,node_cet_validator toneMint
class node_bucket,node_insightbridge,node_streamer toneRose
```

## Components

### API and Contracts

- [FastAPI Routes](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/main.py): `app/main.py`
- [Request Contracts](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/schemas.py): `app/schemas.py`
- [Enforcement Schemas](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/enforcement_schemas.py): `app/enforcement_schemas.py`
- [Contract Checks](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/contract_enforcement.py): `app/contract_enforcement.py`
- [JWT Authentication](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/jwt_auth.py): `app/jwt_auth.py`

### Risk and Epistemics

- [Text Risk Scoring](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer0_intelligence.py): `app/layer0_intelligence.py`
- [Risk Rule Sets](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/aiaic_rules.py): `app/aiaic_rules.py`
- [DGIC Epistemic Adapter](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer3_dgic.py): `app/layer3_dgic.py`
- [Signal Aggregation](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer6_insightbridge.py): `app/layer6_insightbridge.py`

### Governance and Execution

- [Sūtradhāra Routing](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/sutradhara_control_plane.py): `app/sutradhara_control_plane.py`
- [Sarathi Governance](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer1_sarathi.py): `app/layer1_sarathi.py`
- [Enforcement Gate](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer4_enforcement.py): `app/layer4_enforcement.py`
- [Authority Validation](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/rajya_validation_engine.py): `app/rajya_validation_engine.py`
- [Core Execution](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer4_core.py): `app/layer4_core.py`
- [Action Controller](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/execution_controller.py): `app/execution_controller.py`
- [CET Validator](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer7_cet_validator.py): `app/layer7_cet_validator.py`

### Storage and Telemetry

- [Bucket Ledger](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer5_bucket.py): `app/layer5_bucket.py`
- [Telemetry Emission](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/layer6_insightbridge.py): `app/layer6_insightbridge.py`
- [Niyantran Streamer](https://github.com/blackholeinfiverse106-creator/text-risk-scoring-service/blob/main/app/niyantran_streamer.py): `app/niyantran_streamer.py`

### Other components

- **API Client**

## Connections

- API Client → FastAPI Routes: submits requests (evidence: `README.md`)
- FastAPI Routes → Text Risk Scoring: scores text (evidence: `app/main.py`)
- FastAPI Routes → DGIC Epistemic Adapter: validates and adapts (evidence: `app/main.py`)
- FastAPI Routes → Signal Aggregation: aggregates signals (evidence: `app/main.py`)
- Text Risk Scoring → Risk Rule Sets: uses risk categories (evidence: `app/layer0_intelligence.py`)
- FastAPI Routes → Sūtradhāra Routing: routes invocation (evidence: `README.md`)
- Sūtradhāra Routing → Sarathi Governance: routes governance (evidence: `README.md`)
- Sūtradhāra Routing → Enforcement Gate: routes enforcement (evidence: `app/sutradhara_control_plane.py`)
- Sarathi Governance → Authority Validation: requires approval (evidence: `app/layer1_sarathi.py`)
- Core Execution → Authority Validation: validates authority (evidence: `app/layer4_core.py`)
- Core Execution → Sarathi Governance: checks enforcement token (evidence: `app/layer4_core.py`)
- Core Execution → Action Controller: executes or blocks (evidence: `app/layer4_core.py`)
- Core Execution → Bucket Ledger: writes records (evidence: `README.md`)
- Core Execution → Telemetry Emission: emits telemetry (evidence: `README.md`)
- DGIC Epistemic Adapter → Telemetry Emission: provides epistemic signals (evidence: `app/layer3_dgic.py`)
- FastAPI Routes → Request Contracts: validates requests (evidence: `app/main.py`)
- FastAPI Routes → Contract Checks: checks contracts (evidence: `app/main.py`)
- FastAPI Routes → Enforcement Schemas: uses structured contracts (evidence: `app/main.py`)
- FastAPI Routes → Authority Validation: submits validation (evidence: `app/main.py`)
- Sūtradhāra Routing → CET Validator: references validator (evidence: `app/sutradhara_control_plane.py`)
- FastAPI Routes → Bucket Ledger: lists and replays entries (evidence: `app/main.py`)
- FastAPI Routes → JWT Authentication: uses authentication (evidence: `app/main.py`)
