Skip to content

Commit caeac4d

Browse files
committed
Update README.md
1 parent 98d7446 commit caeac4d

1 file changed

Lines changed: 129 additions & 23 deletions

File tree

‎README.md‎

Lines changed: 129 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,142 @@
1-
### The Great Web Heist of Talha
1+
# Brightwave-Style Crawler Project
22

3-
This repository contains a small, AI-assisted **web crawler and search engine** built for the BLG 483E Artificial Intelligence Aided Computer Engineering course. The system consists of a Python backend that crawls and indexes pages plus a React dashboard that lets you start crawls, run searches, and watch system metrics (queue depth, processed URLs, backpressure state) in real time.
3+
This project implements a single-machine web crawler and keyword search engine with a live dashboard. It is designed to satisfy the assignment requirements around:
44

5-
#### Running the backend
5+
- indexing from an origin URL up to depth `k`,
6+
- avoiding duplicate page visits,
7+
- running search while indexing is active,
8+
- managing load with backpressure and rate limiting,
9+
- exposing simple controls and observability in a UI,
10+
- and supporting resume after interruption.
611

7-
1. Create and activate a virtualenv (optional but recommended).
8-
2. Install Python dependencies:
12+
The system has two major parts:
913

10-
```bash
11-
pip install -r requirements.txt
12-
```
14+
- **Crawler service**: creates and runs crawl jobs, supports pause/resume, tracks queue and worker state, and persists job state.
15+
- **Search service**: indexes crawled pages and answers queries with relevant URLs and metadata.
1316

14-
3. Start the backend on `localhost:8000`:
17+
## What The System Does
1518

16-
```bash
17-
uvicorn backend.app:app --reload
18-
```
19+
### 1) Indexing
1920

20-
#### Running the frontend
21+
When you submit an indexing request (`origin`, `k`), the backend creates a crawl job and starts worker tasks.
2122

22-
1. Install Node dependencies:
23+
- URL normalization resolves relative links, removes fragments, and keeps only `http`/`https`.
24+
- Each job tracks `visited` URLs to ensure the same URL is not fetched twice.
25+
- Discovered links are enqueued with incremented depth until `depth <= k`.
2326

24-
```bash
25-
cd frontend
26-
npm install
27-
```
27+
### 2) Search
2828

29-
2. Start the React dev server on `localhost:5173`:
29+
Search uses an in-memory inverted index built from page title and body text.
3030

31-
```bash
32-
npm run dev
33-
```
31+
- Tokenization is regex-based and case-insensitive.
32+
- Results include `relevant_url`, `origin_url`, and `depth` (plus score/title for UI visibility).
33+
- Search is available while crawlers are still running, so newly indexed pages appear as they are discovered.
34+
- `I'm Feeling Lucky` picks a **random** result from matches and opens it.
3435

35-
3. Open the printed URL in your browser. Use the **Index Control** panel to start a crawl, then use the **Search** and **System Dashboard** panels to explore the index and view runtime metrics.
36+
### 3) Runtime Controls and Visibility
37+
38+
The dashboard allows:
39+
40+
- creating crawl jobs,
41+
- pausing and resuming existing jobs,
42+
- changing **global queue limit** across all jobs,
43+
- changing **per-job request rate** live from each job card,
44+
- inspecting detailed job state (frontier preview, counters, recent events),
45+
- viewing global metrics (processed/discovered/duplicates/failed, queue pressure, workers).
46+
47+
## Architecture Summary
48+
49+
- **Backend**: FastAPI + asyncio + standard library networking (`urllib`) + SQLite persistence.
50+
- **Frontend**: React + TypeScript + Vite.
51+
- **Persistence**:
52+
- `pages` table for indexed page snapshots,
53+
- `jobs` table for job metadata and counters,
54+
- `job_visited` and `job_frontier` for resumable crawl state,
55+
- `job_events` for job timeline details.
56+
57+
## API Endpoints
58+
59+
### Index/Search
60+
61+
- `POST /index`
62+
Starts a new crawl job with origin URL, depth `k`, and optional initial rate limit.
63+
64+
- `GET /search?query=...&limit=...`
65+
Returns relevant indexed URLs.
66+
67+
### Job Control and Details
68+
69+
- `GET /jobs/{job_id}`
70+
Full job detail: status, counters, frontier preview, and recent events.
71+
72+
- `POST /jobs/{job_id}/pause`
73+
Pauses a running job.
74+
75+
- `POST /jobs/{job_id}/resume`
76+
Resumes a paused job.
77+
78+
- `POST /jobs/{job_id}/rate-limit`
79+
Updates a job's request rate (`req/s`) while running.
80+
81+
### Global Operations
82+
83+
- `GET /metrics`
84+
Global metrics plus jobs summary.
85+
86+
- `POST /settings/queue-limit`
87+
Updates the **global** queue limit shared by all jobs.
88+
89+
## Backpressure and Load Management
90+
91+
The crawler enforces load control using:
92+
93+
- a **global queue capacity** shared across all jobs,
94+
- per-job request-rate throttling (`req/s`),
95+
- live backpressure state (`normal`, `high`, `queue_full`) shown in UI.
96+
97+
This helps keep the system stable under concurrent crawls on a single machine.
98+
99+
## How To Run
100+
101+
## Backend
102+
103+
```bash
104+
pip install -r requirements.txt
105+
uvicorn backend.app:app --reload
106+
```
107+
108+
Runs on `http://127.0.0.1:8000`.
109+
110+
## Frontend
111+
112+
```bash
113+
cd frontend
114+
npm install
115+
npm run dev
116+
```
117+
118+
Open the printed Vite URL (usually `http://127.0.0.1:5173`).
119+
120+
## Suggested Demo Flow
121+
122+
1. Start one crawler from a seed URL with depth `k`.
123+
2. Observe queue depth, worker count, and backpressure in dashboard.
124+
3. Start a second crawler to demonstrate concurrent jobs.
125+
4. Update global queue limit and per-job req/s live.
126+
5. Pause and resume one job.
127+
6. Run Search and `I'm Feeling Lucky`.
128+
7. Click a job card and inspect frontier preview + event timeline.
129+
130+
## Limitations (Current Scope)
131+
132+
- Search is term-frequency based (no semantic embeddings).
133+
- Single-process deployment (no horizontal scaling).
134+
- No robots.txt policy enforcement yet.
135+
- No hard per-domain crawl budget yet.
136+
137+
## Production Next Steps (1-2 Paragraphs)
138+
139+
To productionize this system, the first step is to separate responsibilities into independent services: crawl scheduler, crawl workers, indexing pipeline, and query API. The current asyncio loop can evolve into a worker template that pulls tasks from a durable queue and writes normalized page documents to persistent storage. The in-memory inverted index should be replaced with a dedicated search layer (for example BM25-capable engine) to improve ranking quality, scalability, and operational resilience.
140+
141+
Operationally, internet-facing crawling needs stronger safety controls: robots.txt compliance, per-domain throttling and crawl budgets, better failure isolation, and kill switches for runaway jobs. The persistence layer should move from local SQLite to managed, replicated data stores. Finally, add full observability (metrics, logs, traces), authentication/authorization for APIs, and deployment automation to support repeatable, safe releases.
36142

0 commit comments

Comments
 (0)