Main web server and its workers
This repository has been archived on 2026-01-30. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • Python 64.7%
  • HTML 34%
  • JavaScript 0.5%
  • Just 0.4%
  • CSS 0.2%
  • Other 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Eddy Hintze 9213c68fff Added scraper modules (#2)
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>
2025-07-22 23:39:07 -04:00
alembic Added seleniumbase with custom actions 2025-07-22 08:11:20 -04:00
app Added scraper modules (#2) 2025-07-22 23:39:07 -04:00
docker Initial commit 2025-07-06 11:57:06 -04:00
scripts Initial commit 2025-07-06 11:57:06 -04:00
.dockerignore Initial commit 2025-07-06 11:57:06 -04:00
.env.example Initial commit 2025-07-06 11:57:06 -04:00
.gitignore Added scraper modules (#2) 2025-07-22 23:39:07 -04:00
.markdownlint.yaml Initial commit 2025-07-06 11:57:06 -04:00
.markdownlintignore Initial commit 2025-07-06 11:57:06 -04:00
.pre-commit-config.yaml Initial commit 2025-07-06 11:57:06 -04:00
alembic.ini Initial commit 2025-07-06 11:57:06 -04:00
conftest.py Initial commit 2025-07-06 11:57:06 -04:00
docker-compose.yaml Initial commit 2025-07-06 11:57:06 -04:00
Dockerfile Initial commit 2025-07-06 11:57:06 -04:00
justfile Initial commit 2025-07-06 11:57:06 -04:00
LICENSE Initial commit 2025-07-06 11:57:06 -04:00
package-lock.json Initial commit 2025-07-06 11:57:06 -04:00
package.json Initial commit 2025-07-06 11:57:06 -04:00
pyproject.toml Initial commit 2025-07-06 11:57:06 -04:00
README.md Added scraper modules (#2) 2025-07-22 23:39:07 -04:00
tailwind.config.js Initial commit 2025-07-06 11:57:06 -04:00
uv.lock Initial commit 2025-07-06 11:57:06 -04:00

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.

  1. Prerequisites

    # Install Docker and Docker Compose
    # https://docs.docker.com/get-docker/
    
  2. Setup

    git clone <repository-url>
    cd webharvest
    cp .env.example .env
    # Edit .env file as needed (defaults work for testing)
    
  3. Run

    docker compose up -d
    
  4. Access the application

Option 2: Development Setup

Best for active development with hot reloading and debugging.

Prerequisites

Install the following tools:

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

🐛 Troubleshooting

Common Issues

  1. Database connection errors: Ensure PostgreSQL is running (just db-start)
  2. Celery tasks not processing: Start a Celery worker
  3. CSS not updating: Run just build-styles or just watch-styles
  4. Port conflicts: Check if ports 8000, 5432, 5672, 15672 are available

📄 License

This project is licensed under the LICENSE file in the repository.