Skip to content

Latest commit

Β 

History

54 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” DevDocs β€” Developer Search Engine

TypeScript React 19 Vite Turso Vercel CI Tests

A production-grade developer documentation search engine built from first principles in TypeScript. Crawls web documentation across AI/ML, Frontend, Backend, and DevOps, indexes full-text content in Turso (distributed libSQL with FTS5), ranks queries with Okapi BM25 + Title Boost, protects servers with Sliding-Window Rate Limiting, and serves instant paginated results over a Vercel Serverless API with global Edge CDN Caching.

πŸ”— Live Production Demo: https://searchengine-jade.vercel.app


πŸ“Έ Overview

User Query: "usememo", "autograd", "dokcer"
                   β”‚
                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Vercel Edge Serverless                    β”‚
β”‚   β€’ IP-Based Sliding Window Rate Limiting (60 req/min)      β”‚
β”‚   β€’ Anti-DoS Input Guard (200 chars max)                    β”‚
β”‚   β€’ Dynamic "Did You Mean" via FTS5 Vocabulary (fts5vocab)  β”‚
β”‚   β€’ SQLite FTS5 Inverted Index Lookups (O(log N))           β”‚
β”‚   β€’ Okapi BM25 Ranking + Title & Category Affinity Boost    β”‚
β”‚   β€’ Server-Side Pagination & Word Snippet Highlighting      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β–Ό                             β–Ό
   Turso Cloud Database (libSQL)      Dynamic React 19 UI
   β€’ 1,300+ Indexed Documentation     β€’ Glassmorphic Dark Mode
   β€’ FTS5 Virtual Table + Triggers    β€’ Live Category Filters
   β€’ Atomic Batch Crawler Inserts     β€’ Interactive "Did You Mean"
   β€’ Health Check Endpoint (/health)  β€’ Pagination Controls & URL Sync

⚑ Key Engineering Features

1. πŸ•ΈοΈ Multi-Worker Asynchronous Web Crawler

  • Breadth-First Search (BFS): Explores documentation level-by-level using an asynchronous WorkerPool queue.
  • Politeness & Safety: Built-in per-domain RateLimiter, automatic robots.txt compliance parser, and polite DevDocsBot/1.0 User-Agent.
  • Incremental Crawling:
    • Tracks ETag and Last-Modified headers to handle HTTP 304 Not Modified and avoid redundant processing.
    • Purges dead pages automatically upon receiving 404 Not Found or 410 Gone.
  • HTML Boilerplate Stripping: Extracts clean text while discarding noise (<nav>, <header>, <footer>, <aside>, <script>, <style>).
  • Sitemap Auto-Discovery: Recursively discovers seed URLs from sitemap.xml.

2. 🎯 Information Retrieval & FTS5 Ranking Engine

  • SQLite FTS5 Inverted Index: Persistent inverted full-text index on Turso with automatic synchronization triggers (INSERT, UPDATE, DELETE).
  • Okapi BM25 ($k_1=1.2, b=0.75$): Length-normalized term frequency scoring with smoothed inverse document frequency (IDF).
  • Title & Category Boosting: Boosts relevance (+5.0 to +10.0) when search terms appear in document <title>, category tags, or URL slugs.
  • Dynamic Typo Tolerance ("Did You Mean?"): Queries Turso's live fts5vocab dictionary and applies Levenshtein edit distance to suggest real-time typo corrections without hardcoded word lists.
  • Phrase Matching & Highlighting: Multi-word phrase matching and sentence window generation with <mark> tags around matched tokens.

3. πŸ›‘οΈ Production Hardening & Abuse Prevention

  • Sliding-Window Rate Limiter: IP-based rate limiting (60 requests/minute per client IP) returning HTTP 429 Too Many Requests with standard Retry-After headers.
  • Input Validation: Rejects queries exceeding 200 characters with HTTP 400 Bad Request to prevent DoS attacks.
  • Server-Side Pagination: Robust page and limit support with clamped inputs preventing buffer overflow.
  • Health Check Endpoint (/health): Status probe for uptime monitors (Vercel, BetterStack) reporting database connectivity, document counts, and live response latency.
  • Atomic Batch Writes: Inserts crawled pages in single atomic client.batch(...) transactions, speeding up crawl operations by 10x.

