# tomfran/search-rs architecture

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

- Interactive diagram: https://gitdiagram.com/tomfran/search-rs
- Repository: https://github.com/tomfran/search-rs

## Overview

Search-rs builds a disk-backed index from a document collection, then answers Boolean or free-text queries; free-text results use BM25 and window scoring, with vocabulary-based spelling correction. Its web interface is a second entry point for querying. The graph preserves the documented web and ranking capabilities, but server-to-engine wiring is not shown in the excerpts, so that connection is marked unverified. Other links are based on the README or shown calls and imports.

Main entry points: [`search/src/engine/builder.rs`](https://github.com/tomfran/search-rs/blob/main/search/src/engine/builder.rs) (Collection builder), [`search/src/engine/mod.rs`](https://github.com/tomfran/search-rs/blob/main/search/src/engine/mod.rs) (Search engine), [`search/src/engine/postings.rs`](https://github.com/tomfran/search-rs/blob/main/search/src/engine/postings.rs) (Postings access and operators), [`search/src/engine/vocabulary.rs`](https://github.com/tomfran/search-rs/blob/main/search/src/engine/vocabulary.rs) (Vocabulary and correction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI commands<br/>[main.rs]"]
  node_web["Web server<br/>[main.rs]"]
  node_templates["Web templates"]
end

subgraph group_indexing["Index construction"]
  node_builder["Collection builder<br/>[builder.rs]"]
  node_preprocessor["Tokenization and stemming<br/>[preprocessor.rs]"]
  node_filewalk["Document traversal<br/>[file_utils.rs]"]
end

subgraph group_query["Query engine"]
  node_engine["Search engine<br/>[mod.rs]"]
  node_vocabulary["Vocabulary and correction<br/>[vocabulary.rs]"]
  node_postings["Postings access and operators<br/>[postings.rs]"]
  node_cache["Postings cache<br/>[postings_cache.rs]"]
  node_heap["Result ranking heap<br/>[heap.rs]"]
end

subgraph group_storage["Index storage"]
  node_documents["Document metadata<br/>[documents.rs]"]
  node_indexfiles[("On-disk index files")]
  node_reader["Bitstream reader<br/>[bits_reader.rs]"]
  node_writer["Bitstream writer<br/>[bits_writer.rs]"]
end

node_operator(("Search user"))

node_operator -->|"builds collection"| node_cli
node_operator -->|"submits queries"| node_web
node_cli -->|"builds index"| node_builder
node_web -.->|"serves interface"| node_templates
node_web -.->|"routes queries"| node_engine
node_builder -->|"walks documents"| node_filewalk
node_builder -->|"tokenizes documents"| node_preprocessor
node_builder -->|"writes postings"| node_postings
node_builder -->|"writes vocabulary"| node_vocabulary
node_builder -->|"writes metadata"| node_documents
node_postings -->|"reads and writes"| node_indexfiles
node_vocabulary -->|"reads and writes"| node_indexfiles
node_documents -->|"reads and writes"| node_indexfiles
node_postings -->|"decodes lists"| node_reader
node_postings -->|"encodes lists"| node_writer
node_vocabulary -->|"loads vocabulary"| node_reader
node_vocabulary -->|"stores vocabulary"| node_writer
node_documents -->|"loads metadata"| node_reader
node_documents -->|"stores metadata"| node_writer
node_engine -->|"normalizes queries"| node_preprocessor
node_engine -->|"corrects terms"| node_vocabulary
node_engine -->|"loads term lists"| node_postings
node_engine -->|"gets document data"| node_documents
node_engine -->|"ranks results"| node_heap
node_postings -->|"caches lists"| node_cache

click node_cli "https://github.com/tomfran/search-rs/blob/main/search/src/main.rs"
click node_web "https://github.com/tomfran/search-rs/blob/main/server/src/main.rs"
click node_templates "https://github.com/tomfran/search-rs/tree/main/server/templates"
click node_builder "https://github.com/tomfran/search-rs/blob/main/search/src/engine/builder.rs"
click node_preprocessor "https://github.com/tomfran/search-rs/blob/main/search/src/engine/preprocessor.rs"
click node_filewalk "https://github.com/tomfran/search-rs/blob/main/search/src/disk/file_utils.rs"
click node_engine "https://github.com/tomfran/search-rs/blob/main/search/src/engine/mod.rs"
click node_vocabulary "https://github.com/tomfran/search-rs/blob/main/search/src/engine/vocabulary.rs"
click node_postings "https://github.com/tomfran/search-rs/blob/main/search/src/engine/postings.rs"
click node_cache "https://github.com/tomfran/search-rs/blob/main/search/src/engine/postings_cache.rs"
click node_heap "https://github.com/tomfran/search-rs/blob/main/search/src/engine/heap.rs"
click node_documents "https://github.com/tomfran/search-rs/blob/main/search/src/engine/documents.rs"
click node_reader "https://github.com/tomfran/search-rs/blob/main/search/src/disk/bits_reader.rs"
click node_writer "https://github.com/tomfran/search-rs/blob/main/search/src/disk/bits_writer.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_web,node_templates,node_operator toneBlue
class node_builder,node_preprocessor,node_filewalk toneAmber
class node_engine,node_vocabulary,node_postings,node_cache,node_heap toneMint
class node_documents,node_indexfiles,node_reader,node_writer toneRose
```

## Components

### User interfaces

- [CLI commands](https://github.com/tomfran/search-rs/blob/main/search/src/main.rs): `search/src/main.rs`
- [Web server](https://github.com/tomfran/search-rs/blob/main/server/src/main.rs): `server/src/main.rs`
- [Web templates](https://github.com/tomfran/search-rs/tree/main/server/templates): `server/templates`

### Index construction

- [Collection builder](https://github.com/tomfran/search-rs/blob/main/search/src/engine/builder.rs): `search/src/engine/builder.rs`
- [Tokenization and stemming](https://github.com/tomfran/search-rs/blob/main/search/src/engine/preprocessor.rs): `search/src/engine/preprocessor.rs`
- [Document traversal](https://github.com/tomfran/search-rs/blob/main/search/src/disk/file_utils.rs): `search/src/disk/file_utils.rs`

### Query engine

- [Search engine](https://github.com/tomfran/search-rs/blob/main/search/src/engine/mod.rs): `search/src/engine/mod.rs`
- [Vocabulary and correction](https://github.com/tomfran/search-rs/blob/main/search/src/engine/vocabulary.rs): `search/src/engine/vocabulary.rs`
- [Postings access and operators](https://github.com/tomfran/search-rs/blob/main/search/src/engine/postings.rs): `search/src/engine/postings.rs`
- [Postings cache](https://github.com/tomfran/search-rs/blob/main/search/src/engine/postings_cache.rs): `search/src/engine/postings_cache.rs`
- [Result ranking heap](https://github.com/tomfran/search-rs/blob/main/search/src/engine/heap.rs): `search/src/engine/heap.rs`

### Index storage

- [Document metadata](https://github.com/tomfran/search-rs/blob/main/search/src/engine/documents.rs): `search/src/engine/documents.rs`
- **On-disk index files**
- [Bitstream reader](https://github.com/tomfran/search-rs/blob/main/search/src/disk/bits_reader.rs): `search/src/disk/bits_reader.rs`
- [Bitstream writer](https://github.com/tomfran/search-rs/blob/main/search/src/disk/bits_writer.rs): `search/src/disk/bits_writer.rs`

### Other components

- **Search user**

## Connections

- Search user → CLI commands: builds collection (evidence: `README.md`)
- Search user → Web server: submits queries (evidence: `README.md`)
- CLI commands → Collection builder: builds index (evidence: `README.md`)
- Web server → Web templates: serves interface
- Web server → Search engine: routes queries
- Collection builder → Document traversal: walks documents (evidence: `search/src/engine/builder.rs`)
- Collection builder → Tokenization and stemming: tokenizes documents (evidence: `search/src/engine/builder.rs`)
- Collection builder → Postings access and operators: writes postings (evidence: `search/src/engine/builder.rs`)
- Collection builder → Vocabulary and correction: writes vocabulary (evidence: `search/src/engine/builder.rs`)
- Collection builder → Document metadata: writes metadata (evidence: `search/src/engine/builder.rs`)
- Postings access and operators → On-disk index files: reads and writes (evidence: `search/src/engine/postings.rs`)
- Vocabulary and correction → On-disk index files: reads and writes (evidence: `search/src/engine/vocabulary.rs`)
- Document metadata → On-disk index files: reads and writes (evidence: `search/src/engine/documents.rs`)
- Postings access and operators → Bitstream reader: decodes lists (evidence: `search/src/engine/postings.rs`)
- Postings access and operators → Bitstream writer: encodes lists (evidence: `search/src/engine/postings.rs`)
- Vocabulary and correction → Bitstream reader: loads vocabulary (evidence: `search/src/engine/vocabulary.rs`)
- Vocabulary and correction → Bitstream writer: stores vocabulary (evidence: `search/src/engine/vocabulary.rs`)
- Document metadata → Bitstream reader: loads metadata (evidence: `search/src/engine/documents.rs`)
- Document metadata → Bitstream writer: stores metadata (evidence: `search/src/engine/documents.rs`)
- Search engine → Tokenization and stemming: normalizes queries (evidence: `search/src/engine/mod.rs`)
- Search engine → Vocabulary and correction: corrects terms (evidence: `README.md`)
- Search engine → Postings access and operators: loads term lists (evidence: `search/src/engine/mod.rs`)
- Search engine → Document metadata: gets document data (evidence: `search/src/engine/mod.rs`)
- Search engine → Result ranking heap: ranks results (evidence: `search/src/engine/mod.rs`)
- Postings access and operators → Postings cache: caches lists (evidence: `search/src/engine/postings.rs`)
