# nanonets/graft architecture

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

- Interactive diagram: https://gitdiagram.com/nanonets/graft
- Repository: https://github.com/nanonets/graft

## Overview

Trail-code is a local context layer for coding agents: it builds a code-and-call graph, finds relevant code for prompts, and carries team learnings between sessions. The README documents agent hooks, checks, search/orientation, and visualization as product capabilities. Sampled source confirms the engine’s build/query operations and MCP server, but several other branches are represented only by README statements; their edges cite that documentation.

Main entry points: [`src/engine.ts`](https://github.com/nanonets/graft/blob/main/src/engine.ts) (Context engine), [`src/notes/notes.ts`](https://github.com/nanonets/graft/blob/main/src/notes/notes.ts) (Learning notes), [`src/graph/build.ts`](https://github.com/nanonets/graft/blob/main/src/graph/build.ts) (Graph build), [`src/context/build.ts`](https://github.com/nanonets/graft/blob/main/src/context/build.ts) (Context build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_map["Code map"]
  node_engine["Context engine<br/>[engine.ts]"]
  node_graphbuild["Graph build<br/>[build.ts]"]
  node_extract["Code extraction<br/>[extract.ts]"]
  node_contextbuild["Context build<br/>[build.ts]"]
  node_llm["Model adapters<br/>[openai.ts]"]
  node_ask["Code retrieval<br/>[ask.ts]"]
  node_blast["Impact analysis<br/>[blast.ts]"]
  node_search["Code search<br/>[grep.ts]"]
  node_visualization["Graph visualization<br/>[assemble.ts]"]
  node_viewer["Interactive viewer<br/>[main.ts]"]
end

subgraph group_learnings["Learnings"]
  node_notes["Learning notes<br/>[notes.ts]"]
  node_coldstart["Initial learnings<br/>[cold-start.ts]"]
  node_learningcheck["Decision checks<br/>[local-check.ts]"]
  node_overlap["Edit overlap<br/>[edit-overlap.ts]"]
end

subgraph group_agent["Agent access"]
  node_cli["CLI entry<br/>[cli.ts]"]
end

subgraph group_integrations["Agent integrations"]
  node_hooks["Session hooks<br/>[hooks.ts]"]
  node_hostsetup["Agent setup<br/>[init.ts]"]
  node_mcp["MCP server<br/>[server.ts]"]
end

subgraph group_team["Team workflows"]
  node_cloud["Workspace sync<br/>[workspace-sync.ts]"]
  node_review["Pull request review<br/>[pr-reviews.ts]"]
end

node_developer(("Developer or agent"))

node_developer -->|"runs commands"| node_cli
node_cli -->|"invokes operations"| node_engine
node_engine -->|"builds graph"| node_graphbuild
node_graphbuild -.->|"extracts symbols"| node_extract
node_engine -->|"builds context"| node_contextbuild
node_contextbuild -.->|"summarizes content"| node_llm
node_engine -->|"retrieves code"| node_ask
node_developer -->|"queries code"| node_ask
node_developer -->|"requests impact"| node_blast
node_developer -->|"searches code"| node_search
node_developer -->|"views map"| node_visualization
node_visualization -.->|"serves visualization"| node_viewer
node_developer -->|"saves learnings"| node_notes
node_notes -->|"supplies decisions"| node_learningcheck
node_developer -->|"checks changes"| node_learningcheck
node_notes -.->|"seeds learnings"| node_coldstart
node_developer -->|"edits code"| node_overlap
node_hostsetup -.->|"installs hooks"| node_hooks
node_developer -->|"sets up agents"| node_hostsetup
node_developer -->|"uses agent tools"| node_mcp
node_notes -.->|"syncs workspace"| node_cloud
node_developer -->|"learns from reviews"| node_review

click node_cli "https://github.com/nanonets/graft/blob/main/src/cli.ts"
click node_engine "https://github.com/nanonets/graft/blob/main/src/engine.ts"
click node_graphbuild "https://github.com/nanonets/graft/blob/main/src/graph/build.ts"
click node_extract "https://github.com/nanonets/graft/blob/main/src/graph/extract.ts"
click node_contextbuild "https://github.com/nanonets/graft/blob/main/src/context/build.ts"
click node_llm "https://github.com/nanonets/graft/blob/main/src/ai/llm/openai.ts"
click node_ask "https://github.com/nanonets/graft/blob/main/src/ask/ask.ts"
click node_blast "https://github.com/nanonets/graft/blob/main/src/blast/blast.ts"
click node_search "https://github.com/nanonets/graft/blob/main/src/search/grep.ts"
click node_visualization "https://github.com/nanonets/graft/blob/main/src/viz/assemble.ts"
click node_viewer "https://github.com/nanonets/graft/blob/main/viewer/main.ts"
click node_notes "https://github.com/nanonets/graft/blob/main/src/notes/notes.ts"
click node_coldstart "https://github.com/nanonets/graft/blob/main/src/notes/cold-start.ts"
click node_learningcheck "https://github.com/nanonets/graft/blob/main/src/check/local-check.ts"
click node_overlap "https://github.com/nanonets/graft/blob/main/src/notes/edit-overlap.ts"
click node_hooks "https://github.com/nanonets/graft/blob/main/src/claude/hooks.ts"
click node_hostsetup "https://github.com/nanonets/graft/blob/main/src/hosts/init.ts"
click node_mcp "https://github.com/nanonets/graft/blob/main/src/mcp/server.ts"
click node_cloud "https://github.com/nanonets/graft/blob/main/src/cloud/workspace-sync.ts"
click node_review "https://github.com/nanonets/graft/blob/main/src/notes/pr-reviews.ts"

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_engine,node_graphbuild,node_extract,node_contextbuild,node_llm,node_ask,node_blast,node_search,node_visualization,node_viewer toneBlue
class node_notes,node_coldstart,node_learningcheck,node_overlap toneAmber
class node_cli toneMint
class node_hooks,node_hostsetup,node_mcp toneRose
class node_cloud,node_review,node_developer toneIndigo
```

## Components

### Code map

- [Context engine](https://github.com/nanonets/graft/blob/main/src/engine.ts): `src/engine.ts`
- [Graph build](https://github.com/nanonets/graft/blob/main/src/graph/build.ts): `src/graph/build.ts`
- [Code extraction](https://github.com/nanonets/graft/blob/main/src/graph/extract.ts): `src/graph/extract.ts`
- [Context build](https://github.com/nanonets/graft/blob/main/src/context/build.ts): `src/context/build.ts`
- [Model adapters](https://github.com/nanonets/graft/blob/main/src/ai/llm/openai.ts): `src/ai/llm/openai.ts`
- [Code retrieval](https://github.com/nanonets/graft/blob/main/src/ask/ask.ts): `src/ask/ask.ts`
- [Impact analysis](https://github.com/nanonets/graft/blob/main/src/blast/blast.ts): `src/blast/blast.ts`
- [Code search](https://github.com/nanonets/graft/blob/main/src/search/grep.ts): `src/search/grep.ts`
- [Graph visualization](https://github.com/nanonets/graft/blob/main/src/viz/assemble.ts): `src/viz/assemble.ts`
- [Interactive viewer](https://github.com/nanonets/graft/blob/main/viewer/main.ts): `viewer/main.ts`

### Learnings

- [Learning notes](https://github.com/nanonets/graft/blob/main/src/notes/notes.ts): `src/notes/notes.ts`
- [Initial learnings](https://github.com/nanonets/graft/blob/main/src/notes/cold-start.ts): `src/notes/cold-start.ts`
- [Decision checks](https://github.com/nanonets/graft/blob/main/src/check/local-check.ts): `src/check/local-check.ts`
- [Edit overlap](https://github.com/nanonets/graft/blob/main/src/notes/edit-overlap.ts): `src/notes/edit-overlap.ts`

### Agent access

- [CLI entry](https://github.com/nanonets/graft/blob/main/src/cli.ts): `src/cli.ts`

### Agent integrations

- [Session hooks](https://github.com/nanonets/graft/blob/main/src/claude/hooks.ts): `src/claude/hooks.ts`
- [Agent setup](https://github.com/nanonets/graft/blob/main/src/hosts/init.ts): `src/hosts/init.ts`
- [MCP server](https://github.com/nanonets/graft/blob/main/src/mcp/server.ts): `src/mcp/server.ts`

### Team workflows

- [Workspace sync](https://github.com/nanonets/graft/blob/main/src/cloud/workspace-sync.ts): `src/cloud/workspace-sync.ts`
- [Pull request review](https://github.com/nanonets/graft/blob/main/src/notes/pr-reviews.ts): `src/notes/pr-reviews.ts`

### Other components

- **Developer or agent**

## Connections

- Developer or agent → CLI entry: runs commands (evidence: `README.md`)
- CLI entry → Context engine: invokes operations (evidence: `src/engine.ts`)
- Context engine → Graph build: builds graph (evidence: `src/engine.ts`)
- Graph build → Code extraction: extracts symbols
- Context engine → Context build: builds context (evidence: `src/engine.ts`)
- Context build → Model adapters: summarizes content
- Context engine → Code retrieval: retrieves code (evidence: `src/engine.ts`)
- Developer or agent → Code retrieval: queries code (evidence: `README.md`)
- Developer or agent → Impact analysis: requests impact (evidence: `README.md`)
- Developer or agent → Code search: searches code (evidence: `README.md`)
- Developer or agent → Graph visualization: views map (evidence: `README.md`)
- Graph visualization → Interactive viewer: serves visualization
- Developer or agent → Learning notes: saves learnings (evidence: `README.md`)
- Learning notes → Decision checks: supplies decisions (evidence: `src/check/local-check.ts`)
- Developer or agent → Decision checks: checks changes (evidence: `README.md`)
- Learning notes → Initial learnings: seeds learnings
- Developer or agent → Edit overlap: edits code (evidence: `README.md`)
- Agent setup → Session hooks: installs hooks
- Developer or agent → Agent setup: sets up agents (evidence: `README.md`)
- Developer or agent → MCP server: uses agent tools (evidence: `src/mcp/server.ts`)
- Learning notes → Workspace sync: syncs workspace
- Developer or agent → Pull request review: learns from reviews (evidence: `README.md`)
