Smart Autocomplete System is a lightweight C++ project that provides fast, in-memory prefix suggestions using a Trie data structure and a small REST API. A tiny web frontend demonstrates the live suggestion behavior and communicates with the C++ backend.
- Overview
- Features
- Repository layout
- Build & Run (Quickstart)
- API Endpoints
- Internals
- Data files & format
- Testing
- Extending & Contributing
- Assumptions & Notes
- License
This repository implements a small, fast autocomplete engine in C++:
- A Trie-based index for prefix search and top-k suggestions.
- Merges a base dictionary and user-specific history and boosts suggestions using frequency counts.
- A lightweight REST API (C++ server) exposes suggestion endpoints used by a single-page frontend under
frontend/.
Use cases: IDE-like word completion, search box suggestions, or small local services needing low-latency prefix queries.
- Fast prefix lookup using a Trie (memory-backed).
- Merge of base dictionaries and per-user history with simple frequency boosting.
- Small REST API for querying suggestions and updating user history.
- Minimal demo frontend to exercise the API.
include/— bundled third-party headers (asio, crow, etc.).src/— main project sources (Trie, TrieNode, Web API server).frontend/— demo single-page UI (index.html,app.js,style.css).data/— dictionaries and user data (data/dictionaries/,data/user_data/).tests/— small test programs and helper utilities.makefile— build script.build/— (optional) build output (may be created bymake).
Prerequisites:
- A C++17-capable compiler (e.g. g++ 7+).
makeandpthreadsupport (the makefile uses-pthread).
Build:
makeNotes on the produced binary:
- Many repositories put the built binary either at
./autocomplete_systemor underbuild/. Ifmakecreatesbuild/, check there. If the binary is not found, list files withls -laand check themakefilefor the exact output name.
Run (example):
# try either of these depending on your makefile
./autocomplete_system
# or
./build/autocomplete_systemOpen the demo frontend:
- Open
frontend/index.htmlin a browser, or - If the server serves the UI over HTTP, point your browser to the server host/port shown in the server log output.
Inspect src/WebAPI.cpp for exact route paths and request/response shapes. Typical endpoints you can expect:
GET /suggest?prefix=<prefix>&k=<k>— returns top-k suggestions forprefix(JSON array/object).POST /user_history— add/update entries in user history (JSON payload).
Exact JSON structures are defined in src/WebAPI.cpp; open that file to confirm required fields and HTTP verbs.
- Trie implementation is split across
src/Trie.cppandsrc/TrieNode.cpp.TrieNode::autoCompleteperforms traversal and collects top-k suggestions (priority selection / DFS).TrieNode::getAllWithPrefixenumerates completions for a given prefix.
src/Trie.cppcontains higher-level logic to load dictionaries, merge with user history, and apply boosting to ranks.- The server layer in
src/WebAPI.cppadapts HTTP requests to trie queries and handles user-history updates.
Edge cases handled (typical):
- Empty prefix — either return empty suggestions or a default hot-list.
- Large k values — your trie traversal may cap results; check
khandling inTrieNode::autoComplete. - Non-ASCII inputs — ensure your dictionary and trie support UTF-8 if needed.
- Base dictionaries:
data/dictionaries/— plain text files (likelyword frequencyor one word per line depending on loader implementation). - User-specific data:
data/user_data/— per-user persisted search counts and custom additions.
To add a new dictionary, place a file in data/dictionaries/ and confirm the loader in src/Trie.cpp picks it up (or add it to the loader list).
There are small test programs under tests/ (for example tests/test.cpp and tests/insert.cpp). To compile/run a single test quickly:
g++ -std=c++17 -Iinclude tests/test.cpp -o test_run
./test_runFor full test integration, see the makefile (it may include targets for test or similar).
- Add new dictionaries to
data/dictionaries/and update loader logic insrc/Trie.cppif necessary. - To change ranking/boosting, update the merge logic in
src/Trie.cppwhere user history and dictionary frequencies are combined. - Add unit tests under
tests/that exercise new behavior. - Ensure new code compiles with
-std=c++17and keep third-party header licenses intact ininclude/.
Suggested small improvements (low-risk):
- Add a
LICENSEfile to the repository. - Add a
make testtarget (if not already present) that runs the simple tests. - Add a small
scripts/helper to seeddata/for demos.
- I did not run
makein this session; themakefileis present and the original README referred to building withmake. If your build produces the binary in a different path, update this README accordingly. - If the server binds to a fixed port, check
src/WebAPI.cppfor the configured port and any environment or CLI overrides.