# moth-logic/cherreader architecture

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

- Interactive diagram: https://gitdiagram.com/moth-logic/cherreader
- Repository: https://github.com/moth-logic/cherreader

## Overview

Cherreader is a C++17 console text indexer. The user selects a text file; the application retains original lines, tokenizes and indexes words, then offers prefix, exact-word, word-length, and frequency queries with optional line text and screen or file output. The README documents the workflow and capabilities; sampled source shows the Trie and its supporting structures, but some loading and menu code was omitted, so those links rely on README statements.

Main entry points: [`ConsoleApplication1.cpp`](https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp) (Query handling), [`ArrayList.h`](https://github.com/moth-logic/cherreader/blob/main/ArrayList.h) (Original lines), [`Trie.h`](https://github.com/moth-logic/cherreader/blob/main/Trie.h) (Word index), [`BSTreeDictionary.h`](https://github.com/moth-logic/cherreader/blob/main/BSTreeDictionary.h) (Child dictionary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application workflow"]
  node_app["Console workflow"]
  node_load["Load and tokenize"]
  node_queries["Query handling"]
  node_ignore["Ignore-word filter"]
end

subgraph group_index["Text index"]
  node_lines["Original lines<br/>[ArrayList.h]"]
  node_trie["Word index<br/>[Trie.h]"]
  node_trienode["Trie nodes<br/>[TrieNode.h]"]
  node_heap["Frequency max-heap<br/>[MaxHeap.h]"]
end

subgraph group_structures["Data structures"]
  node_dictionary["Child dictionary<br/>[BSTreeDictionary.h]"]
  node_bst["Search tree<br/>[BSTree.h]"]
  node_bstnode["Tree nodes<br/>[BSTNode.h]"]
  node_pair["Key-value pairs<br/>[Pair.h]"]
  node_listapi["List interface<br/>[List.h]"]
  node_linkedlist["Doubly linked list<br/>[DoubleLinkedList.h]"]
  node_listnode["List nodes<br/>[DoubleNode.h]"]
  node_dictionaryapi["Dictionary interface<br/>[Dictionary.h]"]
end

subgraph group_output["Results"]
  node_output["Formatted results"]
end

node_user(("Console user"))
node_textfile["Text input"]
node_outputfile["Result text file"]
node_ignorefile["Ignore words file"]

node_user -->|"chooses file and query"| node_app
node_textfile -->|"provides text"| node_load
node_app -->|"loads and tokenizes"| node_load
node_load -->|"stores original lines"| node_lines
node_load -->|"inserts words and lines"| node_trie
node_app -->|"dispatches queries"| node_queries
node_queries -->|"searches index"| node_trie
node_queries -->|"retrieves line text"| node_lines
node_queries -->|"requests top words"| node_ignore
node_ignorefile -->|"supplies excluded words"| node_ignore
node_ignore -->|"filters frequencies"| node_trie
node_ignore -->|"loads filtered frequencies"| node_heap
node_queries -->|"formats query results"| node_output
node_heap -->|"provides top words"| node_output
node_lines -->|"provides original text"| node_output
node_output -->|"prints results"| node_user
node_output -->|"writes results"| node_outputfile
node_trie -->|"traverses and updates"| node_trienode
node_trienode -->|"stores child nodes"| node_dictionary
node_dictionary -->|"stores key-value pairs"| node_bst
node_bst -->|"organizes tree nodes"| node_bstnode
node_bst -->|"orders elements"| node_pair
node_dictionary -->|"creates pairs"| node_pair
node_dictionary -->|"implements interface"| node_dictionaryapi
node_trienode -->|"stores lines and children lists"| node_linkedlist
node_trie -->|"builds result lists"| node_linkedlist
node_linkedlist -->|"implements interface"| node_listapi
node_linkedlist -->|"links nodes"| node_listnode
node_lines -->|"implements interface"| node_listapi
node_heap -->|"stores heap array"| node_lines

click node_app "https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp"
click node_load "https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp"
click node_queries "https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp"
click node_ignore "https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp"
click node_lines "https://github.com/moth-logic/cherreader/blob/main/ArrayList.h"
click node_trie "https://github.com/moth-logic/cherreader/blob/main/Trie.h"
click node_trienode "https://github.com/moth-logic/cherreader/blob/main/TrieNode.h"
click node_dictionary "https://github.com/moth-logic/cherreader/blob/main/BSTreeDictionary.h"
click node_bst "https://github.com/moth-logic/cherreader/blob/main/BSTree.h"
click node_bstnode "https://github.com/moth-logic/cherreader/blob/main/BSTNode.h"
click node_pair "https://github.com/moth-logic/cherreader/blob/main/Pair.h"
click node_listapi "https://github.com/moth-logic/cherreader/blob/main/List.h"
click node_linkedlist "https://github.com/moth-logic/cherreader/blob/main/DoubleLinkedList.h"
click node_listnode "https://github.com/moth-logic/cherreader/blob/main/DoubleNode.h"
click node_dictionaryapi "https://github.com/moth-logic/cherreader/blob/main/Dictionary.h"
click node_heap "https://github.com/moth-logic/cherreader/blob/main/MaxHeap.h"
click node_output "https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp"

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_app,node_load,node_queries,node_ignore,node_user toneBlue
class node_lines,node_trie,node_trienode,node_heap toneAmber
class node_dictionary,node_bst,node_bstnode,node_pair,node_listapi,node_linkedlist,node_listnode,node_dictionaryapi toneMint
class node_output toneRose
class node_textfile,node_outputfile,node_ignorefile toneIndigo
```

## Components

### Application workflow

- [Console workflow](https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp): `ConsoleApplication1.cpp`
- [Load and tokenize](https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp): `ConsoleApplication1.cpp`
- [Query handling](https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp): `ConsoleApplication1.cpp`
- [Ignore-word filter](https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp): `ConsoleApplication1.cpp`

### Text index

- [Original lines](https://github.com/moth-logic/cherreader/blob/main/ArrayList.h): `ArrayList.h`
- [Word index](https://github.com/moth-logic/cherreader/blob/main/Trie.h): `Trie.h`
- [Trie nodes](https://github.com/moth-logic/cherreader/blob/main/TrieNode.h): `TrieNode.h`
- [Frequency max-heap](https://github.com/moth-logic/cherreader/blob/main/MaxHeap.h): `MaxHeap.h`

### Data structures

- [Child dictionary](https://github.com/moth-logic/cherreader/blob/main/BSTreeDictionary.h): `BSTreeDictionary.h`
- [Search tree](https://github.com/moth-logic/cherreader/blob/main/BSTree.h): `BSTree.h`
- [Tree nodes](https://github.com/moth-logic/cherreader/blob/main/BSTNode.h): `BSTNode.h`
- [Key-value pairs](https://github.com/moth-logic/cherreader/blob/main/Pair.h): `Pair.h`
- [List interface](https://github.com/moth-logic/cherreader/blob/main/List.h): `List.h`
- [Doubly linked list](https://github.com/moth-logic/cherreader/blob/main/DoubleLinkedList.h): `DoubleLinkedList.h`
- [List nodes](https://github.com/moth-logic/cherreader/blob/main/DoubleNode.h): `DoubleNode.h`
- [Dictionary interface](https://github.com/moth-logic/cherreader/blob/main/Dictionary.h): `Dictionary.h`

### Results

- [Formatted results](https://github.com/moth-logic/cherreader/blob/main/ConsoleApplication1.cpp): `ConsoleApplication1.cpp`

### Other components

- **Console user**
- **Text input**
- **Result text file**
- **Ignore words file**

## Connections

- Console user → Console workflow: chooses file and query (evidence: `README.md`)
- Text input → Load and tokenize: provides text (evidence: `README.md`)
- Console workflow → Load and tokenize: loads and tokenizes (evidence: `README.md`)
- Load and tokenize → Original lines: stores original lines (evidence: `README.md`)
- Load and tokenize → Word index: inserts words and lines (evidence: `README.md`)
- Console workflow → Query handling: dispatches queries (evidence: `README.md`)
- Query handling → Word index: searches index (evidence: `README.md`)
- Query handling → Original lines: retrieves line text (evidence: `ConsoleApplication1.cpp`)
- Query handling → Ignore-word filter: requests top words (evidence: `README.md`)
- Ignore words file → Ignore-word filter: supplies excluded words (evidence: `README.md`)
- Ignore-word filter → Word index: filters frequencies (evidence: `README.md`)
- Ignore-word filter → Frequency max-heap: loads filtered frequencies (evidence: `README.md`)
- Query handling → Formatted results: formats query results (evidence: `ConsoleApplication1.cpp`)
- Frequency max-heap → Formatted results: provides top words (evidence: `README.md`)
- Original lines → Formatted results: provides original text (evidence: `ConsoleApplication1.cpp`)
- Formatted results → Console user: prints results (evidence: `README.md`)
- Formatted results → Result text file: writes results (evidence: `ConsoleApplication1.cpp`)
- Word index → Trie nodes: traverses and updates (evidence: `Trie.h`)
- Trie nodes → Child dictionary: stores child nodes (evidence: `TrieNode.h`)
- Child dictionary → Search tree: stores key-value pairs (evidence: `BSTreeDictionary.h`)
- Search tree → Tree nodes: organizes tree nodes (evidence: `BSTree.h`)
- Search tree → Key-value pairs: orders elements (evidence: `BSTreeDictionary.h`)
- Child dictionary → Key-value pairs: creates pairs (evidence: `BSTreeDictionary.h`)
- Child dictionary → Dictionary interface: implements interface (evidence: `BSTreeDictionary.h`)
- Trie nodes → Doubly linked list: stores lines and children lists (evidence: `TrieNode.h`)
- Word index → Doubly linked list: builds result lists (evidence: `Trie.h`)
- Doubly linked list → List interface: implements interface (evidence: `DoubleLinkedList.h`)
- Doubly linked list → List nodes: links nodes (evidence: `DoubleLinkedList.h`)
- Original lines → List interface: implements interface (evidence: `ArrayList.h`)
- Frequency max-heap → Original lines: stores heap array (evidence: `MaxHeap.h`)
