Main web server and its workers
- Python 64.7%
- HTML 34%
- JavaScript 0.5%
- Just 0.4%
- CSS 0.2%
- Other 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Also turned on linting and a bunch of files got updated too Reviewed-on: WebHarvest/webharvest#2 Co-authored-by: Eddy Hintze <eddy@gitx.codes> Co-committed-by: Eddy Hintze <eddy@gitx.codes> |
||
| alembic | ||
| app | ||
| docker | ||
| scripts | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| .markdownlint.yaml | ||
| .markdownlintignore | ||
| .pre-commit-config.yaml | ||
| alembic.ini | ||
| conftest.py | ||
| docker-compose.yaml | ||
| Dockerfile | ||
| justfile | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| pyproject.toml | ||
| README.md | ||
| tailwind.config.js | ||
| uv.lock | ||
WebHarvest
A web-based management application for running and monitoring web scrapers.
Built using Fastapi-boilerplate as the starting point.
🛠️ Technology Stack
- Backend: FastAPI, SQLAlchemy, PostgreSQL, Pydantic
- Frontend: Server-side Jinja2 templates, TailwindCSS, vanilla JavaScript
- Auth: fastapi-sso (GitHub, Google, Generic OIDC), local email/password
- Message Queue: RabbitMQ (broker)
- Background Tasks: Celery
- Storage: MinIO (S3-compatible object storage)
- Cache/Quick Storage: Redis
- Tools: uv (package manager), Just (task runner), Docker, Alembic (migrations)
📦 Features
- Web Scraping Management: Create projects and batches to organize scraping tasks
- Multiple Scraper Types: Support for both requests-based and Selenium-based scraping
- Background Processing: Celery-powered background tasks with real-time progress tracking
- Authentication: Multi-provider SSO (GitHub, Google, OIDC) + local email/password
- User Management: Admin functions, user banning, email verification
- API Access: API key system for programmatic access
- Real-time Monitoring: Track scraping progress and results in real-time
🚀 Quick Start
Option 1: Full Docker Setup (Production-like)
Perfect for testing the complete system without local development setup.
-
Prerequisites
# Install Docker and Docker Compose # https://docs.docker.com/get-docker/ -
Setup
git clone <repository-url> cd webharvest cp .env.example .env # Edit .env file as needed (defaults work for testing) -
Run
docker compose up -d -
Access the application
- Web Interface: http://localhost:8000
- RabbitMQ Management: http://localhost:15672 (guest/guest)
- MinIO Console: http://localhost:9001 (scraper/my_secure_password)
Option 2: Development Setup
Best for active development with hot reloading and debugging.
Prerequisites
Install the following tools:
uv[Install] - Python package managerjust[Install] - Task runnerNode.js[Install] - For TailwindCSS
Setup
# 1. Clone and setup environment
git clone <repository-url>
cd webharvest
cp .env.example .env
# 2. Install dependencies for different deployment scenarios:
uv sync # Install base dependencies only (web server)
uv sync --extra scraper # Install base + scraper dependencies (worker)
uv sync --extra all # Install all dependencies (development)
# 3. Install Node.js dependencies for TailwindCSS
npm install
# 4. Setup pre-commit hooks (optional but recommended)
uv run pre-commit install
Running for Development
# Start all services (PostgreSQL + RabbitMQ + FastAPI + MinIO)
just start
just worker-start # Starts worker1 (default)
just worker-start 2 # Starts worker2
just worker-start 3 # Starts worker3
# Alternative: Start services individually
just db-start # Start PostgreSQL
just rabbitmq-start # Start RabbitMQ
just redis-start # Start Redis
just server-start # Start FastAPI server
# Watch CSS changes during development
just watch-styles # In a separate terminal
Database Operations
# Run migrations
uv run alembic upgrade head
# Create new migration
uv run alembic revision --autogenerate -m "description"
# Fresh start (clear database/redis/message queue and restart)
just fresh-start
Celery Workers (Background Tasks)
Choose one of these worker configurations:
# Recommended: Single worker with priority queue support
uv run celery -A app.tasks.celery_app worker --loglevel=info -Q priority,default,maintenance
# Alternative: Separate workers for different queues
uv run celery -A app.tasks.celery_app worker --loglevel=info -Q priority # Priority queue
uv run celery -A app.tasks.celery_app worker --loglevel=info -Q default # Default queue
uv run celery -A app.tasks.celery_app worker --loglevel=info -Q maintenance # Maintenance queue
# Optional: Start celery beat for periodic tasks, not neded for development to run locally
uv run celery -A app.tasks.celery_app beat --loglevel=inf0
# Optional: Start Flower for monitoring
uv run celery -A app.tasks.celery_app flower # Access at http://localhost:5555
🛠️ Development Commands
Available Just Commands
just --list # Show all available commands
just start # Start all services
just server-start # Start only FastAPI (if DB already running)
just fresh-start # Clear database and restart everything
just db-start # Start PostgreSQL container
just db-stop # Stop PostgreSQL container
just rabbitmq-start # Start RabbitMQ container
just rabbitmq-stop # Stop RabbitMQ container
just build-styles # Build TailwindCSS for production
just watch-styles # Watch CSS changes during development
Direct Commands
# Python environment
uv sync # Install/sync dependencies
uv run python -m app.app # Run FastAPI directly
# Database
uv run alembic upgrade head # Run migrations
uv run alembic revision --autogenerate # Create migration
# CSS/Styling
npm run build-styles # Build TailwindCSS
npm run watch-styles # Watch CSS changes
# Testing (when available)
uv run pytest # Run tests
🏗️ Project Architecture
Directory Structure
app/
├── app.py # FastAPI application entry point
├── settings.py # Centralized configuration
├── auth/ # Authentication system
│ ├── models.py # User models
│ └── views/ # Auth route handlers
├── scraper/ # Web scraping functionality
│ ├── models.py # Project and Batch models
│ ├── views/ # Scraper route handlers
│ └── templates/ # Scraper HTML templates
├── tasks/ # Celery background tasks
│ ├── celery_app.py # Celery configuration
│ └── scraper_tasks.py # Scraping task implementations
├── common/ # Shared utilities
│ ├── models.py # Base models
│ ├── db.py # Database setup
│ └── templates.py # Template utilities
├── email/ # Email functionality
└── static/ # CSS, JS, images
Key Components
- Projects: Define default scraper settings (requests vs selenium, timeout, retries)
- Batches: Contain lists of URLs with optional user_data, can override project settings
- Tasks: Background Celery tasks that process batches with real-time progress tracking
- Authentication: Multi-provider system with SSO and local accounts
🔧 Configuration
Environment Variables
Key settings in .env:
# Application
ENV="dev" # dev | staging | prod
APP_NAME="WebHarvest"
HOST="http://localhost:8000"
# Database
DATABASE_USER="postgres"
DATABASE_PASSWORD="postgres"
DATABASE_HOST="localhost" # Use "db" for Docker
DATABASE_PORT=5432
DATABASE_NAME="postgres"
# Authentication
SECRET_KEY="your-secure-secret-key"
DISABLE_REGISTRATION=false
# SSO Providers (optional)
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
# Email (optional)
SMTP_HOST=""
SMTP_PORT=""
SMTP_USER=""
SMTP_PASSWORD=""
SSO Configuration
Configure OAuth providers by setting their respective environment variables:
- GitHub:
GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET - Google:
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET - Generic OIDC:
OIDC_*variables
📊 Monitoring & Management
- Web Interface: Main application at http://localhost:8000
- RabbitMQ Management: http://localhost:15672 (guest/guest)
- Flower (Celery): http://localhost:5555 (when started)
- MinIO Console: http://localhost:9001 (scraper/my-secure-password)
🐛 Troubleshooting
Common Issues
- Database connection errors: Ensure PostgreSQL is running (
just db-start) - Celery tasks not processing: Start a Celery worker
- CSS not updating: Run
just build-stylesorjust watch-styles - Port conflicts: Check if ports 8000, 5432, 5672, 15672 are available
📄 License
This project is licensed under the LICENSE file in the repository.