# keyuraghao/aisrf architecture

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

- Interactive diagram: https://gitdiagram.com/keyuraghao/aisrf
- Repository: https://github.com/keyuraghao/aisrf

## Overview

AISRF is a human-in-the-loop security gateway for LLM applications and agents. Its central workflow intercepts and normalizes outbound requests, analyzes them, applies policy, holds them for review when needed, forwards approved traffic, analyzes responses, and records decisions and evidence. Around that lifecycle, the repository provides red-team campaigns and scanner adapters, source-code review, reporting, integrations, and operator interfaces. The README documents these capabilities; sampled source confirms key pipeline, ticket, campaign, and code-review orchestration, but not every subsystem’s internal wiring.

Main entry points: [`aisrf/gateway/pipeline.py`](https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/pipeline.py) (Request Pipeline), [`aisrf/tickets/service.py`](https://github.com/keyuraghao/aisrf/blob/main/aisrf/tickets/service.py) (Ticket Lifecycle), [`aisrf/db.py`](https://github.com/keyuraghao/aisrf/blob/main/aisrf/db.py) (Application Database), [`aisrf/main.py`](https://github.com/keyuraghao/aisrf/blob/main/aisrf/main.py) (Application Assembly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Request Gateway"]
  node_gateway_router["Gateway Router<br/>[router.py]"]
  node_gateway_pipeline["Request Pipeline<br/>[pipeline.py]"]
  node_analysis["Risk Analysis<br/>[runner.py]"]
  node_guardrails["Guardrail Integrations"]
  node_policy["Traffic Policy<br/>[policy.py]"]
  node_forwarder["Upstream Forwarder<br/>[forwarder.py]"]
  node_response_analysis["Response Analysis"]
end

subgraph group_review["Review and Audit"]
  node_tickets["Ticket Lifecycle<br/>[service.py]"]
  node_dashboard["Review Dashboard<br/>[router.py]"]
  node_audit["Audit Trail<br/>[service.py]"]
end

subgraph group_assessment["Security Assessment"]
  node_redteam["Campaign Runner<br/>[engine.py]"]
  node_scanners["Scanner Adapters"]
  node_codereview["Source Review<br/>[engine.py]"]
  node_reports["Report Generation"]
end

subgraph group_platform["Platform Services"]
  node_database[("Application Database<br/>[db.py]")]
  node_typesafe["TypeSafe Decisions<br/>[client.py]"]
  node_settings[("Live Settings<br/>[settings_store.py]")]
  node_notifications["Reviewer Notifications<br/>[notifications.py]"]
  node_mcp["MCP Actions<br/>[mcp_server.py]"]
  node_application["Application Assembly<br/>[main.py]"]
end

node_client(("LLM Client"))
node_reviewer(("Human Reviewer"))
node_provider(("Model Backend"))

node_client -->|"submits request"| node_gateway_router
node_gateway_router -->|"dispatches traffic"| node_gateway_pipeline
node_gateway_pipeline -->|"runs analysis"| node_analysis
node_gateway_pipeline -->|"checks guardrails"| node_guardrails
node_gateway_pipeline -->|"applies policy"| node_policy
node_gateway_pipeline -->|"creates ticket"| node_tickets
node_gateway_pipeline -->|"forwards approved"| node_forwarder
node_forwarder -->|"sends request"| node_provider
node_provider -->|"returns response"| node_forwarder
node_gateway_pipeline -->|"checks response"| node_response_analysis
node_gateway_pipeline -->|"records outcome"| node_tickets
node_dashboard -->|"reviews tickets"| node_tickets
node_reviewer -->|"decides tickets"| node_dashboard
node_tickets -->|"records decisions"| node_audit
node_gateway_pipeline -->|"persists state"| node_database
node_tickets -->|"stores tickets"| node_database
node_audit -->|"stores events"| node_database
node_redteam -->|"submits probes"| node_gateway_pipeline
node_scanners -->|"sends probes"| node_gateway_router
node_codereview -->|"stores findings"| node_database
node_reports -->|"reads records"| node_database
node_analysis -.->|"requests judgment"| node_typesafe
node_codereview -.->|"triages findings"| node_typesafe
node_gateway_pipeline -->|"reads configuration"| node_settings
node_dashboard -.->|"triggers paging"| node_notifications
node_mcp -->|"invokes review actions"| node_tickets
node_application -->|"mounts routes"| node_gateway_router
node_application -->|"mounts routes"| node_dashboard
node_application -->|"mounts routes"| node_redteam
node_application -->|"mounts routes"| node_reports

click node_gateway_router "https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/router.py"
click node_gateway_pipeline "https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/pipeline.py"
click node_analysis "https://github.com/keyuraghao/aisrf/blob/main/aisrf/analysis/runner.py"
click node_guardrails "https://github.com/keyuraghao/aisrf/tree/main/aisrf/guardrails"
click node_policy "https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/policy.py"
click node_tickets "https://github.com/keyuraghao/aisrf/blob/main/aisrf/tickets/service.py"
click node_dashboard "https://github.com/keyuraghao/aisrf/blob/main/aisrf/dashboard/router.py"
click node_forwarder "https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/forwarder.py"
click node_response_analysis "https://github.com/keyuraghao/aisrf/blob/main/aisrf/analysis/analyzers/response_analyzers.py"
click node_audit "https://github.com/keyuraghao/aisrf/blob/main/aisrf/audit/service.py"
click node_database "https://github.com/keyuraghao/aisrf/blob/main/aisrf/db.py"
click node_redteam "https://github.com/keyuraghao/aisrf/blob/main/aisrf/redteam/engine.py"
click node_scanners "https://github.com/keyuraghao/aisrf/tree/main/aisrf/scanners"
click node_codereview "https://github.com/keyuraghao/aisrf/blob/main/aisrf/codereview/engine.py"
click node_reports "https://github.com/keyuraghao/aisrf/tree/main/aisrf/reports"
click node_typesafe "https://github.com/keyuraghao/aisrf/blob/main/aisrf/typesafe/client.py"
click node_settings "https://github.com/keyuraghao/aisrf/blob/main/aisrf/settings_store.py"
click node_notifications "https://github.com/keyuraghao/aisrf/blob/main/aisrf/notifications.py"
click node_mcp "https://github.com/keyuraghao/aisrf/blob/main/aisrf/mcp_server.py"
click node_application "https://github.com/keyuraghao/aisrf/blob/main/aisrf/main.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_gateway_router,node_gateway_pipeline,node_analysis,node_guardrails,node_policy,node_forwarder,node_response_analysis,node_client,node_reviewer toneBlue
class node_tickets,node_dashboard,node_audit toneAmber
class node_redteam,node_scanners,node_codereview,node_reports toneMint
class node_database,node_typesafe,node_settings,node_notifications,node_mcp,node_application toneRose
class node_provider toneIndigo
```

## Components

### Request Gateway

- [Gateway Router](https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/router.py): `aisrf/gateway/router.py`
- [Request Pipeline](https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/pipeline.py): `aisrf/gateway/pipeline.py`
- [Risk Analysis](https://github.com/keyuraghao/aisrf/blob/main/aisrf/analysis/runner.py): `aisrf/analysis/runner.py`
- [Guardrail Integrations](https://github.com/keyuraghao/aisrf/tree/main/aisrf/guardrails): `aisrf/guardrails`
- [Traffic Policy](https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/policy.py): `aisrf/gateway/policy.py`
- [Upstream Forwarder](https://github.com/keyuraghao/aisrf/blob/main/aisrf/gateway/forwarder.py): `aisrf/gateway/forwarder.py`
- [Response Analysis](https://github.com/keyuraghao/aisrf/blob/main/aisrf/analysis/analyzers/response_analyzers.py): `aisrf/analysis/analyzers/response_analyzers.py`

### Review and Audit

- [Ticket Lifecycle](https://github.com/keyuraghao/aisrf/blob/main/aisrf/tickets/service.py): `aisrf/tickets/service.py`
- [Review Dashboard](https://github.com/keyuraghao/aisrf/blob/main/aisrf/dashboard/router.py): `aisrf/dashboard/router.py`
- [Audit Trail](https://github.com/keyuraghao/aisrf/blob/main/aisrf/audit/service.py): `aisrf/audit/service.py`

### Security Assessment

- [Campaign Runner](https://github.com/keyuraghao/aisrf/blob/main/aisrf/redteam/engine.py): `aisrf/redteam/engine.py`
- [Scanner Adapters](https://github.com/keyuraghao/aisrf/tree/main/aisrf/scanners): `aisrf/scanners`
- [Source Review](https://github.com/keyuraghao/aisrf/blob/main/aisrf/codereview/engine.py): `aisrf/codereview/engine.py`
- [Report Generation](https://github.com/keyuraghao/aisrf/tree/main/aisrf/reports): `aisrf/reports`

### Platform Services

- [Application Database](https://github.com/keyuraghao/aisrf/blob/main/aisrf/db.py): `aisrf/db.py`
- [TypeSafe Decisions](https://github.com/keyuraghao/aisrf/blob/main/aisrf/typesafe/client.py): `aisrf/typesafe/client.py`
- [Live Settings](https://github.com/keyuraghao/aisrf/blob/main/aisrf/settings_store.py): `aisrf/settings_store.py`
- [Reviewer Notifications](https://github.com/keyuraghao/aisrf/blob/main/aisrf/notifications.py): `aisrf/notifications.py`
- [MCP Actions](https://github.com/keyuraghao/aisrf/blob/main/aisrf/mcp_server.py): `aisrf/mcp_server.py`
- [Application Assembly](https://github.com/keyuraghao/aisrf/blob/main/aisrf/main.py): `aisrf/main.py`

### Other components

- **LLM Client**
- **Human Reviewer**
- **Model Backend**

## Connections

- LLM Client → Gateway Router: submits request
- Gateway Router → Request Pipeline: dispatches traffic
- Request Pipeline → Risk Analysis: runs analysis
- Request Pipeline → Guardrail Integrations: checks guardrails
- Request Pipeline → Traffic Policy: applies policy
- Request Pipeline → Ticket Lifecycle: creates ticket
- Request Pipeline → Upstream Forwarder: forwards approved
- Upstream Forwarder → Model Backend: sends request
- Model Backend → Upstream Forwarder: returns response
- Request Pipeline → Response Analysis: checks response
- Request Pipeline → Ticket Lifecycle: records outcome
- Review Dashboard → Ticket Lifecycle: reviews tickets
- Human Reviewer → Review Dashboard: decides tickets
- Ticket Lifecycle → Audit Trail: records decisions
- Request Pipeline → Application Database: persists state
- Ticket Lifecycle → Application Database: stores tickets
- Audit Trail → Application Database: stores events
- Campaign Runner → Request Pipeline: submits probes
- Scanner Adapters → Gateway Router: sends probes
- Source Review → Application Database: stores findings
- Report Generation → Application Database: reads records
- Risk Analysis → TypeSafe Decisions: requests judgment
- Source Review → TypeSafe Decisions: triages findings
- Request Pipeline → Live Settings: reads configuration
- Review Dashboard → Reviewer Notifications: triggers paging
- MCP Actions → Ticket Lifecycle: invokes review actions
- Application Assembly → Gateway Router: mounts routes
- Application Assembly → Review Dashboard: mounts routes
- Application Assembly → Campaign Runner: mounts routes
- Application Assembly → Report Generation: mounts routes
