How prajexec/searchcraft works
SearchCraft is a local-first TypeScript search service: clients create named indexes, submit documents or bounded NDJSON batches, and query ranked results. Writes persist source documents and durable jobs in SQLite; a worker applies changes to custom indexes and immutable segments, while search uses BM25, filters, phrase matching, and cursor pagination. The documented product also includes reindexing, compaction, snapshots, job inspection, and operational endpoints. Edges reflect README statements or shown source references/calls; some maintenance wiring is documented but not shown in sampled implementation.
Main entry points: app.ts HTTP routes · index-manager.ts Index manager · index-worker.ts Index worker · inverted-index.ts Inverted index
Components 22
HTTP API
- HTTP routes
src/app.ts - Bulk parser
src/http/bulk.ts - OpenAPI contract
src/http/openapi.ts
Durable State
- Source documents
src/storage/documents.ts - Indexing jobs
src/storage/jobs.ts - SQLite database
src/storage/sqlite.ts
Search Engine
- Index manager
src/indexes/index-manager.ts - Index configuration
src/indexes/index-config.ts - Index worker
src/workers/index-worker.ts - Inverted index
src/indexing/inverted-index.ts - Tokenizer
src/indexing/tokenizer.ts - BM25 ranking
src/query/bm25.ts - Search filters
src/query/filters.ts - Immutable segments
src/indexing/segment.ts - Position compression
src/indexing/compression.ts - Term dictionary
src/indexing/term-dictionary.ts
Operations
- Runtime config
src/config.ts - Snapshot archives
src/storage/snapshots.ts - Structured logging
src/observability/logger.ts - Metrics
src/observability/metrics.ts
Other components
- Application client
- Local disk
Connections 30
- Application client → HTTP routes: sends requests
README.md - HTTP routes → Bulk parser: parses batches
src/app.ts - HTTP routes → Index manager: routes operations
src/app.ts - HTTP routes → Search filters: parses filters
src/app.ts - HTTP routes → OpenAPI contract: serves contract
src/app.ts - HTTP routes → Runtime config: uses limits
src/app.ts - Index manager → Index configuration: validates config
src/indexes/index-manager.ts - Index manager → Source documents: mutates documents
src/indexes/index-manager.ts - Index manager → Indexing jobs: manages jobs
src/indexes/index-manager.ts - Source documents → SQLite database: persists source
- Indexing jobs → SQLite database: persists queue
- Index worker → Indexing jobs: claims jobs
src/workers/index-worker.ts - Index worker → Source documents: loads documents
src/workers/index-worker.ts - Index worker → Index manager: publishes updates
src/workers/index-worker.ts - Index manager → Inverted index: searches index
src/indexes/index-manager.ts - Inverted index → Tokenizer: tokenizes text
src/indexing/inverted-index.ts - Inverted index → BM25 ranking: scores candidates
src/indexing/inverted-index.ts - Inverted index → Search filters: filters matches
src/indexing/inverted-index.ts - Inverted index → Position compression: encodes positions
src/indexing/inverted-index.ts - Immutable segments → Position compression: decodes positions
src/indexing/segment.ts - Immutable segments → Term dictionary: validates blocks
src/indexing/segment.ts - Index manager → Immutable segments: loads generations
src/indexes/index-manager.ts - Index manager → Local disk: stores index data
README.md - Snapshot archives → Immutable segments: archives index data
src/storage/snapshots.ts - Snapshot archives → Local disk: stores archives
- HTTP routes → Metrics: reports metrics
src/app.ts - Index worker → Metrics: records outcomes
src/workers/index-worker.ts - Index worker → Structured logging: logs events
src/workers/index-worker.ts - HTTP routes → Structured logging: logs requests
src/app.ts - HTTP routes → Application client: returns results
README.md