Crawl API — Headless Browser REST API
Recreación de crawlapi.dev en Rust Full-Stack.
Stack
- Backend: Axum (Rust)
- Database: PostgreSQL + sqlx
- Queue: Redis (jobs + caching + rate limiting)
- Browser Automation: Playwright (Node.js) con Browser Pool
- File Storage: MinIO (S3-compatible)
- Frontend: Next.js 14
- Observabilidad: Prometheus + Grafana + Sentry
- Seguridad: Rate limiting + IP blocking + input validation
- AI: OpenAI GPT-4o-mini extraction
- Auth: Email/password + Google OAuth
- Billing: Stripe Checkout + Webhooks
- CI/CD: GitHub Actions (test, build, deploy)
- Infra: Docker Compose + Kubernetes + HPA + cert-manager
- Load Testing: k6 (smoke, load, stress, screenshot)
Estructura
Endpoints
Crawl/Scrape/AI
| Endpoint |
Descripción |
POST /api/crawl |
Full JS-rendered page crawl |
POST /api/content |
Raw HTML |
POST /api/screenshot |
PNG screenshot (subido a S3) |
POST /api/pdf |
PDF export (subido a S3) |
POST /api/markdown |
Markdown extraction |
POST /api/snapshot |
HTML + screenshot combined |
POST /api/scrape |
CSS selector extraction |
POST /api/json |
Structured JSON |
POST /api/links |
Extract all links |
POST /api/extract |
AI-powered extraction con OpenAI |
Auth
| Endpoint |
Descripción |
POST /api/auth/register |
Crear cuenta |
POST /api/auth/login |
Login (devuelve JWT) |
GET /api/auth/google |
URL de OAuth Google |
GET /api/auth/google/callback |
Callback de OAuth (real con token exchange) |
POST /api/auth/api-keys |
Crear API key (requiere JWT) |
GET /api/auth/api-keys |
Listar API keys (requiere JWT) |
DELETE /api/auth/api-keys/{id} |
Eliminar API key (requiere JWT) |
Billing
| Endpoint |
Descripción |
POST /api/stripe/checkout |
Crear checkout session funcional |
POST /api/stripe/webhook |
Webhook de Stripe (procesa eventos reales) |
Teams
| Endpoint |
Descripción |
POST /api/teams |
Crear equipo |
GET /api/teams/{slug} |
Ver equipo y miembros |
POST /api/teams/{slug}/members |
Agregar miembro |
Observabilidad
| Endpoint |
Descripción |
GET /metrics |
Métricas Prometheus |
GET /ws/logs |
WebSocket live logs |
Quick Start (Docker)
CI/CD (GitHub Actions)
Workflows:
.github/workflows/ci.yml — Test, build, push images
.github/workflows/deploy.yml — Deploy a staging y production
Kubernetes
Load Testing (k6)
Tests
Features implementadas
Core
- ✅ 10 endpoints REST (9 crawl + 1 AI)
- ✅ Browser Pool — 5 navegadores Chromium, 10 páginas cada uno
- ✅ Session/Cookie Persistence — Guarda cookies por
session_id
- ✅ Mobile Emulation — iPhone 14 viewport
- ✅ Infinite Scroll — Auto-scroll hasta el final
- ✅ Custom Headers — Headers arbitrarios por request
Workers
- ✅ Distributed Queue — Redis LPUSH/BLPOP
- ✅ Retry con Backoff — 3 retries con espera exponencial (2s, 4s, 8s)
- ✅ Dead Letter Queue — Jobs fallidos guardados por 24h
- ✅ Caching — Resultados en Redis con TTL 5 min
Scraping Avanzado
- ✅ Stealth Mode — Evade detección de bots (webdriver, plugins, canvas)
- ✅ Proxy Rotation — Múltiples proxies vía
PROXY_URL
- ✅ CAPTCHA Solving — Integración con CapSolver/2captcha
Auth & Billing
- ✅ Email/Password — Bcrypt + JWT
- ✅ Google OAuth — Exchange real de code → token → user info
- ✅ Stripe — Checkout funcional + webhooks reales
- ✅ Teams — Owner/member roles
Observabilidad
- ✅ Prometheus —
/metrics con counters y histograms
- ✅ Grafana — Dashboard incluido
- ✅ Sentry — Error tracking en API y Worker
- ✅ Structured Logging — JSON logs con correlation IDs
- ✅ WebSocket Logs —
/ws/logs
Seguridad
- ✅ Input Validation — URLs, webhooks, tamaños (SSRF protection)
- ✅ Rate Limiting — Por API key (60/min) + por IP (100/min)
- ✅ IP Blocking — Auto-bloqueo por 1 hora
Infraestructura
- ✅ Docker Compose — Todo en un comando
- ✅ Kubernetes — Full manifests con ingress TLS + cert-manager
- ✅ HPA — Auto-scaling 3-20 workers
- ✅ Health Checks — Liveness, readiness, startup probes
- ✅ SSL/TLS — Let's Encrypt automático via cert-manager
Secrets Management
- ✅ Multi-provider — Env vars → Vault → AWS Secrets Manager
- ✅ Fallback chain — Intenta cada provider en orden
Frontend
- ✅ Landing Page
- ✅ API Documentation
- ✅ Interactive Playground — Probar endpoints con code snippets
- ✅ Billing Page — Plans + usage bar
- ✅ Dashboard — Login, API keys, tester
CI/CD
- ✅ GitHub Actions — CI con test, clippy, audit
- ✅ Docker Build & Push — Multi-stage builds
- ✅ Deploy Staging — Auto-deploy en push a main
- ✅ Deploy Production — Solo en tags v*
- ✅ Smoke Tests — Verificación post-deploy
Legal
- ✅ Terms of Service
- ✅ Privacy Policy
- ✅ Data Processing Agreement
Load Testing
- ✅ k6 Smoke Test — 1 VU
- ✅ k6 Load Test — Ramp up a 20 VUs
- ✅ k6 Stress Test — Hasta 200 VUs
- ✅ k6 Screenshot Test — 5 VUs concurrentes
Variables de entorno
Uso de la API
Screenshot con stealth + proxy + CAPTCHA
Mobile emulation
Licencia
MIT