# code-with-rajatkapoor/agentguard architecture

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

- Interactive diagram: https://gitdiagram.com/code-with-rajatkapoor/agentguard
- Repository: https://github.com/code-with-rajatkapoor/agentguard

## Overview

AgentGuard is a runtime firewall and forensic recorder for AI-agent tool use. Its principal workflow runs through the API: an agent proposes a tool call, the guard scores it, and the run engine either executes it, pauses for human approval, or blocks it. Decisions are recorded for the dashboard timeline. The map also includes the documented AI-provider, red-team, and operator-dashboard capabilities. Relationships rely on the supplied excerpts and README; unsampled implementation details are not inferred.

Main entry points: [`main.py`](https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py) (Run engine), [`frontend/index.html`](https://github.com/code-with-rajatkapoor/agentguard/blob/main/frontend/index.html) (Command-center dashboard), [`guard.py`](https://github.com/code-with-rajatkapoor/agentguard/blob/main/guard.py) (Tool-call inspection), [`tools.py`](https://github.com/code-with-rajatkapoor/agentguard/blob/main/tools.py) (Simulated tool executor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Run orchestration"]
  node_api["Run API<br/>[main.py]"]
  node_run_engine["Run engine<br/>[main.py]"]
  node_approval["Approval and stop<br/>[main.py]"]
  node_request_models["API data models<br/>[models.py]"]
  node_tool_executor["Simulated tool executor<br/>[tools.py]"]
  node_support_tools["Support tools<br/>[tools.py]"]
end

subgraph group_security["Policy enforcement"]
  node_guard["Tool-call inspection<br/>[guard.py]"]
  node_policy_rules["Risk rules<br/>[policies.py]"]
end

subgraph group_evidence["Forensics and state"]
  node_event_model["Forensic event model<br/>[models.py]"]
  node_forensic_log[("Forensic recorder<br/>[forensic.py]")]
end

subgraph group_operator["Operator dashboard"]
  node_dashboard["Command-center dashboard<br/>[index.html]"]
  node_dashboard_styles["Dashboard styling<br/>[styles.css]"]
end

subgraph group_capabilities["Agent and demo modes"]
  node_agent["Agent modes<br/>[agent.py]"]
  node_provider_adapter["AI provider adapter<br/>[providers.py]"]
  node_red_team["Red-team scenarios<br/>[redteam.py]"]
end

node_user(("Operator"))

node_user -->|"starts or controls"| node_api
node_api -->|"dispatches runs"| node_run_engine
node_api -->|"handles approval and stop"| node_approval
node_run_engine -->|"gets proposed calls"| node_agent
node_agent -->|"requests model calls"| node_provider_adapter
node_run_engine -->|"inspects proposed calls"| node_guard
node_guard -->|"scores against rules"| node_policy_rules
node_run_engine -->|"executes allowed calls"| node_tool_executor
node_tool_executor -->|"dispatches tools"| node_support_tools
node_run_engine -->|"pauses for review"| node_approval
node_approval -->|"executes approved call"| node_tool_executor
node_run_engine -->|"records decisions"| node_forensic_log
node_api -->|"serves events and verification"| node_forensic_log
node_run_engine -->|"returns run response"| node_request_models
node_guard -->|"creates event data"| node_event_model
node_forensic_log -->|"provides timeline events"| node_dashboard
node_dashboard -->|"requests runs and events"| node_api
node_dashboard -->|"submits review decisions"| node_approval
node_dashboard_styles -->|"styles interface"| node_dashboard
node_api -->|"routes attack scenarios"| node_red_team

click node_api "https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py"
click node_run_engine "https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py"
click node_approval "https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py"
click node_request_models "https://github.com/code-with-rajatkapoor/agentguard/blob/main/models.py"
click node_guard "https://github.com/code-with-rajatkapoor/agentguard/blob/main/guard.py"
click node_policy_rules "https://github.com/code-with-rajatkapoor/agentguard/blob/main/policies.py"
click node_tool_executor "https://github.com/code-with-rajatkapoor/agentguard/blob/main/tools.py"
click node_support_tools "https://github.com/code-with-rajatkapoor/agentguard/blob/main/tools.py"
click node_agent "https://github.com/code-with-rajatkapoor/agentguard/blob/main/agent.py"
click node_provider_adapter "https://github.com/code-with-rajatkapoor/agentguard/blob/main/providers.py"
click node_red_team "https://github.com/code-with-rajatkapoor/agentguard/blob/main/redteam.py"
click node_event_model "https://github.com/code-with-rajatkapoor/agentguard/blob/main/models.py"
click node_forensic_log "https://github.com/code-with-rajatkapoor/agentguard/blob/main/forensic.py"
click node_dashboard "https://github.com/code-with-rajatkapoor/agentguard/blob/main/frontend/index.html"
click node_dashboard_styles "https://github.com/code-with-rajatkapoor/agentguard/blob/main/frontend/styles.css"

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_run_engine,node_approval,node_request_models,node_tool_executor,node_support_tools toneBlue
class node_guard,node_policy_rules toneAmber
class node_event_model,node_forensic_log toneMint
class node_dashboard,node_dashboard_styles toneRose
class node_agent,node_provider_adapter,node_red_team,node_user toneIndigo
```

## Components

### Run orchestration

- [Run API](https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py): `main.py`
- [Run engine](https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py): `main.py`
- [Approval and stop](https://github.com/code-with-rajatkapoor/agentguard/blob/main/main.py): `main.py`
- [API data models](https://github.com/code-with-rajatkapoor/agentguard/blob/main/models.py): `models.py`
- [Simulated tool executor](https://github.com/code-with-rajatkapoor/agentguard/blob/main/tools.py): `tools.py`
- [Support tools](https://github.com/code-with-rajatkapoor/agentguard/blob/main/tools.py): `tools.py`

### Policy enforcement

- [Tool-call inspection](https://github.com/code-with-rajatkapoor/agentguard/blob/main/guard.py): `guard.py`
- [Risk rules](https://github.com/code-with-rajatkapoor/agentguard/blob/main/policies.py): `policies.py`

### Forensics and state

- [Forensic event model](https://github.com/code-with-rajatkapoor/agentguard/blob/main/models.py): `models.py`
- [Forensic recorder](https://github.com/code-with-rajatkapoor/agentguard/blob/main/forensic.py): `forensic.py`

### Operator dashboard

- [Command-center dashboard](https://github.com/code-with-rajatkapoor/agentguard/blob/main/frontend/index.html): `frontend/index.html`
- [Dashboard styling](https://github.com/code-with-rajatkapoor/agentguard/blob/main/frontend/styles.css): `frontend/styles.css`

### Agent and demo modes

- [Agent modes](https://github.com/code-with-rajatkapoor/agentguard/blob/main/agent.py): `agent.py`
- [AI provider adapter](https://github.com/code-with-rajatkapoor/agentguard/blob/main/providers.py): `providers.py`
- [Red-team scenarios](https://github.com/code-with-rajatkapoor/agentguard/blob/main/redteam.py): `redteam.py`

### Other components

- **Operator**

## Connections

- Operator → Run API: starts or controls (evidence: `README.md`)
- Run API → Run engine: dispatches runs (evidence: `README.md`)
- Run API → Approval and stop: handles approval and stop (evidence: `README.md`)
- Run engine → Agent modes: gets proposed calls (evidence: `README.md`)
- Agent modes → AI provider adapter: requests model calls (evidence: `agent.py`)
- Run engine → Tool-call inspection: inspects proposed calls (evidence: `README.md`)
- Tool-call inspection → Risk rules: scores against rules (evidence: `guard.py`)
- Run engine → Simulated tool executor: executes allowed calls (evidence: `README.md`)
- Simulated tool executor → Support tools: dispatches tools (evidence: `tools.py`)
- Run engine → Approval and stop: pauses for review (evidence: `README.md`)
- Approval and stop → Simulated tool executor: executes approved call (evidence: `README.md`)
- Run engine → Forensic recorder: records decisions (evidence: `README.md`)
- Run API → Forensic recorder: serves events and verification (evidence: `main.py`)
- Run engine → API data models: returns run response (evidence: `main.py`)
- Tool-call inspection → Forensic event model: creates event data (evidence: `guard.py`)
- Forensic recorder → Command-center dashboard: provides timeline events (evidence: `README.md`)
- Command-center dashboard → Run API: requests runs and events (evidence: `README.md`)
- Command-center dashboard → Approval and stop: submits review decisions (evidence: `README.md`)
- Dashboard styling → Command-center dashboard: styles interface
- Run API → Red-team scenarios: routes attack scenarios (evidence: `main.py`)
