V2.0 Refactor Summary¶
What Was Built¶
1. FastAPI Backend (/backend)¶
A complete REST API backend that works in both desktop (SQLite) and web (PostgreSQL) modes.
Structure:¶
backend/
├── app/
│ ├── main.py # FastAPI application with CORS
│ ├── config.py # Environment-aware configuration
│ ├── database.py # SQLAlchemy async setup
│ ├── models/
│ │ ├── base.py # Base model with timestamps
│ │ ├── book.py # Book model
│ │ ├── annotation.py # Highlight, Note, ChatContext
│ │ └── settings.py # UserSettings model
│ ├── routers/
│ │ ├── books.py # Book CRUD + file serving
│ │ ├── annotations.py # Annotations CRUD
│ │ └── settings.py # Settings management
│ └── services/
│ └── epub_service.py # EPUB processing (metadata, cover)
└── requirements.txt
Key Features:¶
- ✅ Environment detection (
VIBEREADER_DESKTOP=true/false) - ✅ SQLite for desktop, PostgreSQL for web
- ✅ File storage in
~/VibeReader/(desktop mode) - ✅ EPUB metadata extraction with ebooklib
- ✅ Cover image extraction and base64 encoding
- ✅ SHA256 file hashing for duplicate detection
- ✅ Full CRUD for books, highlights, notes, chat contexts
- ✅ Reading progress tracking
- ✅ Settings persistence
API Endpoints:¶
POST /api/books/import # Import EPUB
GET /api/books # List books
GET /api/books/{id} # Get book
GET /api/books/{id}/file # Download EPUB
PATCH /api/books/{id}/progress # Update progress
DELETE /api/books/{id} # Delete book
POST /api/annotations/highlights # Create highlight
GET /api/annotations/highlights/book/{id}
PATCH /api/annotations/highlights/{id}
DELETE /api/annotations/highlights/{id}
POST /api/annotations/notes # Create note
GET /api/annotations/notes/book/{id}
GET /api/annotations/notes/range/{book_id}/{cfi}
PATCH /api/annotations/notes/{id}
DELETE /api/annotations/notes/{id}
POST /api/annotations/chat-contexts
GET /api/annotations/chat-contexts/book/{id}
GET /api/annotations/chat-contexts/range/{book_id}/{cfi}
PATCH /api/annotations/chat-contexts/{id}
DELETE /api/annotations/chat-contexts/{id}
GET /api/settings
PATCH /api/settings/reading
PATCH /api/settings/api
2. Electron Desktop Wrapper (/desktop)¶
Electron application that spawns the FastAPI backend and loads the React frontend.
Files:¶
main.js- Main process (window management, backend spawning)preload.js- IPC bridge (exposes safe APIs to renderer)package.json- Electron + electron-builder config
Features:¶
- ✅ Spawns Python backend on startup
- ✅ Loads frontend from Vite dev server (dev) or built files (prod)
- ✅ Native file picker for EPUB import
- ✅ Platform detection
- ✅ Graceful backend shutdown
- ✅ Health check before showing window
Build Configuration:¶
- macOS: .dmg, .zip
- Windows: .exe (NSIS installer), portable
- Linux: .AppImage, .deb
3. Frontend API Services (/frontend/src/services)¶
New TypeScript services that replace IndexedDB with REST API calls.
Files Created:¶
apiClient.ts- Platform-aware HTTP clientbookApiService.ts- Book operationsannotationApiService.ts- Annotation operationssettingsApiService.ts- Settings operations
Key Features:¶
- ✅ Auto-detects Electron vs web mode
- ✅ Gets API URL from Electron IPC or environment
- ✅ Type-safe interfaces matching backend models
- ✅ Error handling with detailed messages
- ✅ File upload support
4. Documentation¶
README.md- Updated with v2.0 architecturedocs/getting-started/development.md- Complete dev setup guidedocs/development/migration-guide.md- Step-by-step migration from v1docs/fixes/refactor-summary.md- This filebackend/README.md- Backend-specific docs
What Still Needs to Be Done¶
Priority 1: Frontend Migration¶
- Update
Library.tsxto usebookApiService - Update
Reader.tsxto load EPUB from API URL - Update
ReaderSettings.tsxto usesettingsApiService - Update
AnnotationPanel.tsxto useannotationApiService - Update
UnifiedContextMenu.tsxfor highlight creation - Update
NoteDialog.tsxfor note management - Update
ChatPanel.tsxfor chat context storage
Priority 2: Desktop Build¶
- Set up PyInstaller to bundle Python runtime
- Create build scripts for all platforms
- Test desktop builds on macOS, Windows, Linux
- Set up code signing certificates
- Configure auto-updater
Priority 3: Testing¶
- Backend unit tests (pytest)
- Frontend component tests
- E2E tests (Playwright)
- Desktop app smoke tests
Priority 4: Features¶
- Nostr integration (NIP-84 highlights)
- AI chat with LangGraph
- Cloud storage adapter for web mode
- Data export/import
- Search functionality
Migration Strategy¶
Phase 1: Parallel Implementation (Current)¶
- ✅ New API services exist alongside old IndexedDB code
- ✅ No breaking changes to existing functionality
- ✅ Can test backend independently
Phase 2: Component-by-Component Migration (Next)¶
- Start with
Library.tsx(simplest) - Move to
Reader.tsx(core functionality) - Migrate annotation components
- Update settings management
- Remove old IndexedDB code
Phase 3: Desktop Build (After Migration)¶
- Bundle Python with PyInstaller
- Test desktop builds
- Set up CI/CD for releases
Phase 4: Production (Final)¶
- Deploy web version
- Publish desktop apps
- Set up auto-updates
Testing the Backend¶
1. Install Dependencies¶
2. Run Backend¶
3. Test API¶
Visit http://localhost:8000/docs for interactive API testing
4. Test with curl¶
# Health check
curl http://localhost:8000/health
# Import book
curl -X POST http://localhost:8000/api/books/import \
-F "file=@/path/to/book.epub"
# Get books
curl http://localhost:8000/api/books
Testing the Desktop App¶
1. Install Dependencies¶
2. Run in Dev Mode¶
This will:
1. Start backend from ../backend/venv/bin/python
2. Load frontend from http://localhost:5173 (Vite dev server)
3. Open Electron window
3. Check Logs¶
- Backend logs appear in terminal
- Frontend logs in Electron DevTools (Cmd+Option+I)
Database Locations¶
Desktop Mode¶
~/VibeReader/
├── vibereader.db # SQLite database
├── books/ # EPUB files
│ └── {hash}.epub
└── covers/ # Cover images (future)
Inspecting Database¶
Architecture Benefits¶
Code Reuse¶
- Frontend: 100% shared between desktop and web
- Backend: ~95% shared (only storage layer differs)
Flexibility¶
- Desktop: Local-first, privacy-focused
- Web: Cloud-hosted, auto-sync
- Both: Same features, same codebase
Future-Proof¶
- Easy to add features to both versions
- Can switch between SQLite and PostgreSQL
- Can add cloud storage adapters
- Can integrate external services (Nostr, AI)
Next Steps¶
- Test the backend - Make sure it works standalone
- Start migration - Begin with
Library.tsx - Iterate - Migrate one component at a time
- Test thoroughly - Ensure no regressions
- Remove old code - Clean up IndexedDB services
- Build desktop - Set up PyInstaller bundling
- Deploy - Web version and desktop releases
Questions?¶
See the documentation: - Development Setup - Setup and workflow - Migration Guide - Migration details - Electron Architecture - Desktop architecture