How samit26/readwisely works
Purpose and Runtime
BookReader Web is a Vite-built, fully client-side React ebook reader for EPUB and PDF files. It has no application backend or accounts: browser storage holds library and reading state, while optional translation calls Google Gemini directly using the user’s API key. Static deployment is configured for Netlify.
Entry points: src/main.jsx, src/App.jsx, index.html, netlify.toml.
Application Composition
App assembles global providers and switches the primary experience between the library, reader, and settings surfaces. Shared contexts centralize state and cross-cutting UI notifications rather than introducing a server-side domain layer.
Core paths:
• src/App.jsx
• src/context/AppProviders.jsx
• src/context/LibraryContext.jsx
• src/context/SettingsContext.jsx
• src/context/ToastContext.jsx
Library and Import Workflow
The library is the book-management boundary: it displays shelves, search/status information, import UI, storage warnings, backup actions, and book cards. Drag/drop or file upload initiates metadata extraction and persistence of the book record plus its raw bytes; opening a card transitions into the reader for that book.
Core paths:
• src/components/Library/LibraryView.jsx
• src/components/Library/UploadZone.jsx
• src/components/Library/BookCard.jsx
• src/lib/metadata.js
• src/lib/pdfToEpub.js
Persistent Client Data
IndexedDB is the durable content store, separating lightweight books metadata from raw blobs so library listing does not require loading files. It also stores highlights and bookmarks. localStorage holds settings, per-book reading positions, and the Gemini key. Backup/export-import serializes the local library as a ZIP, providing the portability/sync boundary.
Core paths:
• src/lib/db.js
• src/lib/storage.js
• src/lib/backup.js
• src/components/Library/BackupBar.jsx
Reader Engine Abstraction
The reader UI talks to a common engine interface and treats locations as opaque. Engine implementations expose lifecycle, navigation, location/progress, TOC, search, and annotation operations, then emit events such as loaded, relocated, selected, and error. This preserves a unified toolbar/sidebar workflow while respecting fundamentally different document models.
Core paths:
• src/lib/reader/readerEngine.js
• src/lib/reader/emitter.js
• src/lib/reader/epubEngine.js
• src/lib/reader/pdfEngine.js
Format-Specific Rendering and Reader UI
EPUB uses epub.js-style paginated, reflowable rendering and CFI-based locations/selections. PDF uses pdf.js-style continuous scrolling with lazy page rendering and page/normalized-rectangle highlights. ReaderView owns engine integration; toolbar, sidebar, selection menu, recap, translation, and typography panels consume the reader state/events.
Core paths:
• src/components/Reader/ReaderView.jsx
• src/components/Reader/ReaderToolbar.jsx
• src/components/Reader/ReaderSidebar.jsx
• src/components/Reader/SelectionMenu.jsx
• src/components/Reader/TypographyPanel.jsx
Annotation, Position, and Presentation Flow
Reader actions create highlights, notes, and bookmarks through the active engine and IndexedDB. Relocation events update per-book position storage, enabling “continue reading” and library progress. Settings context supplies themes and typography preferences consumed by reader styles and controls.
Core paths:
• src/components/Reader/ReaderView.jsx
• src/components/Reader/ReaderSidebar.jsx
• src/context/SettingsContext.jsx
• src/styles/reader.css
External Boundary and Deployment
Gemini translation is the sole data-bearing network integration. Selected text is sent browser-to-Google with the locally stored BYOK credential; typed failures drive explicit UI states instead of silent failures. The app otherwise runs offline after assets load and deploys as a static SPA.
Core paths:
• src/lib/gemini.js
• src/components/Reader/TranslatePopover.jsx
• netlify.toml
• vite.config.js
Main entry points: ReaderView.jsx Reader view · App.jsx App router shell · LibraryView.jsx Library view · db.js IndexedDB library store
Components 21
App shell
- Vite entry
src/main.jsx - App router shell · Switches between library, reader, and settings surfaces.
src/App.jsx - Global providers · Supplies library, settings, and toast state.
src/context/AppProviders.jsx - Library state
src/context/LibraryContext.jsx - Settings state · Persists preferences, positions, and Gemini credential.
src/context/SettingsContext.jsx
Library workflow
- Library view · Displays shelves, search, status, import, and storage actions.
src/components/Library/LibraryView.jsx - Book import · Accepts dropped or selected EPUB/PDF files.
src/components/Library/UploadZone.jsx - Metadata extraction · Extracts book metadata and converts PDF when needed.
src/lib/metadata.js - Book cards · Opens a selected book in the reader.
src/components/Library/BookCard.jsx - Backup / restore · Exports or imports the local library ZIP.
src/components/Library/BackupBar.jsx
Client persistence
- IndexedDB library store · Separates book metadata, raw blobs, highlights, and bookmarks.
src/lib/db.js - localStorage state · Stores settings, reading positions, and Gemini key.
src/lib/storage.js - ZIP backup codec
src/lib/backup.js
Reader runtime
- Reader view · Owns active-engine lifecycle and reader event state.
src/components/Reader/ReaderView.jsx - Reader engine interface · Unifies lifecycle, navigation, location, search, and annotations.
src/lib/reader/readerEngine.js - EPUB engine · Uses paginated rendering with CFI locations.
src/lib/reader/epubEngine.js - PDF engine · Uses lazy continuous pages and rectangle highlights.
src/lib/reader/pdfEngine.js - Reader controls · Provides navigation, TOC, search, and annotation workflows.
src/components/Reader/ReaderSidebar.jsx
External delivery
- Gemini translation · Sends selected text directly to Google Gemini.
src/lib/gemini.js - Translation popover · Shows translation and typed error states.
src/components/Reader/TranslatePopover.jsx - Netlify static deployment
netlify.toml
Connections 26
- Vite entry → App router shell: mounts
- App router shell → Global providers: wraps with
- Global providers → Library state: provides
- Global providers → Settings state: provides
- App router shell → Library view: shows library
- App router shell → Reader view: opens reader
- Library view → Book import: hosts
- Book import → Metadata extraction: imports files through
- Metadata extraction → IndexedDB library store: stores metadata and blobs
- Library state → IndexedDB library store: loads library
- Library view → Book cards: renders
- Book cards → Reader view: selects book
- Library view → Backup / restore: offers
- Backup / restore → ZIP backup codec: uses
- ZIP backup codec → IndexedDB library store: exports/imports
- Settings state → localStorage state: persists
- Reader view → Reader engine interface: controls
- Reader engine interface → EPUB engine: implemented by
- Reader engine interface → PDF engine: implemented by
- Reader view → IndexedDB library store: reads books and saves annotations
- Reader view → localStorage state: updates reading position
- Reader view → Reader controls: drives state for
- Reader view → Translation popover: provides selection
- Translation popover → Gemini translation: requests translation
- Gemini translation → localStorage state: reads BYOK credential
- Netlify static deployment → Vite entry: serves static SPA