# anirudh-kavle/coding-agent-audit-trails architecture

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

- Interactive diagram: https://gitdiagram.com/anirudh-kavle/coding-agent-audit-trails
- Repository: https://github.com/anirudh-kavle/coding-agent-audit-trails

## Overview

#### Purpose and entry points
Flight Recorder is a local audit trail for coding-agent tool sessions. It records consequential actions, their visible preceding rationale, and outcomes without storing model API keys. Primary entry points are the `fr` CLI in `flight_recorder/cli.py`, Claude hook adapter `bin/fr_hook_entry.py`, and provider-neutral API wrapper `flight_recorder/recorder.py`.

#### Hook ingestion and action pairing
Claude-style hook payloads enter through `bin/fr_hook_entry.py` and `flight_recorder/hook.py`. Pre-action arguments and post-action results are paired into one action record, preferring provider tool-call IDs and falling back to the newest unmatched same-session/tool action. Raw incoming payloads are independently retained for parser/debug validation.

#### Reasoning capture boundary
`flight_recorder/reasoning.py` extracts only visible assistant text or thinking from a live agent JSONL transcript. It tails a bounded transcript region, finds content preceding the current tool call, and stops at the prior tool result. Missing or unreadable transcripts do not block event capture: the stored action is marked with a capture gap rather than inventing rationale.

#### Provider-neutral instrumentation
API-backed agents instrument local tool execution through `FlightRecorder` in `flight_recorder/recorder.py`. `start_action()` captures tool name, arguments, and supplied visible rationale; the returned action is explicitly finished with either a successful result or error. This separates agent/provider orchestration from durable audit storage and supports future OpenAI or other provider loops without coupling to their credentials.

#### Durable local event store
`flight_recorder/store.py` owns persistence into the user-local `~/.flight-recorder/` directory. SQLite is the queryable source of record, configured for WAL behavior, while date-partitioned JSONL is an append-only mirror for evidence portability. The schema and full-text search support are defined in `flight_recorder/schema.sql`; result truncation and reasoning-size bounds constrain local storage volume.

#### CLI and project integration
`flight_recorder/cli.py` exposes `fr init`, `status`, `ui`, and `grep`. Initialization modifies a target project’s `.claude/settings.json` by merging recorder hooks rather than replacing existing settings. CLI commands form the operational boundary between installed recorder infrastructure and an instrumented coding project.

#### Viewing and search
The local timeline viewer is a FastAPI application rooted at `flight_recorder/viewer/app.py`, with its browser asset at `flight_recorder/viewer/static/index.html`. It reads the same local store used by capture, while `fr grep` relies on the SQLite/FTS query path. No remote backend or hosted service is required.

#### Runtime and trust model
The system is Python-packaged via `pyproject.toml`, uses SQLite and local filesystem storage, and can launch a FastAPI UI. External agent systems provide hook payloads or invoke the recorder API, but audit content remains local; raw payload logging under the recorder directory is intentionally available for compatibility diagnostics.