4. 🎨 Developer-Centric React 19 UI

  • React 19 + TypeScript + Vite: Fast, responsive dark-mode interface.
  • Zero Manual Taxonomy Configuration: Categories and live document counts (e.g. AI / ML (198), Databases (118), React (100)) are dynamically aggregated from the database.
  • Deep Linking: Shareable URL query states (/?q=react&category=React&page=2) with smooth-scrolling pagination.

πŸ“Š Live Indexed Documentation (1,300+ Pages)

Domain / Ecosystem Frameworks & Sources
🧠 AI & Machine Learning PyTorch, LangChain, Hugging Face Transformers, Scikit-Learn
⚑ Frontend Frameworks React, Next.js, Angular, Vue.js, Tailwind CSS
🐍 Languages & Runtimes Python, TypeScript, Node.js, Rust, Go, C/C++, Web APIs (MDN)
πŸ› οΈ Backend & DevOps FastAPI, Express, Docker, Kubernetes, PostgreSQL, Redis

πŸ“ Repository Structure

.
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ ci.yml                    # Automated GitHub Actions CI (build & test)
β”‚   └── crawl.yml                 # Automated daily GitHub Actions crawler cron
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ search.ts                 # Vercel Serverless Search API (FTS5 + BM25 + Rate Limiter)
β”‚   └── healthCheck.ts            # System health status endpoint (/health)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ crawler/
β”‚   β”‚   β”œβ”€β”€ crawler.ts            # Orchestrator (BFS crawl loop)
β”‚   β”‚   β”œβ”€β”€ fetcher.ts            # HTTP client with timeouts, retries, 304 handling, User-Agent
β”‚   β”‚   β”œβ”€β”€ parser.ts             # HTML content & link extractor (Cheerio)
β”‚   β”‚   β”œβ”€β”€ rate-limiter.ts       # Per-domain rate limiter
β”‚   β”‚   β”œβ”€β”€ robots.ts             # robots.txt compliance validator
β”‚   β”‚   β”œβ”€β”€ sitemap.ts            # sitemap.xml parser
β”‚   β”‚   β”œβ”€β”€ url-frontier.ts       # URL deduplication and normalization
β”‚   β”‚   └── worker-pool.ts        # Concurrency worker pool
β”‚   β”œβ”€β”€ engine/
β”‚   β”‚   └── search-engine.ts      # Search engine coordinator
β”‚   β”œβ”€β”€ indexer/
β”‚   β”‚   β”œβ”€β”€ category.ts           # Dynamic domain/meta brand classifier
β”‚   β”‚   β”œβ”€β”€ inverted-index.ts     # Postings lists with term positions
β”‚   β”‚   β”œβ”€β”€ stemmer.ts            # Porter stemmer algorithm
β”‚   β”‚   └── tokenizer.ts          # Code-aware tokenization & abbreviation expansion
β”‚   β”œβ”€β”€ ranking/
β”‚   β”‚   β”œβ”€β”€ bm25.ts               # Okapi BM25 scoring formula
β”‚   β”‚   └── tfidf.ts              # TF-IDF scoring formula
β”‚   β”œβ”€β”€ retrieval/
β”‚   β”‚   β”œβ”€β”€ boolean.ts            # Boolean AND / OR retrieval
β”‚   β”‚   β”œβ”€β”€ levenshtein.ts        # Levenshtein typo tolerance algorithm
β”‚   β”‚   β”œβ”€β”€ phrase.ts             # Positional phrase matching
β”‚   β”‚   β”œβ”€β”€ snippet.ts            # Keyword snippet & <mark> highlighter
β”‚   β”‚   └── synonyms.ts           # Developer abbreviation mapping (js, ts, k8s, etc.)
β”‚   β”œβ”€β”€ store/
β”‚   β”‚   β”œβ”€β”€ sqlite-document-store.ts  # Local SQLite store (node:sqlite)
β”‚   β”‚   β”œβ”€β”€ sqlite-index-store.ts     # Persisted inverted index tables
β”‚   β”‚   └── turso-document-store.ts   # Turso cloud store (FTS5, triggers, batch writes)
β”‚   └── ui/
β”‚       β”œβ”€β”€ App.tsx               # React 19 search UI component (Pagination + Filters)
β”‚       β”œβ”€β”€ App.css               # Dark-mode styling and pagination layout
β”‚       └── main.tsx              # React DOM entrypoint
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ error-handling.test.ts    # Test suite for rate-limiting, DoS guards, FTS injection
β”‚   └── *.test.ts                 # 33 comprehensive unit & integration tests
β”œβ”€β”€ crawl-and-index.ts            # Multi-seed documentation crawl script
β”œβ”€β”€ db-cli.ts                     # CLI query tool for inspecting Turso database
β”œβ”€β”€ setup-fts.ts                  # One-time FTS5 virtual table & vocabulary setup script
β”œβ”€β”€ vite.config.ts                # Vite dev server with integrated API middleware
β”œβ”€β”€ vercel.json                   # Vercel deployment routing & rewrites
└── package.json                  # Dependencies, test runner, and build scripts

