Skip to content

Commit b449dbf

Browse files
Merge pull request #19 from mdhishaamakhtar/master
2 parents b55f17f + eb38256 commit b449dbf

21 files changed

Lines changed: 1919 additions & 202 deletions

.coverage

52 KB
Binary file not shown.

API_DOCUMENTATION.md

Lines changed: 95 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ The Iris Wikipedia Pathfinder API finds the shortest path between two Wikipedia
77
## Base URL
88

99
```
10-
API: http://localhost:9020
11-
Web UI: http://localhost:9020/ui
10+
Application: http://localhost:9020
11+
Interactive UI: http://localhost:9020 (default landing page)
12+
API Documentation: http://localhost:9020/api
1213
```
1314

1415
## Quick Start
@@ -96,10 +97,20 @@ honcho start
9697

9798
## API Endpoints
9899

99-
### 1. Root Endpoint - API Information
100+
### 1. Interactive UI (Landing Page)
100101

101102
**GET /**
102103

104+
Serves the interactive web interface for pathfinding visualization (default landing page).
105+
106+
**GET /any-path**
107+
108+
All non-API paths automatically redirect to the main UI for a seamless user experience.
109+
110+
### 2. API Information
111+
112+
**GET /api**
113+
103114
Returns basic API information and available endpoints.
104115

105116
**Response:**
@@ -113,14 +124,15 @@ Returns basic API information and available endpoints.
113124
"GET /tasks/status/<task_id>": "Check task status",
114125
"POST /explore": "Explore page connections",
115126
"GET /health": "Health check",
116-
"GET /ui": "Interactive web interface",
117-
"GET /": "API information"
127+
"GET /": "Interactive web interface",
128+
"GET /api": "API information"
118129
},
119-
"documentation": "./API_DOCUMENTATION.md"
130+
"documentation": "./API_DOCUMENTATION.md",
131+
"ui_url": "/"
120132
}
121133
```
122134

123-
### 2. Find Path Between Pages
135+
### 3. Find Path Between Pages
124136

125137
**POST /getPath**
126138

@@ -164,7 +176,7 @@ curl -X POST http://localhost:9020/getPath \
164176
}'
165177
```
166178

167-
### 3. Check Task Status
179+
### 4. Check Task Status
168180

169181
**GET /tasks/status/{task_id}**
170182

@@ -173,29 +185,39 @@ Polls the status of a pathfinding task.
173185
**Path Parameters:**
174186
- `task_id` (string, required): Task ID returned from /getPath
175187

176-
**Response - Task Pending:**
188+
**Response — PENDING:**
177189
```json
178190
{
179-
"status": "PENDING",
191+
"status": "PENDING",
180192
"task_id": "abc123-def456-ghi789",
181193
"message": "Task is waiting to be processed"
182194
}
183195
```
184196

185-
**Response - Task In Progress:**
197+
**Response — IN_PROGRESS:**
186198
```json
187199
{
188200
"status": "IN_PROGRESS",
189-
"task_id": "abc123-def456-ghi789",
201+
"task_id": "abc123-def456-ghi789",
190202
"progress": {
191-
"current_depth": 3,
192-
"nodes_explored": 150,
193-
"message": "Searching at depth 3..."
203+
"status": "Starting pathfinding search...",
204+
"search_stats": {
205+
"nodes_explored": 0,
206+
"current_depth": 0,
207+
"last_node": "Albert Einstein",
208+
"queue_size": 1,
209+
"start_page": "Albert Einstein",
210+
"end_page": "Physics",
211+
"max_depth": 6
212+
},
213+
"search_time_elapsed": 0
194214
}
195215
}
196216
```
197217

198-
**Response - Task Success:**
218+
Note: The `progress` object mirrors the task's meta and may include additional fields depending on runtime.
219+
220+
**Response — SUCCESS:**
199221
```json
200222
{
201223
"status": "SUCCESS",
@@ -204,12 +226,22 @@ Polls the status of a pathfinding task.
204226
"path": ["Albert Einstein", "Science", "Physics"],
205227
"length": 3,
206228
"search_time": 2.45,
207-
"nodes_explored": 287
229+
"nodes_explored": 287,
230+
"search_stats": {
231+
"nodes_explored": 287,
232+
"final_depth": 2,
233+
"start_page": "Albert Einstein",
234+
"end_page": "Physics",
235+
"max_depth": 6,
236+
"search_completed": true
237+
}
208238
}
209239
}
210240
```
211241

212-
**Response - Task Failed:**
242+
Note: If the underlying task returns a different structure, it may be passed through as-is in `result`.
243+
244+
**Response — FAILURE:**
213245
```json
214246
{
215247
"status": "FAILURE",
@@ -218,12 +250,23 @@ Polls the status of a pathfinding task.
218250
}
219251
```
220252

253+
**Response — Other States (e.g., RETRY):**
254+
```json
255+
{
256+
"status": "RETRY",
257+
"task_id": "abc123-def456-ghi789",
258+
"info": "Retrying due to: Connection timeout to Wikipedia API"
259+
}
260+
```
261+
262+
Note: For states other than the above, `info` contains a string description derived from the task's state/meta.
263+
221264
**Example cURL:**
222265
```bash
223266
curl http://localhost:9020/tasks/status/abc123-def456-ghi789
224267
```
225268

226-
### 4. Explore Page Connections
269+
### 5. Explore Page Connections
227270

228271
**POST /explore**
229272

@@ -272,7 +315,7 @@ curl -X POST http://localhost:9020/explore \
272315
}'
273316
```
274317

275-
### 5. Health Check
318+
### 6. Health Check
276319

277320
**GET /health**
278321

@@ -283,7 +326,7 @@ Checks the health status of all system components.
283326
{
284327
"status": "healthy",
285328
"redis_status": "healthy",
286-
"cache_status": "healthy",
329+
"cache_status": "healthy",
287330
"wikipedia_api_status": "healthy",
288331
"timestamp": "2025-01-31T00:00:00Z"
289332
}
@@ -295,7 +338,7 @@ Checks the health status of all system components.
295338
"status": "degraded",
296339
"redis_status": "unhealthy: Connection refused",
297340
"cache_status": "healthy",
298-
"wikipedia_api_status": "healthy",
341+
"wikipedia_api_status": "healthy",
299342
"timestamp": "2025-01-31T00:00:00Z"
300343
}
301344
```
@@ -305,7 +348,7 @@ Checks the health status of all system components.
305348
curl http://localhost:9020/health
306349
```
307350

308-
### 6. Clear Cache (Admin)
351+
### 7. Clear Cache (Admin)
309352

310353
**POST /cache/clear**
311354

@@ -337,24 +380,27 @@ curl -X POST http://localhost:9020/cache/clear \
337380
-d '{"pattern": "wiki_links:*"}'
338381
```
339382

340-
### 7. Interactive Web Interface
383+
### 8. Interactive Web Interface Features
341384

342-
**GET /ui**
385+
The main landing page (`/`) serves the interactive web interface with enhanced features:
343386

344-
Serves the interactive web interface for visualizing Wikipedia pathfinding results.
345-
346-
**Features:**
387+
**Enhanced Features:**
388+
- **UI-First Experience**: Landing page serves interactive UI directly, all paths redirect to main interface
389+
- **State Persistence**: Automatically saves and restores search state using localStorage
390+
- **Mobile-Optimized**: Fixed touch/scroll conflicts for seamless mobile graph interaction
391+
- **Session Recovery**: Automatically resumes interrupted searches after page refresh
347392
- **Modern Dark Theme**: Professional dark tech aesthetic with GitHub-inspired colors
348393
- **Interactive Graph Visualization**: D3.js-powered force-directed graph with physics simulation
349-
- **Real-Time Pathfinding**: Live progress tracking and result visualization
350394
- **Dynamic Node Interaction**: Drag-and-drop nodes with intelligent physics
351395
- **Smart Text Rendering**: Dynamic text truncation based on graph density
352396
- **Professional Typography**: JetBrains Mono font throughout
353-
- **Responsive Design**: Works on desktop and mobile devices
397+
- **Responsive Design**: Works perfectly on desktop and mobile devices
354398

355399
**Navigation:**
356400
```
357-
http://localhost:9020/ui
401+
http://localhost:9020/ (default landing page)
402+
http://localhost:9020/ui (redirects to main UI)
403+
http://localhost:9020/<any> (redirects to main UI)
358404
```
359405

360406
**Interface Components:**
@@ -369,12 +415,13 @@ http://localhost:9020/ui
369415
- **Error Handling**: User-friendly error messages and loading states
370416

371417
**Usage:**
372-
1. Navigate to `/ui` in your browser
373-
2. Enter Wikipedia page titles in start and end fields
418+
1. Navigate to `/` in your browser (or any non-API path)
419+
2. Enter Wikipedia page titles in start and end fields
374420
3. Click "Find Path" to initiate pathfinding
375-
4. Watch real-time graph visualization
376-
5. Interact with nodes by dragging them
421+
4. View graph visualization as path is discovered
422+
5. Interact with nodes by dragging them (mobile-optimized)
377423
6. Click on path steps to visit Wikipedia pages
424+
7. State is automatically saved - refresh to resume interrupted searches
378425

379426
**Technical Details:**
380427
- Uses D3.js v7 for graph visualization
@@ -405,6 +452,9 @@ All endpoints return structured error responses when something goes wrong:
405452
}
406453
```
407454

455+
Note: JSON 404 responses are returned for API-like paths (for example, `/api/...`).
456+
Requests to non-API paths instead redirect to the main UI (`/`).
457+
408458
**405 Method Not Allowed:**
409459
```json
410460
{
@@ -461,9 +511,11 @@ curl http://localhost:9020/tasks/status/xyz789-abc123-def456
461511
"status": "IN_PROGRESS",
462512
"task_id": "xyz789-abc123-def456",
463513
"progress": {
464-
"current_depth": 2,
465-
"nodes_explored": 95,
466-
"message": "Searching at depth 2..."
514+
"current": 10,
515+
"total": 100,
516+
"status": "Validating pages...",
517+
"start_page": "Barack Obama",
518+
"end_page": "Computer Science"
467519
}
468520
}
469521
```
@@ -489,10 +541,10 @@ curl http://localhost:9020/tasks/status/xyz789-abc123-def456
489541

490542
## Rate Limiting
491543

492-
The API includes basic rate limiting middleware:
493-
- Default: 100 requests per minute per IP
494-
- Rate limit headers are included in responses
495-
- Exceeding limits returns HTTP 429 Too Many Requests
544+
Basic logging-only rate limiting is present for visibility, but limits are not enforced in this build:
545+
- Logs each request with a per-IP note; no counters are persisted
546+
- No `429 Too Many Requests` responses are emitted by default
547+
- For production-grade limits, plug in a Redis-backed limiter
496548

497549
## Environment Configuration
498550

@@ -569,4 +621,4 @@ For issues and questions:
569621
- Check the logs: Application logs provide detailed error information
570622
- Health endpoint: Use `/health` to diagnose system issues
571623
- Redis connectivity: Ensure Redis is running and accessible
572-
- Wikipedia API: Check if Wikipedia API is accessible from your network
624+
- Wikipedia API: Check if Wikipedia API is accessible from your network

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ The project demonstrates expertise in:
3939
- **CORS Support**: Cross-origin resource sharing for frontend integration
4040

4141
### ✅ Interactive Visualization
42-
- **Web-Based UI**: Modern dark-themed interface for interactive pathfinding
43-
- **Real-Time Graph Visualization**: D3.js-powered interactive graph with physics simulation
42+
- **Web-Based UI**: Interactive interface for pathfinding with real-time progress
43+
- **Graph Visualization**: D3.js-powered interactive graph with physics simulation
44+
- **Mobile Support**: Touch-optimized interface that works on mobile devices
45+
- **State Persistence**: Saves progress and resumes interrupted searches
4446
- **Dynamic Features**: Drag-and-drop nodes, responsive layout, smart text truncation
45-
- **Professional Design**: Clean typography with JetBrains Mono, opaque text backgrounds
4647

4748
### ✅ Development Tools
4849
- **Comprehensive Testing**: Unit and integration tests with 100% pass rate
@@ -68,7 +69,7 @@ The project demonstrates expertise in:
6869

6970
[![pytest](https://img.shields.io/badge/pytest-8.3.3-0A9EDC?style=for-the-badge&logo=pytest&logoColor=white)](https://pytest.org)
7071
[![Black](https://img.shields.io/badge/Code%20Style-Black-000000?style=for-the-badge&logo=python&logoColor=white)](https://github.com/psf/black)
71-
[![Coverage](https://img.shields.io/badge/Coverage-81%20Tests%20Passing-success?style=for-the-badge&logo=pytest)](./tests/)
72+
[![Coverage](https://img.shields.io/badge/Coverage-107%20Tests%20Passing%20(~80%25)-success?style=for-the-badge&logo=pytest)](./tests/)
7273
[![Marshmallow](https://img.shields.io/badge/Validation-Marshmallow-FF6B6B?style=for-the-badge&logo=python)](https://marshmallow.readthedocs.io/)
7374

7475
## Project Information
@@ -102,8 +103,8 @@ pip install -r requirements.txt
102103
```
103104

104105
The application will be available at:
105-
- **API**: `http://localhost:9020`
106-
- **Interactive UI**: `http://localhost:9020/ui`
106+
- **Interactive UI**: `http://localhost:9020` (default landing page)
107+
- **API Documentation**: `http://localhost:9020/api`
107108

108109
### Production Deployment
109110
```bash
@@ -121,11 +122,13 @@ export REDIS_URL=redis://localhost:6379/0
121122
Complete API documentation with examples, request/response schemas, and integration guides is available in [API_DOCUMENTATION.md](./API_DOCUMENTATION.md).
122123

123124
### Key Endpoints
125+
- `GET /` - Interactive UI (default landing page)
126+
- `GET /<any-path>` - All non-API paths redirect to main UI
124127
- `POST /getPath` - Start pathfinding task (returns task ID for polling)
125-
- `GET /tasks/status/<task_id>` - Poll task status and retrieve results
128+
- `GET /tasks/status/<task_id>` - Poll task status with progress updates
126129
- `POST /explore` - Discover page connections for graph visualization
127130
- `GET /health` - System health monitoring endpoint
128-
- `GET /ui` - Interactive web interface for pathfinding visualization
131+
- `GET /api` - API documentation and information
129132

130133
## Architecture Highlights
131134

@@ -146,17 +149,24 @@ The core pathfinding algorithm demonstrates advanced system design:
146149

147150
```bash
148151
# Run comprehensive test suite
149-
pytest tests/ -v
152+
pytest -v
150153

151-
# Run with coverage reporting
152-
pytest tests/ --cov=app --cov-report=html
154+
# Run with coverage reporting (console + HTML)
155+
pytest --cov=app --cov-report=term-missing --cov-report=html
153156

154157
# Test specific components
155158
pytest tests/unit/ -v # Unit tests
156159
pytest tests/integration/ -v # Integration tests
157160
```
158161

159-
Current test coverage: **81 tests passing** with comprehensive unit and integration coverage.
162+
Current test coverage: **107 tests passing** with approximately **80% line coverage** across the `app/` package (see `htmlcov/index.html` after running coverage for a browsable report).
163+
164+
Key areas covered by new tests:
165+
- Cache and queue infrastructure with Redis client mocking
166+
- ServiceFactory lifecycle and Celery task configuration helpers
167+
- Wikipedia client parsing, batching, and request handling with a fake session
168+
- API middleware decorators (error handling, CORS, rate limiting, size checks)
169+
- Logging configuration, including file handler setup for non-testing environments
160170

161171
## Contributors
162172

0 commit comments

Comments
 (0)