A Python Flask API that powers the “First Link Rule” project by fetching and following the first link of any Wikipedia article until it reaches the Philosophy page, detects a loop, or hits a dead end. Supports both parsing-based traversal (BeautifulSoup) and optional Selenium-based traversal.
- About
- Features
- Tech Stack
- Setup & Installation
- Configuration
- API Endpoints
- Project Structure
- License
- Acknowledgments
This service handles traversal logic for the First Link Project. It exposes endpoints to start a traversal from any Wikipedia URL, returning the full path, step count, and any errors encountered.
- Parsing-Based Traversal with
requests+ BeautifulSoup for lightweight environments - Selenium-Based Traversal (optional) for full browser simulation
- Loop & Dead-End Detection to prevent infinite cycles
- Configurable Limits (max iterations, target URL)
- Docker Support for containerized deployment
- Language: Python 3.12+
- Framework: Flask
- HTTP: Requests
- HTML Parsing: BeautifulSoup4
- Browser Automation: Selenium (optional)
- Containerization: Docker
git clone https://github.com/190-785/First_Link_Backend.git
cd First_Link_Backend
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
flask run --port 10000docker build -t first-link-backend .
docker run -p 10000:10000 first-link-backendCreate a .env file in the project root with:
FLASK_ENV=development
SECRET_KEY=your_secret_key
MAX_ITERATIONS=30
PHILOSOPHY_URL=https://en.wikipedia.org/wiki/Philosophy
ALLOWED_ORIGINS=http://localhost:5173
USE_SELENIUM=falseUSE_SELENIUM: set totrueto enable Selenium mode.
Request Body (JSON):
{
"start_url": "https://en.wikipedia.org/wiki/Physics"
}Response (JSON):
{
"path": [
"https://en.wikipedia.org/wiki/Physics",
"...",
"https://en.wikipedia.org/wiki/Philosophy"
],
"steps": 7,
"last_link": "https://en.wikipedia.org/wiki/Philosophy",
"error": null
}Response (JSON):
{
"status": "Backend is running"
}First_Link_Backend/
├── app.py # Flask application
├── parsing_traversal.py # BeautifulSoup-based traversal logic
├── traversal.py # Core traversal engine
├── predefined_paths.json # Example path sets (optional)
├── requirements.txt # Python dependencies
├── Dockerfile # Container build instructions
└── .env.example # Sample environment variables
This backend is licensed under the GNU General Public License v3.0. See the LICENSE file for full terms.
- Not David – For the inspiring “First Link Rule” video: https://youtu.be/-llumS2rA8I?feature=shared
- Wikipedia – For the open REST API
- Open‑source community – For all the libraries and tools used in this project