# imbdy/trace architecture

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

- Interactive diagram: https://gitdiagram.com/imbdy/trace
- Repository: https://github.com/imbdy/trace

## Overview

Trace is an AI debugging companion: a user submits a Debug or Explain request, the desktop frontend sends it to a loopback backend, and the backend gathers evidence, consults Ollama, verifies cited locations, and returns a report. The report can include a verified patch; history and follow-ups support continued investigation. Both Electron and Tkinter frontends are present. Edges reflect the README, excerpts, and SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`trace_backend/investigation_engine.py`](https://github.com/imbdy/trace/blob/main/trace_backend/investigation_engine.py) (Agent investigation graph), [`trace_backend/server.py`](https://github.com/imbdy/trace/blob/main/trace_backend/server.py) (Loopback API server), [`electron/src/main/main.ts`](https://github.com/imbdy/trace/blob/main/electron/src/main/main.ts) (Electron shell), [`trace_ui/api_client.py`](https://github.com/imbdy/trace/blob/main/trace_ui/api_client.py) (Loopback API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_electron_app["Electron shell<br/>[main.ts]"]
  node_electron_ui["Companion and results UI"]
  node_python_ui["Tk companion app<br/>[app.py]"]
  node_tk_companion["Companion panel<br/>[companion.py]"]
  node_results["Results workspace<br/>[results_window.py]"]
end

subgraph group_api["Request and history"]
  node_protocol["API contract types<br/>[protocol.ts]"]
  node_api_client["Loopback API client<br/>[api_client.py]"]
  node_server["Loopback API server<br/>[server.py]"]
  node_history[("Investigation history<br/>[history.py]")]
end

subgraph group_investigation["Investigation pipeline"]
  node_engine["Agent investigation graph"]
  node_agent_graph["Graph execution<br/>[agent_graph.py]"]
  node_ollama_client["Ollama inference client<br/>[ollama_client.py]"]
  node_validator["Citation verification<br/>[validator.py]"]
  node_report["Investigation report<br/>[schemas.py]"]
end

subgraph group_evidence["Evidence and changes"]
  node_screenshot["Screenshot capture"]
  node_context["Local context collection"]
  node_inspector["Project inspection"]
  node_code_tools["Diagnostics and code tools<br/>[code_tools.py]"]
  node_git_context["Git enrichment<br/>[git_context.py]"]
  node_fixer["Verified patch application<br/>[code_fixer.py]"]
end

node_user(("Developer"))
node_ollama{{"Ollama model service"}}

node_user -->|"submits request"| node_electron_ui
node_user -->|"submits request"| node_tk_companion
node_electron_app -.->|"hosts UI"| node_electron_ui
node_electron_app -->|"starts backend"| node_server
node_electron_app -->|"calls API"| node_api_client
node_python_ui -->|"creates panel"| node_tk_companion
node_python_ui -->|"opens results"| node_results
node_python_ui -->|"starts and streams"| node_api_client
node_api_client -->|"sends HTTP requests"| node_server
node_server -->|"runs investigation"| node_engine
node_server -->|"loads and saves history"| node_history
node_engine -->|"executes graph"| node_agent_graph
node_engine -->|"captures screen"| node_screenshot
node_engine -->|"collects context"| node_context
node_engine -->|"reads project files"| node_inspector
node_engine -->|"runs diagnostics"| node_code_tools
node_engine -->|"enriches findings"| node_git_context
node_engine -->|"requests analysis"| node_ollama_client
node_ollama_client -->|"sends prompts"| node_ollama
node_engine -->|"verifies citations"| node_validator
node_engine -->|"applies verified patch"| node_fixer
node_engine -->|"builds report"| node_report
node_server -.->|"streams status and report"| node_electron_app
node_server -->|"streams events and results"| node_api_client
node_results -->|"presents findings"| node_user

click node_electron_app "https://github.com/imbdy/trace/blob/main/electron/src/main/main.ts"
click node_electron_ui "https://github.com/imbdy/trace/tree/main/electron/src/renderer"
click node_python_ui "https://github.com/imbdy/trace/blob/main/trace_ui/app.py"
click node_tk_companion "https://github.com/imbdy/trace/blob/main/trace_ui/companion.py"
click node_results "https://github.com/imbdy/trace/blob/main/trace_ui/results_window.py"
click node_protocol "https://github.com/imbdy/trace/blob/main/electron/src/shared/protocol.ts"
click node_api_client "https://github.com/imbdy/trace/blob/main/trace_ui/api_client.py"
click node_server "https://github.com/imbdy/trace/blob/main/trace_backend/server.py"
click node_history "https://github.com/imbdy/trace/blob/main/trace_backend/history.py"
click node_engine "https://github.com/imbdy/trace/blob/main/trace_backend/investigation_engine.py"
click node_agent_graph "https://github.com/imbdy/trace/blob/main/trace_backend/agent_graph.py"
click node_screenshot "https://github.com/imbdy/trace/blob/main/trace_backend/screenshot_service.py"
click node_context "https://github.com/imbdy/trace/blob/main/trace_backend/context_collector.py"
click node_inspector "https://github.com/imbdy/trace/blob/main/trace_backend/project_inspector.py"
click node_code_tools "https://github.com/imbdy/trace/blob/main/trace_backend/code_tools.py"
click node_git_context "https://github.com/imbdy/trace/blob/main/trace_backend/git_context.py"
click node_ollama_client "https://github.com/imbdy/trace/blob/main/trace_backend/ollama_client.py"
click node_validator "https://github.com/imbdy/trace/blob/main/trace_backend/validator.py"
click node_fixer "https://github.com/imbdy/trace/blob/main/trace_backend/code_fixer.py"
click node_report "https://github.com/imbdy/trace/blob/main/trace_backend/schemas.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_electron_app,node_electron_ui,node_python_ui,node_tk_companion,node_results toneBlue
class node_protocol,node_api_client,node_server,node_history toneAmber
class node_engine,node_agent_graph,node_ollama_client,node_validator,node_report toneMint
class node_screenshot,node_context,node_inspector,node_code_tools,node_git_context,node_fixer toneRose
class node_user,node_ollama toneIndigo
```

## Components

### Desktop experience

- [Electron shell](https://github.com/imbdy/trace/blob/main/electron/src/main/main.ts): `electron/src/main/main.ts`
- [Companion and results UI](https://github.com/imbdy/trace/tree/main/electron/src/renderer): `electron/src/renderer`
- [Tk companion app](https://github.com/imbdy/trace/blob/main/trace_ui/app.py): `trace_ui/app.py`
- [Companion panel](https://github.com/imbdy/trace/blob/main/trace_ui/companion.py): `trace_ui/companion.py`
- [Results workspace](https://github.com/imbdy/trace/blob/main/trace_ui/results_window.py): `trace_ui/results_window.py`

### Request and history

- [API contract types](https://github.com/imbdy/trace/blob/main/electron/src/shared/protocol.ts): `electron/src/shared/protocol.ts`
- [Loopback API client](https://github.com/imbdy/trace/blob/main/trace_ui/api_client.py): `trace_ui/api_client.py`
- [Loopback API server](https://github.com/imbdy/trace/blob/main/trace_backend/server.py): `trace_backend/server.py`
- [Investigation history](https://github.com/imbdy/trace/blob/main/trace_backend/history.py): `trace_backend/history.py`

### Investigation pipeline

- [Agent investigation graph](https://github.com/imbdy/trace/blob/main/trace_backend/investigation_engine.py): `trace_backend/investigation_engine.py`
- [Graph execution](https://github.com/imbdy/trace/blob/main/trace_backend/agent_graph.py): `trace_backend/agent_graph.py`
- [Ollama inference client](https://github.com/imbdy/trace/blob/main/trace_backend/ollama_client.py): `trace_backend/ollama_client.py`
- [Citation verification](https://github.com/imbdy/trace/blob/main/trace_backend/validator.py): `trace_backend/validator.py`
- [Investigation report](https://github.com/imbdy/trace/blob/main/trace_backend/schemas.py): `trace_backend/schemas.py`

### Evidence and changes

- [Screenshot capture](https://github.com/imbdy/trace/blob/main/trace_backend/screenshot_service.py): `trace_backend/screenshot_service.py`
- [Local context collection](https://github.com/imbdy/trace/blob/main/trace_backend/context_collector.py): `trace_backend/context_collector.py`
- [Project inspection](https://github.com/imbdy/trace/blob/main/trace_backend/project_inspector.py): `trace_backend/project_inspector.py`
- [Diagnostics and code tools](https://github.com/imbdy/trace/blob/main/trace_backend/code_tools.py): `trace_backend/code_tools.py`
- [Git enrichment](https://github.com/imbdy/trace/blob/main/trace_backend/git_context.py): `trace_backend/git_context.py`
- [Verified patch application](https://github.com/imbdy/trace/blob/main/trace_backend/code_fixer.py): `trace_backend/code_fixer.py`

### Other components

- **Developer**
- **Ollama model service**

## Connections

- Developer → Companion and results UI: submits request
- Developer → Companion panel: submits request
- Electron shell → Companion and results UI: hosts UI
- Electron shell → Loopback API server: starts backend (evidence: `electron/src/main/main.ts`)
- Electron shell → Loopback API client: calls API (evidence: `electron/src/main/main.ts`)
- Tk companion app → Companion panel: creates panel (evidence: `trace_ui/app.py`)
- Tk companion app → Results workspace: opens results (evidence: `trace_ui/app.py`)
- Tk companion app → Loopback API client: starts and streams (evidence: `trace_ui/app.py`)
- Loopback API client → Loopback API server: sends HTTP requests (evidence: `trace_ui/api_client.py`)
- Loopback API server → Agent investigation graph: runs investigation (evidence: `trace_backend/server.py`)
- Loopback API server → Investigation history: loads and saves history (evidence: `trace_backend/server.py`)
- Agent investigation graph → Graph execution: executes graph (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Screenshot capture: captures screen (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Local context collection: collects context (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Project inspection: reads project files (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Diagnostics and code tools: runs diagnostics (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Git enrichment: enriches findings (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Ollama inference client: requests analysis (evidence: `trace_backend/investigation_engine.py`)
- Ollama inference client → Ollama model service: sends prompts (evidence: `trace_backend/ollama_client.py`)
- Agent investigation graph → Citation verification: verifies citations (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Verified patch application: applies verified patch (evidence: `trace_backend/investigation_engine.py`)
- Agent investigation graph → Investigation report: builds report (evidence: `trace_backend/investigation_engine.py`)
- Loopback API server → Electron shell: streams status and report
- Loopback API server → Loopback API client: streams events and results (evidence: `trace_ui/api_client.py`)
- Results workspace → Developer: presents findings
