# kpnc0/localmind architecture

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

- Interactive diagram: https://gitdiagram.com/kpnc0/localmind
- Repository: https://github.com/kpnc0/localmind

## Overview

LocalMind is a local semantic-search CLI. Its principal workflow is to read supported files from a watch folder, extract text, embed passages, and save or incrementally reuse vectors in an on-disk index; search embeds a query, ranks indexed passages by cosine similarity, and prints file results with optional snippets. The README documents these capabilities, but the CLI orchestration and extraction implementation were not excerpted, so workflow edges rely on the README rather than inspected call sites.

Main entry points: [`src/main.rs`](https://github.com/kpnc0/localmind/blob/main/src/main.rs) (Command handling), [`src/embed.rs`](https://github.com/kpnc0/localmind/blob/main/src/embed.rs) (Passage embedding), [`src/index.rs`](https://github.com/kpnc0/localmind/blob/main/src/index.rs) (Binary index), [`src/extract.rs`](https://github.com/kpnc0/localmind/blob/main/src/extract.rs) (Text extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and results"]
  node_cli["Command handling<br/>[main.rs]"]
  node_output["Terminal results<br/>[main.rs]"]
  node_snippets["Snippet formatting<br/>[snippet.rs]"]
end

subgraph group_ingest["Document ingestion"]
  node_watch["Watch folder"]
  node_extract["Text extraction<br/>[extract.rs]"]
end

subgraph group_semantic["Semantic processing"]
  node_embed["Passage embedding<br/>[embed.rs]"]
  node_model["Embedding model"]
  node_queryvec["Query embedding<br/>[embed.rs]"]
  node_rank["Vector ranking<br/>[search.rs]"]
  node_hf["Hugging Face"]
end

subgraph group_storage["Index storage"]
  node_index[("Binary index<br/>[index.rs]")]
  node_reuse["Incremental reuse<br/>[index.rs]"]
end

node_user(("CLI user"))

node_user -->|"runs commands"| node_cli
node_cli -->|"selects folder"| node_watch
node_watch -->|"supplies files"| node_extract
node_extract -->|"provides text"| node_embed
node_embed -->|"computes vectors"| node_model
node_cli -->|"writes or opens"| node_index
node_index -->|"provides cached records"| node_reuse
node_reuse -->|"avoids re-embedding"| node_embed
node_cli -->|"embeds query"| node_queryvec
node_queryvec -->|"computes vector"| node_model
node_cli -->|"requests search"| node_rank
node_index -->|"provides vectors"| node_rank
node_rank -->|"returns ranked files"| node_output
node_cli -->|"prints results"| node_output
node_output -->|"formats optional snippets"| node_snippets
node_snippets -->|"reads file text"| node_extract
node_embed -.->|"downloads model files"| node_hf

click node_cli "https://github.com/kpnc0/localmind/blob/main/src/main.rs"
click node_output "https://github.com/kpnc0/localmind/blob/main/src/main.rs"
click node_extract "https://github.com/kpnc0/localmind/blob/main/src/extract.rs"
click node_snippets "https://github.com/kpnc0/localmind/blob/main/src/snippet.rs"
click node_embed "https://github.com/kpnc0/localmind/blob/main/src/embed.rs"
click node_queryvec "https://github.com/kpnc0/localmind/blob/main/src/embed.rs"
click node_rank "https://github.com/kpnc0/localmind/blob/main/src/search.rs"
click node_index "https://github.com/kpnc0/localmind/blob/main/src/index.rs"
click node_reuse "https://github.com/kpnc0/localmind/blob/main/src/index.rs"

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_cli,node_output,node_snippets,node_user toneBlue
class node_watch,node_extract toneAmber
class node_embed,node_model,node_queryvec,node_rank,node_hf toneMint
class node_index,node_reuse toneRose
```

## Components

### CLI and results

- [Command handling](https://github.com/kpnc0/localmind/blob/main/src/main.rs): `src/main.rs`
- [Terminal results](https://github.com/kpnc0/localmind/blob/main/src/main.rs): `src/main.rs`
- [Snippet formatting](https://github.com/kpnc0/localmind/blob/main/src/snippet.rs): `src/snippet.rs`

### Document ingestion

- **Watch folder**
- [Text extraction](https://github.com/kpnc0/localmind/blob/main/src/extract.rs): `src/extract.rs`

### Semantic processing

- [Passage embedding](https://github.com/kpnc0/localmind/blob/main/src/embed.rs): `src/embed.rs`
- **Embedding model**
- [Query embedding](https://github.com/kpnc0/localmind/blob/main/src/embed.rs): `src/embed.rs`
- [Vector ranking](https://github.com/kpnc0/localmind/blob/main/src/search.rs): `src/search.rs`
- **Hugging Face**

### Index storage

- [Binary index](https://github.com/kpnc0/localmind/blob/main/src/index.rs): `src/index.rs`
- [Incremental reuse](https://github.com/kpnc0/localmind/blob/main/src/index.rs): `src/index.rs`

### Other components

- **CLI user**

## Connections

- CLI user → Command handling: runs commands (evidence: `Readme.md`)
- Command handling → Watch folder: selects folder (evidence: `Readme.md`)
- Watch folder → Text extraction: supplies files (evidence: `Readme.md`)
- Text extraction → Passage embedding: provides text (evidence: `Readme.md`)
- Passage embedding → Embedding model: computes vectors (evidence: `Readme.md`)
- Command handling → Binary index: writes or opens (evidence: `Readme.md`)
- Binary index → Incremental reuse: provides cached records (evidence: `Readme.md`)
- Incremental reuse → Passage embedding: avoids re-embedding (evidence: `Readme.md`)
- Command handling → Query embedding: embeds query (evidence: `Readme.md`)
- Query embedding → Embedding model: computes vector (evidence: `Readme.md`)
- Command handling → Vector ranking: requests search (evidence: `Readme.md`)
- Binary index → Vector ranking: provides vectors (evidence: `Readme.md`)
- Vector ranking → Terminal results: returns ranked files (evidence: `Readme.md`)
- Command handling → Terminal results: prints results (evidence: `Readme.md`)
- Terminal results → Snippet formatting: formats optional snippets (evidence: `Readme.md`)
- Snippet formatting → Text extraction: reads file text (evidence: `src/snippet.rs`)
- Passage embedding → Hugging Face: downloads model files (evidence: `src/embed.rs`)
