A local-first, distributed Optical Character Recognition (OCR) platform built with Go, React, and Wails.
In the modern digital infrastructure, organizations face a massive bottleneck: the digitization of physical archives. Processing tens of thousands of high-resolution pages is computationally expensive and slow on a single machine. Cloud solutions (like AWS Textract) introduce severe data privacy concerns (HIPAA, GDPR) and require constant internet connectivity.
Swarm solves this by creating a decentralized compute grid out of ad-hoc local devices (laptops, desktops) sitting around in your office. It uses a Master-Worker topology over a Local Area Network (LAN) to securely and privately distribute OCR tasks using advanced distributed systems techniques.
- Privacy-First & Local: Zero cloud dependency. Sensitive documents (medical records, legal contracts) never leave your local network. Air-gap friendly.
- Dynamic Load Balancing (Work Stealing): Idle worker nodes proactively "steal" tasks from busy nodes via direct P2P RPC, ensuring maximum CPU utilization across the cluster.
- Autonomic Peer Discovery (SWIM Gossip): Nodes dynamically form a mesh network via UDP multicast gossip. If a laptop is closed or disconnects, the cluster self-heals without task loss.
- Result Verification (Consensus): Implements redundant execution. Multiple workers process the same chunk and the Master verifies consensus to defend against malicious nodes or corrupted processing.
- Cross-Platform GUI: A sleek interface built with React, Vite, and Wails, giving a native desktop feel on Mac, Windows, and Linux.
The architecture relies on high-performance concurrent processing in Go and robust networking protocols:
- Master Node (Orchestrator): Runs the Wails GUI, manages the Global Job Queue, parses multi-page PDFs locally, and validates the integrity of returned OCR data.
- Worker Nodes: Stateless compute units running the Tesseract CGO wrapper. Features a local Double-Ended Queue (Deque) optimized for both LIFO local processing (cache locality) and FIFO work stealing.
See explanation.md for a deep dive into the network topologies and data flow.
To run or develop Swarm, ensure you have the following installed:
- Go (1.20+)
- Node.js & npm
- Wails Setup
- Tesseract OCR: Required on each machine for the core engine:
- macOS:
brew install tesseract - Linux (Ubuntu):
sudo apt-get install tesseract-ocr libtesseract-dev - Windows: UB-Mannheim Tesseract installer
- macOS:
(Note: We use github.com/gen2brain/go-fitz for cross-platform PDF handling).
-
Clone the Repository:
git clone https://github.com/your-org/distributed-ocr.git cd distributed-ocr -
Frontend Setup: The project uses a React/Vite frontend located in
/frontend.cd frontend npm install npm run dev -
Backend/App Setup: The main Wails application is bound in
app.go. To run the application in development mode with hot-reloading:# From the project root wails devLinux Users: Run with
wails dev -tags webkit2_41to support specific webkit dependencies.
To see the distributed work stealing and gossip protocols in action across physical machines:
- LAN Connection: Connect multiple computers (e.g., Laptop A and Laptop B) to the exact same local Wi-Fi or router.
- Build the Release:
Compile the app for production on both machines:
wails build
- Launch Nodes: Open the compiled app executable (found in
build/bin/) on both computers. - Discover Peers: On Laptop A (your designated Master), click Scan For Nodes. The UDP gossip protocol will automatically discover Laptop B's IP address.
- Distribute Work: Click Upload Document on Laptop A and select a large PDF.
- Watch the Magic: Laptop A chunks the PDF and distributes it via RPC. Laptop B will compute the OCR using its local Tesseract instance and return strings back to Laptop A to be verified and stitched back together!
/frontend- React, TypeScript, Vite frontend source./master- Orchestrator logic, consensus verification, and job queuing./worker- Node executor, Task Deque, and Tesseract C/Go bindings./swim- Custom UDP Gossip and discovery protocol implementation./rpc- Protobuf/TCP communication interfaces for task assignments and work stealing.
We welcome pull requests!
- Create a new branch for your feature (
git checkout -b feature/nice-feature). - Make your backend changes in Go or frontend changes inside
/frontend. - Please do not commit to
maindirectly. - Submit a PR!
GNU GPL V3
