# erenoozr/searchcraft architecture

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

- Interactive diagram: https://gitdiagram.com/erenoozr/searchcraft
- Repository: https://github.com/erenoozr/searchcraft

## Overview

SearchCraft is an in-memory Python search engine. A user submits a query through the CLI or library API; the engine parses it, evaluates Boolean and phrase logic against the positional index, scores matches with BM25, and returns ranked results with snippets. Document ingestion uses the same text pipeline to populate the index. The README documents the demo dataset and capabilities; some CLI and result-construction details fall in omitted source excerpts, so those links are not asserted as verified calls.

Main entry points: [`searchcraft.py`](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py) (SearchEngine), [`dataset.py`](https://github.com/erenoozr/searchcraft/blob/main/dataset.py) (Demo documents)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Text and Index"]
  node_demo_data["Demo documents<br/>[dataset.py]"]
  node_pipeline["Text pipeline<br/>[searchcraft.py]"]
  node_index[("Positional index<br/>[searchcraft.py]")]
end

subgraph group_query["Query and Ranking"]
  node_parser["Query parser<br/>[searchcraft.py]"]
  node_ast["Boolean AST<br/>[searchcraft.py]"]
  node_scorer["BM25 scorer<br/>[searchcraft.py]"]
end

subgraph group_interface["Search Interface"]
  node_cli["CLI shell<br/>[searchcraft.py]"]
  node_engine["SearchEngine<br/>[searchcraft.py]"]
  node_results["Ranked results<br/>[searchcraft.py]"]
  node_snippets["Match snippets<br/>[searchcraft.py]"]
end

node_user(("Search user"))

node_user -->|"runs query"| node_cli
node_user -->|"calls API"| node_engine
node_cli -.->|"submits query"| node_engine
node_engine -->|"creates"| node_index
node_engine -->|"creates"| node_scorer
node_engine -->|"creates"| node_parser
node_engine -->|"adds documents"| node_index
node_index -->|"analyzes text"| node_pipeline
node_engine -->|"parses query"| node_parser
node_parser -.->|"analyzes terms"| node_pipeline
node_engine -->|"evaluates query"| node_ast
node_ast -->|"scores matches"| node_scorer
node_scorer -->|"reads postings"| node_index
node_engine -.->|"ranks matches"| node_results
node_engine -.->|"builds snippets"| node_snippets
node_index -->|"reads document spans"| node_snippets
node_cli -.->|"loads demo corpus"| node_demo_data

click node_cli "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_engine "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_demo_data "https://github.com/erenoozr/searchcraft/blob/main/dataset.py"
click node_pipeline "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_index "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_parser "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_ast "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_scorer "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_results "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py"
click node_snippets "https://github.com/erenoozr/searchcraft/blob/main/searchcraft.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_demo_data,node_pipeline,node_index,node_user toneBlue
class node_parser,node_ast,node_scorer toneAmber
class node_cli,node_engine,node_results,node_snippets toneMint
```

## Components

### Text and Index

- [Demo documents](https://github.com/erenoozr/searchcraft/blob/main/dataset.py): `dataset.py`
- [Text pipeline](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`
- [Positional index](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`

### Query and Ranking

- [Query parser](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`
- [Boolean AST](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`
- [BM25 scorer](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`

### Search Interface

- [CLI shell](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`
- [SearchEngine](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`
- [Ranked results](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`
- [Match snippets](https://github.com/erenoozr/searchcraft/blob/main/searchcraft.py): `searchcraft.py`

### Other components

- **Search user**

## Connections

- Search user → CLI shell: runs query (evidence: `README.md`)
- Search user → SearchEngine: calls API (evidence: `README.md`)
- CLI shell → SearchEngine: submits query (evidence: `searchcraft.py`)
- SearchEngine → Positional index: creates (evidence: `searchcraft.py`)
- SearchEngine → BM25 scorer: creates (evidence: `searchcraft.py`)
- SearchEngine → Query parser: creates (evidence: `searchcraft.py`)
- SearchEngine → Positional index: adds documents (evidence: `searchcraft.py`)
- Positional index → Text pipeline: analyzes text (evidence: `searchcraft.py`)
- SearchEngine → Query parser: parses query (evidence: `searchcraft.py`)
- Query parser → Text pipeline: analyzes terms (evidence: `searchcraft.py`)
- SearchEngine → Boolean AST: evaluates query (evidence: `searchcraft.py`)
- Boolean AST → BM25 scorer: scores matches (evidence: `searchcraft.py`)
- BM25 scorer → Positional index: reads postings (evidence: `searchcraft.py`)
- SearchEngine → Ranked results: ranks matches (evidence: `searchcraft.py`)
- SearchEngine → Match snippets: builds snippets (evidence: `searchcraft.py`)
- Positional index → Match snippets: reads document spans (evidence: `searchcraft.py`)
- CLI shell → Demo documents: loads demo corpus (evidence: `searchcraft.py`)
