Full-stack system for code/text indexing and search powered by advanced data structures:
- Trie for prefix autocomplete
- Suffix Array for substring pattern matching
- Segment Tree for range frequency analytics
React (frontend) -> Express API (backend) -> C++ executable (core engine) -> file storage and indexing layer
ADSA_Project/
src/ # React frontend
backend/src/ # Express API and engine bridge
core/ # C++ engine + data structure implementations
engine.cpp
trie.cpp
suffix_array.cpp
segment_tree.cpp
data/files/ # Stored uploaded files + metadata index
temp_io/ # Reserved for optional temp IPC files
./engine search prefix <query> <file_path>
./engine search substring <query> <file_path>
./engine analytics <word> <l> <r> <file_path>
./engine update <line_number> <new_content> <file_path>
All responses are JSON-compatible via stdout.
POST /upload- multipart file field:
file - returns
file_id
- multipart file field:
GET /search?file_id=...&query=...&type=prefix|substringGET /analytics?file_id=...&word=...&l=1&r=20POST /update- JSON body:
{ file_id, line_number, new_content }
- JSON body:
GET /filesGET /files/:fileIdGET /health
- Install JavaScript dependencies:
npm install- Build the C++ core:
npm run build:engine- Run frontend + backend together:
npm run dev:fullFrontend runs at http://localhost:5173 and backend at http://localhost:5000.
- Drag-and-drop upload
- Debounced live search
- Prefix / substring mode switch
- Line-numbered viewer with query highlighting
- Range analytics panel
- Line update + re-index action
- Ranked search results
- Prefix lookup:
$O(L)$ traversal on the trie - Substring lookup: binary search over suffix array, roughly
$O(m \log n)$ - Segment tree query/update:
$O(\log n)$
The standalone executable is stateless between invocations, so the backend controls persisted files while the engine rebuilds in-memory structures per command for correctness and modularity.
"Empty response from http://localhost:5173/api/files"
Symptoms: File list won't load, shows "Failed to load files" error or "Empty response" in console.
Root Causes & Solutions:
-
Backend is not running:
# Terminal 2: Start backend npm run dev:backend- Backend MUST be running on http://localhost:5000
- Check terminal for:
Backend API listening on http://localhost:5000
-
Frontend port changed (5173 → 5174+ if port in use):
- If 5173 is occupied, Vite auto-increments to 5174, 5175, etc.
- Use the actual port shown in your terminal
- Frontend proxy routes
/api/*requests to backend:5000 - Both must be running for the app to work
-
Proxy not routing correctly:
- Clear Vite dev cache and restart:
# Kill both servers (Ctrl+C) rm -r node_modules/.vite npm run dev:full
- Clear Vite dev cache and restart:
-
Direct connectivity test:
# Test backend directly Invoke-WebRequest http://localhost:5000/files -UseBasicParsing # Test through frontend proxy Invoke-WebRequest http://localhost:5174/api/files -UseBasicParsing
-
Wait for both servers to fully start:
- After
npm run dev:frontend, wait 1-2 seconds - After
npm run dev:backend, wait 1-2 seconds - Refresh browser if it loads too early
- After
Quick Diagnostic:
- Open browser DevTools (F12)
- Go to Console tab
- Look for error message details
- Check Network tab to see if
/api/filesrequest is being sent - Share error details if stuck
Symptoms: Upload button shows "Uploading and indexing file..." but then error appears.
Solutions:
-
Verify both servers are running:
# Terminal 1: Frontend npm run dev:frontend # Terminal 2: Backend npm run dev:backend
- Frontend should be on http://localhost:5173 (or 5174+ if ports taken)
- Backend should be on http://localhost:5000
-
Check backend logs for upload errors:
- Look for
[UPLOAD]messages in backend terminal - Verify
data/files/directory exists and is writable - Check
data/files/index.jsonis not corrupted
- Look for
-
Use Browser DevTools to debug:
- Press F12 → Network tab
- Perform an upload
- Click
/api/uploadrequest - Check Response tab for actual JSON error (not HTML)
- Check Console tab for any parse errors
-
Verify file compatibility:
- Use text-based files only (.txt, .md, .cpp, .js, .py, .java, .json, .csv)
- Binary files will cause parsing errors
- Maximum file size: 50MB
-
Full reset if stuck:
# Stop both servers (Ctrl+C) # Clear uploaded files rm data/files/*.txt # Restart both servers npm run dev:frontend npm run dev:backend # Try uploading again
# Find and kill process using the port
netstat -ano | findstr :5000 # or :5173 for frontend
taskkill /PID <PID> /F
# Then restart
npm run dev:backendnpm run build:engineThis compiles the C++ search engine from source. Requires g++ compiler.
- Maximum file size is 50MB
- Split larger files into chunks
- Use gzip compression for text before uploading if needed
- Confirm file was indexed: check file appears in file list
- Try simple prefix search (e.g., type "a" or "the")
- Verify file contains text in UTF-8 format
- Check backend logs for engine errors
- For very large files (>10MB), first search will be slower as engine builds indices
- Subsequent searches on same file are cached in-memory by React component
- Try substring search if prefix search is slow (suffix array can be faster for patterns)
npm run dev:fullThis runs frontend (5173/5174) + backend (5000) concurrently.
npm run build # Frontend
npm run build:engine # C++ (if needed)Output: dist/ folder contains production-ready React bundle.
src/— React UI components + CSSbackend/src/— Express server + file storage + engine bridgecore/— C++ source + compiledenginebinarydata/files/— Uploaded files +index.jsonmetadatapublic/— Static assets
All endpoints return JSON with ok field:
{
"ok": true,
"data": {...}
}Or on error:
{
"ok": false,
"error": "Human-readable error message"
}