5a64048ba2bea629b59cda33df1d1b7434097b7e
imageproc::find_contours panics on some edge images (called Option::unwrap() on None). Wrap with catch_unwind and provide a safe fallback (use full image bounds). Also add catch_unwind around the entire pipeline so no panic can crash the worker thread. Co-Authored-By: Kilo <kilo@kilo.ai>
Tools — Document Scanner & Media Processing
Self-hosted, no-install document scanner dan media processing tools yang jalan di browser. Alternatif dari CamScanner, ilovepdf, compressjpeg — tanpa upload ke pihak ketiga.
Tech Stack
- Frontend: Next.js 16 + TypeScript + shadcn/ui + Tailwind v4 + Framer Motion
- Backend: Rust (Axum gateway + worker pool with Tokio)
- Queue: NATS JetStream (job queue + progress pub/sub)
- Cache: Redis (job metadata, rate limiting)
- Image Processing:
image+imageproccrates (edge detection, warp, binarization, deskew) - OCR: Tesseract via
leptesscrate (optional feature)
Architecture
Browser → Next.js (frontend) → Rust Gateway (Axum) → NATS Queue → Workers (Tokio+Rayon)
↕ ↕
Redis Temp Storage
Directory Structure
apps/tools/
├── frontend/ # Next.js 16 SPA
│ ├── src/
│ │ ├── app/ # Pages + API routes
│ │ ├── components/# shadcn/ui components
│ │ └── hooks/ # Custom hooks (useJobStatus, useUpload)
│ ├── package.json
│ └── next.config.ts
├── backend/ # Rust workspace
│ ├── common/ # Shared types, errors, NATS constants
│ ├── gateway/ # Axum API server (upload, job, WS, download)
│ ├── workers/ # Processing workers (scanner, image, PDF)
│ └── wasm/ # WASM image processing (future)
├── scripts/
│ └── entrypoint.sh
└── Dockerfile
Development
# Start Redis + NATS
docker compose -f infra/compose/shared.yml -f infra/compose/nats.yml up -d
# Start Rust workers
cd apps/tools/backend
REDIS_URL=redis://localhost:6379 NATS_URL=nats://localhost:4222 cargo run --bin workers
# Start Rust gateway (another terminal)
REDIS_URL=redis://localhost:6379 NATS_URL=nats://localhost:4222 \
STORAGE_PATH=/tmp/tools cargo run --bin gateway
# Start Next.js frontend (another terminal)
cd apps/tools/frontend
bun dev --port 3002
Build
docker build -f infra/docker/tools.Dockerfile -t tools:latest .
Pipeline Stages (Document Scanner)
- Preprocess — Load, resize (max 2000px), grayscale
- Edge Detection — Canny with adaptive threshold + morphological close
- Corner Detection — Contour analysis with fallback chain
- Perspective Warp — DLT homography + bilinear interpolation
- Shadow Removal — Background subtraction + CLAHE
- Binarization — Sauvola local threshold (integral image accelerated)
- Deskew — Hough transform line detection
- Enhance — Unsharp mask + contrast adjustment
- OCR — Tesseract (English + Indonesian)
- PDF Generation — Searchable PDF with invisible text layer
Languages
Rust
61.8%
TypeScript
36%
CSS
1.2%
Shell
0.9%