# ujwalbagalkoti/ai-time-travel-debugger architecture

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

- Interactive diagram: https://gitdiagram.com/ujwalbagalkoti/ai-time-travel-debugger
- Repository: https://github.com/ujwalbagalkoti/ai-time-travel-debugger

## Overview

The product records AI-agent executions as traces, imports them for inspection, and lets users fork a historical step for safe cached replay or optional live LLM replay. The graph follows the documented upload-to-debugger workflow and separates capture, API/persistence, replay, and UI responsibilities. Source excerpts show the SDK, backend, and primary UI calls; optional LangChain capture and upload are documented in the README, while frontend replay requests are visible in the page source.

Main entry points: [`backend/app/main.py`](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/main.py) (FastAPI endpoints), [`frontend/app/page.tsx`](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/frontend/app/page.tsx) (Debugger page), [`sdk/agent_tracer.py`](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/sdk/agent_tracer.py) (AgentTracer), [`backend/app/replay_engine.py`](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/replay_engine.py) (Replay engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Trace capture"]
  node_tracer["AgentTracer<br/>[agent_tracer.py]"]
  node_langchain["LangChain callback<br/>[langchain.py]"]
  node_tracefile["JSON trace file"]
end

subgraph group_service["Trace API and storage"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_database[("Trace and branch store<br/>[database.py]")]
end

subgraph group_replay["Replay"]
  node_replayengine["Replay engine<br/>[replay_engine.py]"]
end

subgraph group_debugger["Debugger UI"]
  node_page["Debugger page<br/>[page.tsx]"]
  node_canvas["Execution graph<br/>[TraceCanvas.tsx]"]
end

node_agent(("Agent application"))
node_user(("Debugger user"))
node_openai["OpenAI API"]

node_agent -->|"instruments"| node_tracer
node_tracer -->|"writes trace"| node_tracefile
node_langchain -->|"records callbacks"| node_tracer
node_user -->|"uploads trace"| node_api
node_tracefile -->|"imports trace"| node_api
node_api -->|"reads and writes"| node_database
node_page -->|"fetches trace"| node_api
node_api -->|"returns trace data"| node_page
node_page -->|"renders steps"| node_canvas
node_user -->|"inspects and edits"| node_page
node_page -->|"requests branch"| node_api
node_api -->|"matches tool cache"| node_replayengine
node_api -->|"requests live replay"| node_replayengine
node_replayengine -.->|"calls model optionally"| node_openai
node_api -->|"persists branch"| node_database

click node_tracer "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/sdk/agent_tracer.py"
click node_langchain "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/sdk/integrations/langchain.py"
click node_api "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/main.py"
click node_database "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/database.py"
click node_replayengine "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/replay_engine.py"
click node_page "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/frontend/app/page.tsx"
click node_canvas "https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/frontend/components/TraceCanvas.tsx"

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_tracer,node_langchain,node_tracefile,node_user toneBlue
class node_api,node_database toneAmber
class node_replayengine,node_openai toneMint
class node_page,node_canvas toneRose
class node_agent toneIndigo
```

## Components

### Trace capture

- [AgentTracer](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/sdk/agent_tracer.py): `sdk/agent_tracer.py`
- [LangChain callback](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/sdk/integrations/langchain.py): `sdk/integrations/langchain.py`
- **JSON trace file**

### Trace API and storage

- [FastAPI endpoints](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/main.py): `backend/app/main.py`
- [Trace and branch store](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/database.py): `backend/app/database.py`

### Replay

- [Replay engine](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/backend/app/replay_engine.py): `backend/app/replay_engine.py`

### Debugger UI

- [Debugger page](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Execution graph](https://github.com/ujwalbagalkoti/ai-time-travel-debugger/blob/main/frontend/components/TraceCanvas.tsx): `frontend/components/TraceCanvas.tsx`

### Other components

- **Agent application**
- **Debugger user**
- **OpenAI API**

## Connections

- Agent application → AgentTracer: instruments (evidence: `README.md`)
- AgentTracer → JSON trace file: writes trace (evidence: `README.md`)
- LangChain callback → AgentTracer: records callbacks (evidence: `sdk/integrations/langchain.py`)
- Debugger user → FastAPI endpoints: uploads trace (evidence: `README.md`)
- JSON trace file → FastAPI endpoints: imports trace (evidence: `README.md`)
- FastAPI endpoints → Trace and branch store: reads and writes (evidence: `backend/app/main.py`)
- Debugger page → FastAPI endpoints: fetches trace (evidence: `frontend/app/page.tsx`)
- FastAPI endpoints → Debugger page: returns trace data (evidence: `backend/app/main.py`)
- Debugger page → Execution graph: renders steps (evidence: `frontend/app/page.tsx`)
- Debugger user → Debugger page: inspects and edits (evidence: `README.md`)
- Debugger page → FastAPI endpoints: requests branch (evidence: `frontend/app/page.tsx`)
- FastAPI endpoints → Replay engine: matches tool cache (evidence: `backend/app/main.py`)
- FastAPI endpoints → Replay engine: requests live replay (evidence: `backend/app/main.py`)
- Replay engine → OpenAI API: calls model optionally (evidence: `backend/app/replay_engine.py`)
- FastAPI endpoints → Trace and branch store: persists branch (evidence: `backend/app/main.py`)