πŸš€ Getting Started Locally

Prerequisites

  • Node.js: $\ge 22.0.0$
  • pnpm: $\ge 9.0.0$

1. Installation

git clone https://github.com/Souma061/Search-Engine.git
cd Search-Engine
pnpm install

2. Environment Setup (Optional for Cloud DB)

Create a .env file in the root directory:

TURSO_DATABASE_URL=libsql://your-database.turso.io
TURSO_AUTH_TOKEN=your-turso-token

(If omitted, the crawler and local testing will automatically use the local SQLite file index.db)

3. Start Frontend & Search API

# Starts unified Vite server (UI on http://localhost:3000, API on /search & /health)
pnpm run dev

4. Run the Documentation Crawler

# Crawls documentation seeds into Turso cloud DB
pnpm run crawl

5. Query the Database via CLI

# Inspect Turso tables and query terms from terminal
pnpm run db "SELECT title, rank FROM docs_fts WHERE docs_fts MATCH 'react' ORDER BY rank LIMIT 5;"

πŸ§ͺ Testing & Reliability Suite

Run all 39 automated tests (unit, integration, crawler, ranking, and error resilience):

pnpm test
βœ” detectCategory detects framework from URL hostname (1.63ms)
βœ” search engine filters results by category (2.22ms)
βœ” Error Handling: Query exceeding max length returns 400 (1.25ms)
βœ” Error Handling: Special FTS5 characters do not crash query engine (5.62ms)
βœ” Error Handling: Invalid pagination values are safely sanitized (0.47ms)
βœ” Error Handling: Rate limiter triggers 429 on abuse (5.02ms)
βœ” Error Handling: Health check handles request and reports status (111.8ms)
βœ” incremental crawl handles 304 Not Modified and 404 Purging (107.9ms)
βœ” crawl β†’ store β†’ index β†’ search end to end (562.6ms)
βœ” levenshteinDistance calculates correct edit operations (0.99ms)
βœ” suggestCorrection suggests closest indexed term for typos (2.36ms)
βœ” BM25 OR search returns sorted scores (1.52ms)
βœ” parseSitemap extracts loc URLs and lastmod timestamps from XML (3.54ms)
βœ” generateSnippet extracts surrounding text window and highlights query words (1.30ms)
...
β„Ή tests 39 | pass 39 | fail 0

πŸ“œ Available NPM Scripts

Script Command Description
pnpm run dev vite Starts Vite React frontend & integrated backend API on localhost:3000
pnpm run build vite build Compiles production bundle into dist/
pnpm run crawl tsx crawl-and-index.ts Runs multi-seed crawler, batch-inserts into Turso, and syncs FTS index
pnpm run db tsx db-cli.ts Terminal CLI tool to query Turso cloud database
pnpm run seed tsx seed-demo.ts Populates local demo documents into index.db
pnpm test node --test test/*.test.ts Runs native Node.js test runner

πŸ—ΊοΈ Roadmap & Future Enhancements

  • Phase 1: Code-aware tokenizer, BM25 scoring, and Porter stemmer.
  • Phase 2: Incremental crawling with HTTP 304 ETag validation, 404 purging, and DevDocsBot User-Agent.
  • Phase 3: Turso distributed cloud database migration & Vercel Edge Serverless Functions.
  • Phase 4: SQLite FTS5 inverted index, auto-sync triggers, and dynamic vocabulary (fts5vocab).
  • Phase 5: Production rate limiting (60 req/min), DoS input guards, and server-side pagination.
  • Phase 6: Automated daily GitHub Actions crawl cron and CI test/build pipeline.
  • Phase 7 (Upcoming): AI Overview (AIO) layer using Retrieval-Augmented Generation (RAG) to synthesize direct code explanations from top retrieved snippets.

πŸ“„ License

MIT License. Free to use, study, and modify.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages