# boredmayonnaise/smart-autocomplete architecture

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

- Interactive diagram: https://gitdiagram.com/boredmayonnaise/smart-autocomplete
- Repository: https://github.com/boredmayonnaise/smart-autocomplete

## Overview

SmartAutocomplete is a local C++ teaching editor for trie prefix lookup, Levenshtein distance, and KMP search. The user edits text or supplies algorithm inputs; the browser requests C++ results or traces, then displays and replays them. Dictionary replacement and usage-based ranking are another user-facing capability. The sampled code shows the server-to-API call and core algorithm implementations; endpoint-to-algorithm wiring is supported by the README, while several UI and API details are unsampled.

Main entry points: [`src/web/api.cpp`](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/web/api.cpp) (HTTP API), [`static/app.js`](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/app.js) (Editor UI), [`src/core/dictionary.cpp`](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp) (Trie and ranking), [`src/main.cpp`](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/main.cpp) (Crow server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_editor["Editor and visualization"]
  node_browser_ui["Editor UI<br/>[app.js]"]
  node_page["Editor page<br/>[index.html]"]
  node_ui_styles["Layout and styles<br/>[style.css]"]
  node_visualization["Trace replay and views<br/>[app.js]"]
end

subgraph group_server["HTTP application"]
  node_server_main["Crow server<br/>[main.cpp]"]
  node_api["HTTP API<br/>[api.cpp]"]
  node_api_contract["API contract<br/>[api.hpp]"]
end

subgraph group_core["Core algorithms"]
  node_prefix_lookup["Trie prefix lookup<br/>[dictionary.cpp]"]
  node_fuzzy_suggestions["Fuzzy suggestions<br/>[dictionary.cpp]"]
  node_edit_distance["Levenshtein trace<br/>[algorithms.cpp]"]
  node_kmp_search["KMP trace and matches<br/>[algorithms.cpp]"]
end

subgraph group_vocabulary["Vocabulary and text"]
  node_dictionary["Trie and ranking<br/>[dictionary.cpp]"]
  node_word_list["Bundled vocabulary<br/>[words.txt]"]
  node_text["Unicode text handling<br/>[text.cpp]"]
  node_core_types["Core types and limits<br/>[core.hpp]"]
end

node_user(("User"))

node_user -->|"edits and selects"| node_browser_ui
node_page -->|"loads script"| node_browser_ui
node_page -->|"loads styles"| node_ui_styles
node_browser_ui -->|"requests results and traces"| node_api
node_api -->|"returns JSON"| node_browser_ui
node_browser_ui -->|"replays traces"| node_visualization
node_user -->|"steps and switches views"| node_visualization
node_server_main -->|"dispatches requests"| node_api
node_server_main -->|"loads vocabulary"| node_word_list
node_server_main -->|"serves assets"| node_page
node_api -->|"implements interface"| node_api_contract
node_api -->|"requests completions"| node_prefix_lookup
node_api -->|"requests spelling candidates"| node_fuzzy_suggestions
node_api -->|"requests distance trace"| node_edit_distance
node_api -->|"requests search trace"| node_kmp_search
node_api -->|"replaces and updates usage"| node_dictionary
node_dictionary -->|"builds vocabulary from"| node_word_list
node_prefix_lookup -->|"reads trie and cache"| node_dictionary
node_fuzzy_suggestions -->|"searches trie words"| node_dictionary
node_api -.->|"uses text conversion"| node_text
node_edit_distance -->|"uses trace and result types"| node_core_types
node_kmp_search -->|"uses search and trace types"| node_core_types

click node_browser_ui "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/app.js"
click node_page "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/index.html"
click node_ui_styles "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/style.css"
click node_visualization "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/app.js"
click node_server_main "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/main.cpp"
click node_api "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/web/api.cpp"
click node_api_contract "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/web/api.hpp"
click node_dictionary "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp"
click node_word_list "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/data/words.txt"
click node_text "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/text.cpp"
click node_core_types "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/include/smartautocomplete/core.hpp"
click node_prefix_lookup "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp"
click node_fuzzy_suggestions "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp"
click node_edit_distance "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/algorithms.cpp"
click node_kmp_search "https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/algorithms.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_browser_ui,node_page,node_ui_styles,node_visualization,node_user toneBlue
class node_server_main,node_api,node_api_contract toneAmber
class node_prefix_lookup,node_fuzzy_suggestions,node_edit_distance,node_kmp_search toneMint
class node_dictionary,node_word_list,node_text,node_core_types toneRose
```

## Components

### Editor and visualization

- [Editor UI](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/app.js): `static/app.js`
- [Editor page](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/index.html): `static/index.html`
- [Layout and styles](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/style.css): `static/style.css`
- [Trace replay and views](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/static/app.js): `static/app.js`

### HTTP application

- [Crow server](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/main.cpp): `src/main.cpp`
- [HTTP API](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/web/api.cpp): `src/web/api.cpp`
- [API contract](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/web/api.hpp): `src/web/api.hpp`

### Core algorithms

- [Trie prefix lookup](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp): `src/core/dictionary.cpp`
- [Fuzzy suggestions](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp): `src/core/dictionary.cpp`
- [Levenshtein trace](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/algorithms.cpp): `src/core/algorithms.cpp`
- [KMP trace and matches](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/algorithms.cpp): `src/core/algorithms.cpp`

### Vocabulary and text

- [Trie and ranking](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/dictionary.cpp): `src/core/dictionary.cpp`
- [Bundled vocabulary](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/data/words.txt): `data/words.txt`
- [Unicode text handling](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/src/core/text.cpp): `src/core/text.cpp`
- [Core types and limits](https://github.com/boredmayonnaise/smart-autocomplete/blob/master/include/smartautocomplete/core.hpp): `include/smartautocomplete/core.hpp`

### Other components

- **User**

## Connections

- User → Editor UI: edits and selects (evidence: `README.md`)
- Editor page → Editor UI: loads script
- Editor page → Layout and styles: loads styles
- Editor UI → HTTP API: requests results and traces (evidence: `static/app.js`)
- HTTP API → Editor UI: returns JSON (evidence: `README.md`)
- Editor UI → Trace replay and views: replays traces (evidence: `README.md`)
- User → Trace replay and views: steps and switches views (evidence: `README.md`)
- Crow server → HTTP API: dispatches requests (evidence: `src/main.cpp`)
- Crow server → Bundled vocabulary: loads vocabulary (evidence: `src/main.cpp`)
- Crow server → Editor page: serves assets (evidence: `src/main.cpp`)
- HTTP API → API contract: implements interface (evidence: `src/web/api.cpp`)
- HTTP API → Trie prefix lookup: requests completions (evidence: `README.md`)
- HTTP API → Fuzzy suggestions: requests spelling candidates (evidence: `README.md`)
- HTTP API → Levenshtein trace: requests distance trace (evidence: `README.md`)
- HTTP API → KMP trace and matches: requests search trace (evidence: `README.md`)
- HTTP API → Trie and ranking: replaces and updates usage (evidence: `README.md`)
- Trie and ranking → Bundled vocabulary: builds vocabulary from
- Trie prefix lookup → Trie and ranking: reads trie and cache (evidence: `src/core/dictionary.cpp`)
- Fuzzy suggestions → Trie and ranking: searches trie words (evidence: `src/core/dictionary.cpp`)
- HTTP API → Unicode text handling: uses text conversion
- Levenshtein trace → Core types and limits: uses trace and result types (evidence: `src/core/algorithms.cpp`)
- KMP trace and matches → Core types and limits: uses search and trace types (evidence: `src/core/algorithms.cpp`)