Main entry points: [`flight_recorder/store.py`](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/store.py) (Durable event store), [`flight_recorder/recorder.py`](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/recorder.py) (FlightRecorder), [`flight_recorder/cli.py`](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/cli.py) (fr CLI), [`bin/fr_hook_entry.py`](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/bin/fr_hook_entry.py) (Hook entry adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Capture"]
  node_claude{{"Claude hooks<br/>external agent"}}
  node_hook_entry["Hook entry adapter<br/>hook adapter<br/>[fr_hook_entry.py]"]
  node_hook_pairing["Hook action pairing<br/>ingestion logic<br/>[hook.py]"]
  node_reasoning["Visible reasoning capture<br/>transcript reader<br/>[reasoning.py]"]
  node_api_agents{{"API-backed agents<br/>external agent"}}
end

subgraph group_core["Recorder Core"]
  node_recorder["FlightRecorder<br/>instrumentation API<br/>[recorder.py]"]
end

subgraph group_storage["Local Audit Store"]
  node_store["Durable event store<br/>persistence service<br/>[store.py]"]
  node_schema["SQLite schema &amp; FTS<br/>database schema<br/>[schema.sql]"]
  node_sqlite[("SQLite query store<br/>local database")]
  node_jsonl["Date-partitioned JSONL<br/>evidence mirror"]
  node_raw_payloads["Raw payload log<br/>diagnostic evidence"]
end

subgraph group_access["Operations &amp; Viewing"]
  node_cli["fr CLI<br/>command interface<br/>[cli.py]"]
  node_project_settings["Project Claude settings<br/>project integration"]
  node_viewer["Timeline viewer API<br/>FastAPI application<br/>[app.py]"]
  node_viewer_ui["Timeline browser UI<br/>browser asset<br/>[index.html]"]
end

node_claude -->|"hook payloads"| node_hook_entry
node_hook_entry -->|"normalizes events"| node_hook_pairing
node_hook_entry -->|"retains raw payloads"| node_raw_payloads
node_hook_pairing -->|"finds preceding rationale"| node_reasoning
node_reasoning -->|"rationale or capture gap"| node_recorder
node_hook_pairing -->|"paired action"| node_recorder
node_api_agents -->|"start / finish action"| node_recorder
node_recorder -->|"durable action record"| node_store
node_store -->|"uses"| node_schema
node_store -->|"queryable records"| node_sqlite
node_store -->|"append-only mirror"| node_jsonl
node_cli -->|"init merges hooks"| node_project_settings
node_project_settings -.->|"configures hook execution"| node_claude
node_cli -->|"grep via FTS"| node_sqlite
node_cli -->|"launches UI"| node_viewer
node_viewer -->|"reads timeline"| node_sqlite
node_viewer -->|"serves"| node_viewer_ui

click node_hook_entry "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/bin/fr_hook_entry.py"
click node_hook_pairing "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/hook.py"
click node_reasoning "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/reasoning.py"
click node_recorder "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/recorder.py"
click node_store "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/store.py"
click node_schema "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/schema.sql"
click node_cli "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/cli.py"
click node_viewer "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/viewer/app.py"
click node_viewer_ui "https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/viewer/static/index.html"

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_claude,node_hook_entry,node_hook_pairing,node_reasoning,node_api_agents toneBlue
class node_recorder toneAmber
class node_store,node_schema,node_sqlite,node_jsonl,node_raw_payloads toneMint
class node_cli,node_project_settings,node_viewer,node_viewer_ui toneRose
```

## Components

### Capture

- **Claude hooks**: external agent · Supplies pre- and post-tool payloads.
- [Hook entry adapter](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/bin/fr_hook_entry.py): hook adapter · `bin/fr_hook_entry.py`
- [Hook action pairing](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/hook.py): ingestion logic · Pairs calls by tool ID or unmatched session/tool action. · `flight_recorder/hook.py`
- [Visible reasoning capture](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/reasoning.py): transcript reader · Captures preceding visible text without blocking events on gaps. · `flight_recorder/reasoning.py`
- **API-backed agents**: external agent · Invoke provider-neutral local instrumentation.

### Recorder Core

- [FlightRecorder](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/recorder.py): instrumentation API · Starts and explicitly finishes tool actions. · `flight_recorder/recorder.py`

### Local Audit Store

- [Durable event store](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/store.py): persistence service · Applies size bounds and writes local audit records. · `flight_recorder/store.py`
- [SQLite schema & FTS](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/schema.sql): database schema · `flight_recorder/schema.sql`
- **SQLite query store**: local database · WAL-backed source of record in the user-local recorder directory.
- **Date-partitioned JSONL**: evidence mirror · Append-only portable audit mirror in the user-local recorder directory.
- **Raw payload log**: diagnostic evidence · Retains incoming payloads independently for compatibility debugging.

### Operations & Viewing

- [fr CLI](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/cli.py): command interface · Provides init, status, ui, and grep. · `flight_recorder/cli.py`
- **Project Claude settings**: project integration · Hook settings are merged rather than replaced.
- [Timeline viewer API](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/viewer/app.py): FastAPI application · `flight_recorder/viewer/app.py`
- [Timeline browser UI](https://github.com/anirudh-kavle/coding-agent-audit-trails/blob/main/flight_recorder/viewer/static/index.html): browser asset · `flight_recorder/viewer/static/index.html`

## Connections

- Claude hooks → Hook entry adapter: hook payloads
- Hook entry adapter → Hook action pairing: normalizes events
- Hook entry adapter → Raw payload log: retains raw payloads
- Hook action pairing → Visible reasoning capture: finds preceding rationale
- Visible reasoning capture → FlightRecorder: rationale or capture gap
- Hook action pairing → FlightRecorder: paired action
- API-backed agents → FlightRecorder: start / finish action
- FlightRecorder → Durable event store: durable action record
- Durable event store → SQLite schema & FTS: uses
- Durable event store → SQLite query store: queryable records
- Durable event store → Date-partitioned JSONL: append-only mirror
- fr CLI → Project Claude settings: init merges hooks
- Project Claude settings → Claude hooks: configures hook execution
- fr CLI → SQLite query store: grep via FTS
- fr CLI → Timeline viewer API: launches UI
- Timeline viewer API → SQLite query store: reads timeline
- Timeline viewer API → Timeline browser UI: serves
