# ethantiller/gatekeeper architecture

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

- Interactive diagram: https://gitdiagram.com/ethantiller/gatekeeper
- Repository: https://github.com/ethantiller/gatekeeper

## Overview

Gatekeeper protects AI coding-agent actions through client hooks: it tracks sessions, normalizes and evaluates tool actions, then returns a decision; risky execution is isolated in Docker. Separate capabilities retain prompt/untrusted-read scanning, decision review and rollback, and client/server setup. The graph follows documented workflows and relationships visible in the excerpts or SOURCE INDEX; several implementation details are unsampled, so uncertain links are omitted.

Main entry points: [`src/gatekeeper/pipeline/decide.py`](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/decide.py) (Decision pipeline), [`src/gatekeeper/server/hooks`](https://github.com/ethantiller/gatekeeper/tree/main/src/gatekeeper/server/hooks) (Hook routes), [`src/gatekeeper/sandbox/runner.py`](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/runner.py) (Sandbox runner), [`src/gatekeeper/server/main.py`](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/main.py) (HTTP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Agent entry"]
  node_hooks["Hook routes"]
  node_server["HTTP server<br/>[main.py]"]
  node_auth["Token auth<br/>[auth.py]"]
  node_mcp["MCP tools<br/>[mcp_tools.py]"]
end

subgraph group_decision["Action evaluation"]
  node_decide["Decision pipeline<br/>[decide.py]"]
  node_parser["Command parser<br/>[parser.py]"]
  node_rules["Policy rules<br/>[rules.py]"]
  node_scanner["Instruction scanner<br/>[scanner.py]"]
  node_untrusted["Untrusted reads<br/>[untrusted.py]"]
  node_judge["Risk judge<br/>[judge.py]"]
  node_gemini["Gemini client<br/>[gemini_client.py]"]
  node_combine["Verdict combiner<br/>[combine.py]"]
end

subgraph group_sandbox["Sandbox execution"]
  node_runner["Sandbox runner<br/>[runner.py]"]
  node_environment["Sandbox environment<br/>[environment.py]"]
  node_repoimages["Repo images<br/>[repo_images.py]"]
  node_tripwires["Tripwire secrets<br/>[tripwires.py]"]
  node_logger["Connection logger<br/>[logger.py]"]
  node_saved["Saved changes<br/>[saved_changes.py]"]
end

subgraph group_state["Session and review"]
  node_sessions["Session tracking<br/>[sessions.py]"]
  node_db[("SQLite database<br/>[database.py]")]
  node_store["Decision store<br/>[decision_store.py]"]
  node_checkpoints["Git checkpoints<br/>[checkpoints.py]"]
  node_review["Review commands<br/>[review.py]"]
end

subgraph group_operations["Setup and service"]
  node_setup["Client setup<br/>[clients.py]"]
  node_service["Server service<br/>[service.py]"]
  node_sounds["Prompt sounds<br/>[sounds.py]"]
end

node_agent(("Coding agent"))

node_agent -->|"sends hooks"| node_hooks
node_agent -->|"uses tools"| node_mcp
node_server -->|"checks requests"| node_auth
node_server -->|"mounts routes"| node_hooks
node_server -->|"opens database"| node_db
node_hooks -->|"tracks sessions"| node_sessions
node_hooks -->|"evaluates action"| node_decide
node_hooks -->|"handles prompts"| node_sounds
node_decide -->|"parses commands"| node_parser
node_decide -->|"matches rules"| node_rules
node_decide -->|"checks reads"| node_untrusted
node_decide -->|"rates risk"| node_judge
node_decide -->|"combines verdict"| node_combine
node_untrusted -->|"scans content"| node_scanner
node_untrusted -->|"requests review"| node_gemini
node_decide -->|"runs sandbox"| node_runner
node_decide -->|"saves decision"| node_store
node_store -->|"creates checkpoint"| node_checkpoints
node_review -->|"reads decisions"| node_store
node_review -->|"rolls back"| node_checkpoints
node_runner -->|"uses environment"| node_environment
node_runner -->|"uses repo image"| node_repoimages
node_runner -->|"plants secrets"| node_tripwires
node_runner -->|"archives changes"| node_saved
node_environment -->|"starts logger"| node_logger
node_environment -->|"configures tripwires"| node_tripwires
node_setup -->|"installs hooks"| node_agent
node_service -->|"starts service"| node_server
node_hooks -->|"starts sessions"| node_sessions

click node_hooks "https://github.com/ethantiller/gatekeeper/tree/main/src/gatekeeper/server/hooks"
click node_server "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/main.py"
click node_auth "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/auth.py"
click node_mcp "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/mcp_tools.py"
click node_sessions "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/sessions.py"
click node_db "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/database.py"
click node_decide "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/decide.py"
click node_parser "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/parser.py"
click node_rules "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/rules.py"
click node_scanner "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/scanner.py"
click node_untrusted "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/untrusted.py"
click node_judge "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/judge.py"
click node_gemini "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/client/gemini_client.py"
click node_combine "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/combine.py"
click node_store "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/decision_store.py"
click node_checkpoints "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/checkpoints.py"
click node_review "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/cli/review.py"
click node_runner "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/runner.py"
click node_environment "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/environment.py"
click node_repoimages "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/repo_images.py"
click node_tripwires "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/tripwires.py"
click node_logger "https://github.com/ethantiller/gatekeeper/blob/main/docker/connection_logger/logger.py"
click node_saved "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/saved_changes.py"
click node_setup "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/setup/clients.py"
click node_service "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/setup/service.py"
click node_sounds "https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/sounds.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_hooks,node_server,node_auth,node_mcp toneBlue
class node_decide,node_parser,node_rules,node_scanner,node_untrusted,node_judge,node_gemini,node_combine toneAmber
class node_runner,node_environment,node_repoimages,node_tripwires,node_logger,node_saved toneMint
class node_sessions,node_db,node_store,node_checkpoints,node_review toneRose
class node_setup,node_service,node_sounds,node_agent toneIndigo
```

## Components

### Agent entry

- [Hook routes](https://github.com/ethantiller/gatekeeper/tree/main/src/gatekeeper/server/hooks): `src/gatekeeper/server/hooks`
- [HTTP server](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/main.py): `src/gatekeeper/server/main.py`
- [Token auth](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/auth.py): `src/gatekeeper/server/auth.py`
- [MCP tools](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/server/mcp_tools.py): `src/gatekeeper/server/mcp_tools.py`

### Action evaluation

- [Decision pipeline](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/decide.py): `src/gatekeeper/pipeline/decide.py`
- [Command parser](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/parser.py): `src/gatekeeper/pipeline/parser.py`
- [Policy rules](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/rules.py): `src/gatekeeper/pipeline/rules.py`
- [Instruction scanner](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/scanner.py): `src/gatekeeper/pipeline/scanner.py`
- [Untrusted reads](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/untrusted.py): `src/gatekeeper/pipeline/untrusted.py`
- [Risk judge](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/judge.py): `src/gatekeeper/pipeline/judge.py`
- [Gemini client](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/client/gemini_client.py): `src/gatekeeper/client/gemini_client.py`
- [Verdict combiner](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/pipeline/combine.py): `src/gatekeeper/pipeline/combine.py`

### Sandbox execution

- [Sandbox runner](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/runner.py): `src/gatekeeper/sandbox/runner.py`
- [Sandbox environment](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/environment.py): `src/gatekeeper/sandbox/environment.py`
- [Repo images](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/repo_images.py): `src/gatekeeper/sandbox/repo_images.py`
- [Tripwire secrets](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/tripwires.py): `src/gatekeeper/sandbox/tripwires.py`
- [Connection logger](https://github.com/ethantiller/gatekeeper/blob/main/docker/connection_logger/logger.py): `docker/connection_logger/logger.py`
- [Saved changes](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/sandbox/saved_changes.py): `src/gatekeeper/sandbox/saved_changes.py`

### Session and review

- [Session tracking](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/sessions.py): `src/gatekeeper/core/sessions.py`
- [SQLite database](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/database.py): `src/gatekeeper/database.py`
- [Decision store](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/decision_store.py): `src/gatekeeper/core/decision_store.py`
- [Git checkpoints](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/checkpoints.py): `src/gatekeeper/core/checkpoints.py`
- [Review commands](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/cli/review.py): `src/gatekeeper/cli/review.py`

### Setup and service

- [Client setup](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/setup/clients.py): `src/gatekeeper/setup/clients.py`
- [Server service](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/setup/service.py): `src/gatekeeper/setup/service.py`
- [Prompt sounds](https://github.com/ethantiller/gatekeeper/blob/main/src/gatekeeper/core/sounds.py): `src/gatekeeper/core/sounds.py`

### Other components

- **Coding agent**

## Connections

- Coding agent → Hook routes: sends hooks (evidence: `README.md`)
- Coding agent → MCP tools: uses tools (evidence: `README.md`)
- HTTP server → Token auth: checks requests (evidence: `src/gatekeeper/server/main.py`)
- HTTP server → Hook routes: mounts routes (evidence: `src/gatekeeper/server/main.py`)
- HTTP server → SQLite database: opens database (evidence: `src/gatekeeper/server/main.py`)
- Hook routes → Session tracking: tracks sessions (evidence: `src/gatekeeper/server/hooks/before_tool/route.py`)
- Hook routes → Decision pipeline: evaluates action (evidence: `src/gatekeeper/server/hooks/before_tool/route.py`)
- Hook routes → Prompt sounds: handles prompts (evidence: `src/gatekeeper/server/hooks/prompt/route.py`)
- Decision pipeline → Command parser: parses commands (evidence: `src/gatekeeper/pipeline/decide.py`)
- Decision pipeline → Policy rules: matches rules (evidence: `src/gatekeeper/pipeline/decide.py`)
- Decision pipeline → Untrusted reads: checks reads (evidence: `src/gatekeeper/pipeline/decide.py`)
- Decision pipeline → Risk judge: rates risk (evidence: `src/gatekeeper/pipeline/decide.py`)
- Decision pipeline → Verdict combiner: combines verdict (evidence: `src/gatekeeper/pipeline/decide.py`)
- Untrusted reads → Instruction scanner: scans content (evidence: `src/gatekeeper/pipeline/untrusted.py`)
- Untrusted reads → Gemini client: requests review
- Decision pipeline → Sandbox runner: runs sandbox (evidence: `src/gatekeeper/pipeline/decide.py`)
- Decision pipeline → Decision store: saves decision (evidence: `src/gatekeeper/pipeline/decide.py`)
- Decision store → Git checkpoints: creates checkpoint (evidence: `src/gatekeeper/core/decision_store.py`)
- Review commands → Decision store: reads decisions (evidence: `src/gatekeeper/cli/review.py`)
- Review commands → Git checkpoints: rolls back (evidence: `README.md`)
- Sandbox runner → Sandbox environment: uses environment (evidence: `src/gatekeeper/sandbox/runner.py`)
- Sandbox runner → Repo images: uses repo image (evidence: `src/gatekeeper/sandbox/runner.py`)
- Sandbox runner → Tripwire secrets: plants secrets (evidence: `src/gatekeeper/sandbox/runner.py`)
- Sandbox runner → Saved changes: archives changes (evidence: `src/gatekeeper/sandbox/runner.py`)
- Sandbox environment → Connection logger: starts logger (evidence: `README.md`)
- Sandbox environment → Tripwire secrets: configures tripwires (evidence: `src/gatekeeper/sandbox/environment.py`)
- Client setup → Coding agent: installs hooks (evidence: `src/gatekeeper/setup/clients.py`)
- Server service → HTTP server: starts service (evidence: `src/gatekeeper/setup/service.py`)
- Hook routes → Session tracking: starts sessions (evidence: `src/gatekeeper/server/hooks/session_start/route.py`)
