# jrtrj/searchengine architecture

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

- Interactive diagram: https://gitdiagram.com/jrtrj/searchengine
- Repository: https://github.com/jrtrj/searchengine

## Overview

This is a small Go search-engine demo: its command creates three hard-coded documents, indexes their body text, searches a hard-coded query, and prints matching document IDs. The index tokenizes both document bodies and queries, storing term-to-posting lists in memory; search returns sorted IDs. Titles are modeled but not indexed, and there is no persistent storage or interactive input. The graph reflects the sampled implementation, not additional search capabilities.

Main entry points: [`internal/index/index.go`](https://github.com/jrtrj/searchengine/blob/main/internal/index/index.go) (Inverted index), [`cmd/searchengine/main.go`](https://github.com/jrtrj/searchengine/blob/main/cmd/searchengine/main.go) (Demo entry point), [`internal/tokenizer/tokenizer.go`](https://github.com/jrtrj/searchengine/blob/main/internal/tokenizer/tokenizer.go) (Tokenizer), [`internal/model/document.go`](https://github.com/jrtrj/searchengine/blob/main/internal/model/document.go) (Document model)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_main["Demo entry point<br/>[main.go]"]
node_document["Document model<br/>[document.go]"]
node_index["Inverted index<br/>[index.go]"]
node_index_state[("Term postings<br/>[index.go]")]
node_tokenizer["Tokenizer<br/>[tokenizer.go]"]
node_terminal(("Terminal output"))

node_main -->|"creates"| node_document
node_main -->|"adds documents"| node_index
node_main -->|"searches"| node_index
node_index -->|"tokenizes bodies"| node_tokenizer
node_index -->|"tokenizes query"| node_tokenizer
node_index -->|"writes postings"| node_index_state
node_index -->|"reads postings"| node_index_state
node_index -->|"returns IDs"| node_main
node_main -->|"prints results"| node_terminal

click node_main "https://github.com/jrtrj/searchengine/blob/main/cmd/searchengine/main.go"
click node_document "https://github.com/jrtrj/searchengine/blob/main/internal/model/document.go"
click node_index "https://github.com/jrtrj/searchengine/blob/main/internal/index/index.go"
click node_index_state "https://github.com/jrtrj/searchengine/blob/main/internal/index/index.go"
click node_tokenizer "https://github.com/jrtrj/searchengine/blob/main/internal/tokenizer/tokenizer.go"

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_main,node_index,node_tokenizer toneTeal
class node_document,node_terminal toneIndigo
class node_index_state toneAmber
```

## Components

### Other components

- [Demo entry point](https://github.com/jrtrj/searchengine/blob/main/cmd/searchengine/main.go): `cmd/searchengine/main.go`
- [Document model](https://github.com/jrtrj/searchengine/blob/main/internal/model/document.go): `internal/model/document.go`
- [Inverted index](https://github.com/jrtrj/searchengine/blob/main/internal/index/index.go): `internal/index/index.go`
- [Term postings](https://github.com/jrtrj/searchengine/blob/main/internal/index/index.go): `internal/index/index.go`
- [Tokenizer](https://github.com/jrtrj/searchengine/blob/main/internal/tokenizer/tokenizer.go): `internal/tokenizer/tokenizer.go`
- **Terminal output**

## Connections

- Demo entry point → Document model: creates
- Demo entry point → Inverted index: adds documents
- Demo entry point → Inverted index: searches
- Inverted index → Tokenizer: tokenizes bodies
- Inverted index → Tokenizer: tokenizes query
- Inverted index → Term postings: writes postings
- Inverted index → Term postings: reads postings
- Inverted index → Demo entry point: returns IDs
- Demo entry point → Terminal output: prints results
