---
title: Architecture
description: The pieces of Hindsight and how an event travels from your editor to the dashboard.
sidebar:
  order: 1
---

Hindsight has four parts. A daemon on your computer collects events. A server keeps them and works out the time. A desktop app and a website show the result. Adapters are the small bits of glue that tell the daemon what an editor or agent is doing.

```mermaid
flowchart LR
  subgraph computer["Your computer"]
    adapters["Adapters<br/>hooks, plugins, extensions"]
    git["post-commit hook"]
    daemon["hindsight-daemon<br/>SQLite, presence, local API on 127.0.0.1:5292"]
    app["Desktop app<br/>tray, Byte, dashboard"]
    adapters --> daemon
    git --> daemon
    app <--> daemon
  end
  daemon -- "hash-chained batches, every 60 s" --> server["hindsight-server"]
  server <--> db[("Postgres")]
  server --> web["Website dashboard"]
```

## What lives where

The Rust workspace in `Cargo.toml` has four members. The adapters sit next to it.

| Path | What it is |
|---|---|
| `crates/hindsight-core` | Shared logic: the event schema, the privacy helpers, the hash chain, upload receipts, the attention rules that turn events into time, and the wire types the other crates share. |
| `crates/hindsight-daemon` | The `hindsight-daemon` binary: local API, SQLite store, presence, sync, and the `connect` command that hooks it into your tools. |
| `crates/hindsight-server` | The `hindsight-server` binary: HTTP API, Postgres migrations, the website dashboard, OAuth and API keys. It also serves the files in `website/`. |
| `apps/desktop` | The desktop app. Tauri (Rust) in `src-tauri`, SvelteKit in `src`. Tray icon, Byte's popup, and the same dashboard pages as the website. |
| `adapters/claude-code`, `codex`, `cursor`, `antigravity` | A `hooks.json` each. The daemon merges it into the tool's own config. |
| `adapters/opencode` | A TypeScript plugin that runs `hindsight-daemon emit` for OpenCode. |
| `adapters/vscode` | A TypeScript extension for VS Code, Cursor and VSCodium that reports your typing to the local API. |
| `adapters/zed` | A Rust extension (built by Zed for WebAssembly, outside the workspace) that starts `hindsight-daemon lsp` as a language server. |

## The path of one event

1. **An adapter reports something**

    A hook fires or an extension notices you typed. The adapter hands the daemon a small event: a kind, a time, a project name and a few counts. It never hands over text. See [adding an adapter](/docs/developers/adding-an-adapter) for the ways in.

2. **The daemon checks it and stores it**

    `Event::check_text` in `hindsight-core` runs first. It refuses anything that carries text where text isn't allowed. What passes goes into a SQLite file, `hindsight.db`, in the daemon's data directory.

3. **The daemon seals batches**

    Pending events are sealed into a batch whose hash covers the previous batch's hash: `blake3(prev_hash || canonical_json(events))`. Change an old event and every hash after it breaks.

4. **The daemon uploads**

    Once a minute it asks `GET /api/v1/batches/head` what the server already has, then sends the rest with `POST /api/v1/batches`. It only does this once the computer is signed in.

5. **The server checks the chain and credits the time**

    The server checks that each batch links onto what it holds and that no event breaks the privacy rules. Then it works out the credited minutes itself with the same attention rules from `hindsight-core`. The daemon never reports totals. It does keep a local estimate for when the server isn't reachable.

6. **The server sends back a receipt**

    Each accepted upload returns a receipt: the server's clock, signed with a key only the server has. The daemon records it as an event, so it's sealed into the chain after everything before it. That's how the server knows an event wasn't back-dated: anything sealed after a receipt was recorded after the server issued it.

7. **The dashboard draws it**

    The website's pages (`/today`, `/projects`, `/usage` and the rest) are drawn on the server from the credited minutes. A WebSocket at `/ws` tells open pages when new events arrive.

## The daemon

`hindsight-daemon` is one binary with a few jobs.

- `run` starts the local API on `127.0.0.1:5292` and the background loops: sync every 60 seconds, history, presence (which app has focus, how long you've been idle) and the watcher for Zed's own agent.
- `emit --source <name>` is what agent hooks call. It reads a JSON payload on stdin, records events, prints nothing and always exits 0. A hook that crashed an agent would be worse than a missed event.
- `connect` and `disconnect` add and remove Hindsight from your tools. The installer runs `connect`, and so does the desktop app every time it starts.
- `login`, `sync`, `status`, `git-hook`, `install-git-hook` and `lsp` do what they say.

The daemon talks to the desktop app over its local API. The app's webview never sees the token: the Rust side of the app reads `local-token` from the data directory and makes the calls.

## The server

`hindsight-server` is an axum app on Postgres. On startup it runs the migrations in `crates/hindsight-server/migrations` and then, in the background, redoes everyone's stored time if the crediting rules changed (`RULES_VERSION` in `hindsight-core`, or the two windows in your settings).

Besides the daemon's endpoints, it also serves:

- the dashboard and landing page, drawn on the server;
- Hack Club sign-in, API keys, and Hindsight as an OAuth provider;
- the Review API and signed claims, which review programs read;
- an optional pass-through to a private admin panel at `/admin`.

The [API page](/docs/developers/api) lists the parts outsiders can call.

## One rule runs through all of it

Events never hold prompt text, code, file contents or file paths. The event metadata is a closed struct, so there's no field to put them in, and unknown fields are rejected when an event is read. Text becomes a length, a typed-versus-pasted ratio or a keyed hash. The one exception is what you deliberately write to Byte. See [contributing](/docs/developers/contributing#the-privacy-rule) for how that shapes changes.
