README
Web Spider ๐ท๏ธ
A high-performance, concurrent web crawler built with Go and TypeScript. Features intelligent caching, robots.txt compliance, and beautiful Markdown conversion.
Features
- Concurrent Crawling: Configurable worker pool for parallel page processing
- Smart Caching: Time-based cache with configurable expiration
- Resume Capability: Persistent queue allows stopping and resuming crawls
- Depth-First Crawling: Automatically detects and respects maximum depth
- HTML to Markdown: Converts crawled pages to clean Markdown format
- Robots.txt Compliance: Respects website crawling rules
- Rate Limiting: Polite crawling with configurable delays
- Modern UI: Real-time dashboard with Tailwind CSS and shadcn styling
- REST API: Full control via HTTP endpoints
Architecture
shell
web-spider/
โโโ backend/ # Go crawler engine
โ โโโ cmd/ # Application entry point
โ โโโ internal/ # Core business logic
โ โ โโโ api/ # REST API handlers
โ โ โโโ cache/ # Caching system
โ โ โโโ converter/# HTML to Markdown
โ โ โโโ crawler/ # Main crawler engine
โ โ โโโ queue/ # Priority queue
โ โ โโโ storage/ # File system storage
โ โโโ pkg/ # Shared packages
โโโ frontend/ # TypeScript UI
โ โโโ src/
โ โโโ api/ # API client
โ โโโ components/# UI components
โโโ data/ # Crawled data storage
โโโ pages/ # Markdown pages
โโโ links/ # Link metadata
โโโ cache/ # Cache storage
Quick Start
Prerequisites
- Go 1.21+
- Node.js 18+
- Make (optional)
Installation
bash
# Clone the repository
git clone https://github.com/yourusername/web-spider.git
cd web-spider
# Install dependencies
make install-deps
# Or manually:
cd backend && go mod download
cd ../frontend && npm install
Running
bash
# Production build
make build
make run
# Development mode (with hot reload)
make dev
# Or run separately:
make backend-dev # Terminal 1
make frontend-dev # Terminal 2The application will be available at:
- Frontend: http://localhost:3001
- API: http://localhost:8090
Configuration
Default Settings
json
{
"crawler": {
"max_workers": 5,
"max_depth": 10,
"cache_duration": "24h",
"rate_limit": "1s",
"respect_robots": true,
"user_agent": "WebSpider/1.0"
}
}
Environment Variables
bash
SPIDER_PORT=8090 # API server port
SPIDER_HOST=0.0.0.0 # API server host
SPIDER_DATA_DIR=./data # Data storage directory
API Endpoints
Crawler Control
bash
# Start crawling
POST /api/v1/crawl/start
{
"url": "https://example.com"
}
# Stop crawling
POST /api/v1/crawl/stop
# Get statistics
GET /api/v1/crawl/stats
# Get/Update configuration
GET /api/v1/crawl/config
PUT /api/v1/crawl/config
Data Access
bash
# List crawled domains
GET /api/v1/domains
# Get cached pages
GET /api/v1/pages/{domain}
# Get extracted links
GET /api/v1/links/{domain}
# Cache management
GET /api/v1/cache/stats
DELETE /api/v1/cache
# Queue management
GET /api/v1/queue
DELETE /api/v1/queue
Storage Structure
shell
data/
โโโ pages/
โ โโโ example.com/
โ โโโ index.md # Converted markdown
โ โโโ index.md.meta.json # Metadata
โโโ links/
โ โโโ example.com/
โ โโโ [hash]_links.json # Extracted links
โโโ queue.json # Persistent queue
โโโ stats.json # Crawl statistics
Advanced Usage
Custom Configuration File
bash
# Create config.json
{
"server": {
"port": "8090",
"host": "0.0.0.0"
},
"crawler": {
"max_workers": 10,
"max_depth": 5,
"cache_duration": "12h",
"rate_limit": "500ms"
}
}
# Run with custom config
./bin/web-spider -config config.json
Docker Deployment
bash
# Build image
docker build -t web-spider:latest .
# Run container
docker run -d \
-p 8090:8090 \
-p 3001:3001 \
-v $(pwd)/data:/app/data \
web-spider:latest
Development
Testing
bash
# Run all tests
make test
# Run specific package tests
cd backend && go test ./internal/crawler -v
Building from Source
bash
# Backend only
cd backend
go build -o ../bin/web-spider cmd/main.go
# Frontend only
cd frontend
npm run build
Features in Detail
Concurrent Worker Pool
- Dynamic worker scaling
- Graceful shutdown
- Automatic retry on failure
Intelligent Caching
- URL-based cache keys
- Configurable TTL
- Automatic cache invalidation
Resume Capability
- Persistent queue state
- Automatic recovery on restart
- Progress tracking
Depth Detection
- Automatic max depth discovery
- Priority-based crawling
- Breadth-first option available
Troubleshooting
Common Issues
bash
# Change ports in config or environment
SPIDER_PORT=8081 ./bin/web-spider
bash
# Fix permissions
chmod -R 755 ./data
bash
# Reduce workers and increase rate limit
# Adjust in UI settings or config file
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Acknowledgments
- Built with Go and TypeScript
- UI styled with Tailwind CSS
- HTML parsing with goquery
- Markdown conversion with custom algorithms