# aryanketkar-15/trc-engine architecture

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

- Interactive diagram: https://gitdiagram.com/aryanketkar-15/trc-engine
- Repository: https://github.com/aryanketkar-15/trc-engine

## Overview

TRC Engine Phase 1 accepts a system model, retrieves relevant knowledge-base patterns, analyzes attack chains, generates and validates threat scenarios, then exposes them for human review and writes approved results to SCRS. The API also tracks run status and supports rejection-driven retries. The README documents this workflow and KB ingestion; source excerpts show orchestration and selected module dependencies. Some unsampled component details are represented only where the README or source index supports them.

Main entry points: [`agents/threat_agent/orchestrator.py`](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/orchestrator.py) (Pipeline Orchestrator), [`agents/threat_agent/router.py`](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/router.py) (Threat API), [`agents/threat_agent/retrieval.py`](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/retrieval.py) (KB Retrieval), [`agents/threat_agent/generator.py`](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/generator.py) (Scenario Generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Runs"]
  node_api["Threat API<br/>[router.py]"]
  node_app["FastAPI App<br/>[main.py]"]
  node_settings["Runtime Settings<br/>[settings.py]"]
end

subgraph group_reasoning["Threat Reasoning"]
  node_orchestrator["Pipeline Orchestrator<br/>[orchestrator.py]"]
  node_attack["Attack Chain Analysis<br/>[attack_chain.py]"]
  node_generator["Scenario Generator<br/>[generator.py]"]
  node_validator["Invariant Validator<br/>[validator.py]"]
  node_grounding["Evidence Grounding<br/>[grounding.py]"]
  node_llm["LLM Client<br/>[llm_client.py]"]
  node_schemas["Threat Contracts<br/>[schemas.py]"]
  node_scorer["Confidence Scorer<br/>[scorer.py]"]
end

subgraph group_knowledge["Knowledge Base"]
  node_retrieval["KB Retrieval<br/>[retrieval.py]"]
  node_rerank["Candidate Reranking<br/>[rerank.py]"]
  node_kb_loaders["Knowledge Loaders<br/>[base_loader.py]"]
  node_kb_builder["KB Index Builder<br/>[build_index.py]"]
end

subgraph group_state["Persistence and State"]
  node_db[("PostgreSQL and pgvector<br/>[db.py]")]
  node_run_store["Run Registry<br/>[run_store.py]"]
  node_scrs[("SCRS State Manager<br/>[state_manager.py]")]
end

node_analyst(("Analyst"))
node_human(("Human Reviewer"))

node_analyst -->|"submits model"| node_api
node_app -->|"mounts router"| node_api
node_api -->|"starts analysis"| node_orchestrator
node_orchestrator -->|"fetches candidates"| node_retrieval
node_retrieval -->|"queries vectors"| node_db
node_retrieval -->|"reranks candidates"| node_rerank
node_orchestrator -->|"builds paths"| node_attack
node_orchestrator -->|"generates scenarios"| node_generator
node_generator -->|"requests completion"| node_llm
node_orchestrator -->|"validates scenarios"| node_validator
node_orchestrator -->|"uses grounding"| node_grounding
node_generator -->|"scores confidence"| node_scorer
node_api -->|"tracks runs"| node_run_store
node_run_store -->|"persists runs"| node_db
node_human -->|"reviews scenarios"| node_api
node_api -->|"records approval"| node_scrs
node_kb_builder -->|"loads entries"| node_kb_loaders
node_kb_builder -->|"builds vector index"| node_db
node_llm -->|"reads credentials"| node_settings
node_retrieval -->|"reads options"| node_settings

click node_api "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/router.py"
click node_app "https://github.com/aryanketkar-15/trc-engine/blob/develop/main.py"
click node_orchestrator "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/orchestrator.py"
click node_retrieval "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/retrieval.py"
click node_attack "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/attack_chain.py"
click node_generator "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/generator.py"
click node_validator "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/validator.py"
click node_grounding "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/grounding.py"
click node_rerank "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/rerank.py"
click node_llm "https://github.com/aryanketkar-15/trc-engine/blob/develop/common/llm_client.py"
click node_settings "https://github.com/aryanketkar-15/trc-engine/blob/develop/config/settings.py"
click node_kb_loaders "https://github.com/aryanketkar-15/trc-engine/blob/develop/kb/loaders/base_loader.py"
click node_kb_builder "https://github.com/aryanketkar-15/trc-engine/blob/develop/kb/scripts/build_index.py"
click node_db "https://github.com/aryanketkar-15/trc-engine/blob/develop/common/db.py"
click node_run_store "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/run_store.py"
click node_scrs "https://github.com/aryanketkar-15/trc-engine/blob/develop/scrp/state_manager.py"
click node_schemas "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/schemas.py"
click node_scorer "https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/scorer.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_app,node_settings,node_human toneBlue
class node_orchestrator,node_attack,node_generator,node_validator,node_grounding,node_llm,node_schemas,node_scorer toneAmber
class node_retrieval,node_rerank,node_kb_loaders,node_kb_builder toneMint
class node_db,node_run_store,node_scrs toneRose
class node_analyst toneIndigo
```

## Components

### API and Runs

- [Threat API](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/router.py): `agents/threat_agent/router.py`
- [FastAPI App](https://github.com/aryanketkar-15/trc-engine/blob/develop/main.py): `main.py`
- [Runtime Settings](https://github.com/aryanketkar-15/trc-engine/blob/develop/config/settings.py): `config/settings.py`

### Threat Reasoning

- [Pipeline Orchestrator](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/orchestrator.py): `agents/threat_agent/orchestrator.py`
- [Attack Chain Analysis](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/attack_chain.py): `agents/threat_agent/attack_chain.py`
- [Scenario Generator](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/generator.py): `agents/threat_agent/generator.py`
- [Invariant Validator](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/validator.py): `agents/threat_agent/validator.py`
- [Evidence Grounding](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/grounding.py): `agents/threat_agent/grounding.py`
- [LLM Client](https://github.com/aryanketkar-15/trc-engine/blob/develop/common/llm_client.py): `common/llm_client.py`
- [Threat Contracts](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/schemas.py): `agents/threat_agent/schemas.py`
- [Confidence Scorer](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/scorer.py): `agents/threat_agent/scorer.py`

### Knowledge Base

- [KB Retrieval](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/retrieval.py): `agents/threat_agent/retrieval.py`
- [Candidate Reranking](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/rerank.py): `agents/threat_agent/rerank.py`
- [Knowledge Loaders](https://github.com/aryanketkar-15/trc-engine/blob/develop/kb/loaders/base_loader.py): `kb/loaders/base_loader.py`
- [KB Index Builder](https://github.com/aryanketkar-15/trc-engine/blob/develop/kb/scripts/build_index.py): `kb/scripts/build_index.py`

### Persistence and State

- [PostgreSQL and pgvector](https://github.com/aryanketkar-15/trc-engine/blob/develop/common/db.py): `common/db.py`
- [Run Registry](https://github.com/aryanketkar-15/trc-engine/blob/develop/agents/threat_agent/run_store.py): `agents/threat_agent/run_store.py`
- [SCRS State Manager](https://github.com/aryanketkar-15/trc-engine/blob/develop/scrp/state_manager.py): `scrp/state_manager.py`

### Other components

- **Analyst**
- **Human Reviewer**

## Connections

- Analyst → Threat API: submits model
- FastAPI App → Threat API: mounts router (evidence: `main.py`)
- Threat API → Pipeline Orchestrator: starts analysis (evidence: `agents/threat_agent/router.py`)
- Pipeline Orchestrator → KB Retrieval: fetches candidates (evidence: `agents/threat_agent/orchestrator.py`)
- KB Retrieval → PostgreSQL and pgvector: queries vectors (evidence: `agents/threat_agent/retrieval.py`)
- KB Retrieval → Candidate Reranking: reranks candidates (evidence: `agents/threat_agent/retrieval.py`)
- Pipeline Orchestrator → Attack Chain Analysis: builds paths (evidence: `agents/threat_agent/orchestrator.py`)
- Pipeline Orchestrator → Scenario Generator: generates scenarios (evidence: `agents/threat_agent/orchestrator.py`)
- Scenario Generator → LLM Client: requests completion (evidence: `agents/threat_agent/generator.py`)
- Pipeline Orchestrator → Invariant Validator: validates scenarios (evidence: `agents/threat_agent/orchestrator.py`)
- Pipeline Orchestrator → Evidence Grounding: uses grounding (evidence: `agents/threat_agent/orchestrator.py`)
- Scenario Generator → Confidence Scorer: scores confidence (evidence: `agents/threat_agent/generator.py`)
- Threat API → Run Registry: tracks runs (evidence: `agents/threat_agent/router.py`)
- Run Registry → PostgreSQL and pgvector: persists runs (evidence: `agents/threat_agent/run_store.py`)
- Human Reviewer → Threat API: reviews scenarios
- Threat API → SCRS State Manager: records approval (evidence: `agents/threat_agent/router.py`)
- KB Index Builder → Knowledge Loaders: loads entries (evidence: `kb/scripts/build_index.py`)
- KB Index Builder → PostgreSQL and pgvector: builds vector index (evidence: `kb/scripts/build_index.py`)
- LLM Client → Runtime Settings: reads credentials (evidence: `common/llm_client.py`)
- KB Retrieval → Runtime Settings: reads options (evidence: `agents/threat_agent/retrieval.py`)
