The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the Sourcelibrary V2 listing page.
Explore thousands of digitized historical texts with AI-enhanced translations and scholarly curation.
🎯 About Source Library
Source Library is an open digital library dedicated to making early printed books and primary sources readable and citable. We specialize in alchemy, Hermetica, Kabbalah, Rosicrucianism, and early modern science—texts that bridge historical scholarship with contemporary exploration.
🌟 Why Source Library?
✨ Originals First — Read the original language text with AI-enhanced translations alongside
🎓 Citable Scholarship — Every book gets a DOI and scholarly metadata (USTC alignment, edition tracking)
🔍 Discovery — Collections, galleries of illustrations, and semantic search surface overlooked texts
✅ Rigorous QA — Manual verification, image quality scoring, and OCR validation before publication
The platform ingests ~15K pages monthly from Internet Archive, Gallica, Bodleian, Wellcome, and other digital heritage partners.
🚀 Quick Start
💻 Development Environment
bash
# 🍴 Clone and install
git clone https://github.com/Embassy-of-the-Free-Mind/sourcelibrary-v2.git
cd sourcelibrary-v2
npm install
# ⚙️ Configure environment (see .env.example for required variables)
# Must include: MongoDB Atlas connection, Google Gemini API key, Vercel Blob token
# ▶️ Start dev server
npm run dev
🌍 Publishing — Set visible: true, mint DOI, push to search index
Batch endpoints process up to 5 pages/request using Gemini Batch API (50% cheaper).
🔌 API Routes (Key)
Base URL:https://sourcelibrary.org (production) or http://localhost:3000 (local dev with .env.local configured).
Common 404 mistake: paths like /api/bph/books or /api/bph/books/[id]do not exist. BPH catalogue APIs live under /api/embed/bph/.... There is also no top-level /api/[tenant]/books route — tenant book listings use /api/books/library or the embed routes below.
Public read APIs (no auth required today)
Endpoint
Method
Purpose
/api/search?q=<query>
GET
Full-text search across books and page translations
/api/books?limit=100&offset=0
GET
Simple book list (global catalogue; visible: true, indexed only)
/api/books/library?limit=100&skip=0
GET
Rich browse API — search, sort, filters, collections
The /api/[tenant]/books/[id]/... paths that exist in the codebase are editor/processing routes (batch OCR, index rebuild, etc.) — not public catalogue listings.
Authenticated / internal APIs
These require a signed-in session cookie, editor role, or (for some dataset endpoints) a Bearer API key. Calling them without auth returns 401 or 403.
All examples below hit production and need no API key. Replace the base URL with http://localhost:3000 when running locally (MongoDB + env vars required).
curl
bash
# Search translated text
curl -s "https://sourcelibrary.org/api/search?q=quintessence&limit=5" | jq .
# List books (global catalogue)
curl -s "https://sourcelibrary.org/api/books?limit=5" | jq .
# Browse with filters and sort
curl -s "https://sourcelibrary.org/api/books/library?limit=5&sort=recent-translation&has_translation=true" | jq .
# BPH catalogue — note /api/embed/bph/, NOT /api/bph/
curl -s "https://sourcelibrary.org/api/embed/bph/books?limit=5&translated=true" | jq .
# BPH via tenant_slug on the library endpoint
curl -s "https://sourcelibrary.org/api/books/library?tenant_slug=bph&limit=5" | jq .
# Book metadata (id or slug)
curl -s "https://sourcelibrary.org/api/books/know-thyself-reger-von-ehrenhart" | jq .
# Citable quote for a page
curl -s "https://sourcelibrary.org/api/books/6836f8ee811c8ab472a49e36/quote?page=57" | jq .
# Gallery search
curl -s "https://sourcelibrary.org/api/gallery?subject=alchemy&limit=5" | jq .
Pretty-printing with jq is optional; omit | jq . to see raw JSON.
Postman
Create a new GET request.
Set URL to e.g. https://sourcelibrary.org/api/embed/bph/books
On the Params tab add query keys: limit = 24, sort = title, translated = true
Leave Auth as No Auth for the public endpoints above.
// From the UI or via API
POST /api/books
{
"ia_id": "thehermetic00fludd",
"title": "The Hermetic and Alchemical Writings",
"author": "Arthur Edward Waite",
"language": "en",
"ustc_id": "123456"
}
The system:
📥 Fetches page images from IA IIIF
✂️ Detects splits and generates crop coordinates
📤 Queues for OCR and translation
🌍 Publishes when processing completes
✂️ Processing a Split Book
🖥️ Visit /book/[id]/split
🖱️ Adjust split line visually (drag or Gemini AI auto-detection)
✅ Click "Apply Split" — creates two virtual pages with crop coordinates
📸 Original images preserved; OCR runs on cropped versions
✍️ Batch OCR with Gemini Batch API
typescript
POST /api/books/[id]/batch-ocr-async
{
"page_ids": ["page-1", "page-2", "page-3"],
"language": "la"
}
Returns a job ID; Gemini processes offline, saves results when complete. 50% cheaper than standard API.
🎓 Generating a Scholarly Edition
typescript
POST /api/books/[id]/editions
{
"title": "The Emerald Tablet: First Complete English Translation",
"translator": "Jane Doe",
"language": "en",
"format": "epub"
}
System generates:
📝 Scholarly front matter (introduction, translator bio, etc.)
📱 EPUB with TOC and metadata
🆔 DOI via Zenodo integration
📚 Citation metadata (BibTeX, RIS)
🧪 Testing
🚀 Run Tests
bash
# Unit tests
npm run test:unit
# Integration tests
npm run test:integration
# End-to-end tests (Playwright)
npm run test:e2e
# Coverage report
npm run test:coverage
# Watch mode
npm run test:watch
We welcome contributions! Start with CONTRIBUTING.md — setup, the branch/PR workflow, how deploys work (and the Vercel setup you should NOT do), and the data-safety rules. Deeper doctrine lives in the development workflow. The short version:
🌿 Create a feature branch (off main):
bash
# Using git worktree for multi-session safety
git worktree add .claude/worktrees/feat-xyz feat/xyz
cd .claude/worktrees/feat-xyz
✏️ Make changes and test:
Terminal
npm run lint
npm run test
npm run test:e2e
📤 Push and create a PR:
bash
git push origin feat/xyz
gh pr create --base main
📋 PR guidelines:
One concern per PR — Don't bundle refactors with features
Verify deletions — Always grep -rn before deleting code
Run type check — npx tsc --noEmit before submitting
Describe scope — State what's in scope AND out of scope
🎯 What We're Looking For
🐛 Bug fixes with test coverage
✨ Feature implementations aligned with project mission
⚡ Performance improvements with benchmarks
📝 Documentation improvements
♿ UX/accessibility enhancements
🏢 Tenant integration examples
📢 Reporting Issues
🐛 Bugs — Include reproduction steps, expected vs. actual behavior
💡 Feature requests — Explain the use case and user impact