Transform your reading experience with AI-generated visualizations
Live Demo Β· Documentation Β· Report Bug Β· Request Feature
English | Π ΡΡΡΠΊΠΈΠΉ
fancai is a modern web application for reading fiction with automatic AI-generated images based on scene descriptions. As you read, the app extracts visual descriptions from the text and generates stunning illustrations using state-of-the-art AI models.
π Upload Book β π AI Extracts Descriptions β π¨ Generate Images β β¨ Read with Visuals
- Upload your EPUB or FB2 book
- Read with a beautiful, customizable reader
- Discover highlighted descriptions as you read
- Generate AI illustrations for any scene with one click
- Save your progress and reading position automatically
| Feature | Description |
|---|---|
| π Multi-format Support | EPUB and FB2 formats with full metadata extraction |
| π€ LLM-Powered Extraction | Google Gemini identifies characters, scenes, and settings |
| π¨ AI Image Generation | Google Imagen 4 creates high-quality illustrations |
| π Smart Position Tracking | CFI-based reading position with pixel-perfect restoration |
| π Dark Mode | Comfortable reading day and night |
| π± PWA Ready | Install as an app, works offline |
| π Subscription Model | FREE / PREMIUM / ULTIMATE tiers |
| π Offline Sync | Queue operations offline, auto-sync when online |
| π‘οΈ Resilient APIs | Exponential backoff retry for all external services |
| π Secure Sessions | JWT token blacklist for secure logout |
Get Fancai running locally in under 5 minutes.
- Docker and Docker Compose
- Git
- Google Cloud API key (for Gemini + Imagen) - Get one here
# Clone the repository
git clone https://github.com/sandk0/fancai.git
cd bookreader-ai
# Copy environment template
cp .env.example .env
# Edit .env and add your API keys
nano .env # or use your preferred editor
# Start all services
docker-compose up -d
# Open in browser
open http://localhost:5173Create a .env file with these essential variables:
# Required
DB_PASSWORD=your_secure_password
REDIS_PASSWORD=your_redis_password
SECRET_KEY=your_jwt_secret_key
# AI Services (required for image generation)
GOOGLE_API_KEY=your_google_api_key
# Optional
DEBUG=true
CORS_ORIGINS=http://localhost:5173Note: See .env.example for all available options.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client (Browser) β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββββ β
β β React 19 β β epub.js β β TanStack Query + IndexedDB β β
β β + TypeScriptβ β EPUB Rendererβ β Caching Layer β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β REST API
ββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β ββββββββββββββββ βββββββββββββββββ ββββββββββββββββββββββββββββ β
β β Auth (JWT) β β Book Parser β β Description Extractor β β
β β β β EPUB/FB2 β β (Google Gemini 3.0 Flash)β β
β ββββββββββββββββ βββββββββββββββββ ββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Image Generator (Google Imagen 4) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β β
ββββββββββββ΄βββββββββββ βββββββββββ΄ββββββββββ
β PostgreSQL 15 β β Redis 7.4 β
β (Data Storage) β β (Cache + Queue) β
βββββββββββββββββββββββ βββββββββββββββββββββ
| Service | Purpose | Lines of Code |
|---|---|---|
book_parser.py |
EPUB/FB2 parsing, chapter extraction, CFI generation | 925 |
gemini_extractor.py |
LLM-based description extraction via Gemini API | 661 |
imagen_generator.py |
AI image generation via Imagen 4 | 644 |
retry.py |
Exponential backoff decorators (tenacity) | 515 |
reading_session_cache.py |
Redis-backed session caching | 454 |
auth_service.py |
JWT authentication and authorization | 373 |
token_blacklist.py |
JWT token revocation (Redis) | 156 |
Total Backend: 17+ services, 8,400+ lines of code
POST /api/v1/auth/register # Create account
POST /api/v1/auth/login # Get JWT token
POST /api/v1/auth/refresh # Refresh tokenGET /api/v1/books # List user's books
POST /api/v1/books/upload # Upload EPUB/FB2
GET /api/v1/books/{id} # Get book details
DELETE /api/v1/books/{id} # Delete bookGET /api/v1/chapters/{id} # Get chapter content
PUT /api/v1/books/{id}/progress # Update reading position
GET /api/v1/descriptions/{chapter_id} # Get extracted descriptionsPOST /api/v1/images/generate/{description_id} # Generate image
GET /api/v1/images/{id} # Get generated imageFull API Documentation: Available at
/docs(Swagger UI) when running locally.
| Metric | Value | Improvement |
|---|---|---|
| Database Query Time | <5ms | 100x faster (vs 500ms) |
| API Response (cached) | <50ms | 83% faster |
| Frontend TTI | 1.2s | 66% faster |
| Bundle Size | 386KB gzipped | 29% smaller |
| Memory Usage | 2-3 GB RAM | 75% reduction |
| Docker Image | 800 MB | 68% smaller |
- Database: JSONB + GIN indexes for 100x faster queries
- Caching: Redis with 85% cache hit rate
- Frontend: TanStack Query with stale-while-revalidate pattern
- Offline: IndexedDB caching for chapters and images
- Algorithms: O(n) text highlighting (vs O(nΒ²))
- EPUB/FB2 book parsing
- LLM-based description extraction (Gemini)
- AI image generation (Imagen 4)
- Reading progress tracking (CFI)
- Offline support (PWA + IndexedDB)
- Subscription system
- Resilient API calls (exponential backoff)
- JWT token blacklist (secure logout)
- Offline sync queue
- Integration test suite
- Theme system (Light/Dark/Sepia)
- iOS Mobile Optimizations (scroll/zoom fixes, safe-area)
- Mobile apps (React Native)
- Social features (sharing, comments)
- Multiple AI model support
- Book recommendations
See the open issues for planned features and known issues.
Contributions make the open-source community amazing. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please read CONTRIBUTING.md for details on our code of conduct and development process.
# Backend development
cd backend
pip install -r requirements.txt
pytest -v --cov=app # Run all tests with coverage
pytest tests/services/ -v # Unit tests only
pytest tests/integration/ -v # Integration tests only
mypy app/ # Type checking
# Frontend development
cd frontend
npm install
npm test # Run tests
npm run test:coverage # Run with coverage
npm run type-check # TypeScript check| Category | Tests | Description |
|---|---|---|
| Backend Unit | 35+ | Service-level tests |
| Backend Integration | 8 | End-to-end API flows |
| Frontend Hooks | 18 | React hooks tests |
| Total | 60+ | Full test suite |
fancai/
βββ frontend/ # React + TypeScript frontend
β βββ src/
β β βββ components/ # UI components (86 total)
β β β βββ Reader/ # EPUB reader (15 components)
β β β βββ Settings/ # Settings (8 components)
β β β βββ Library/ # Book library (6 components)
β β β βββ Admin/ # Admin panel (5 components)
β β β βββ UI/ # Shared UI (20+ components)
β β βββ hooks/ # React hooks (56 total)
β β β βββ api/ # TanStack Query hooks (5 files)
β β β βββ epub/ # EPUB reader hooks (22 files)
β β β βββ reader/ # Reader logic (9 files)
β β β βββ [15 top-level hooks]
β β βββ services/ # Caching services (9 files)
β β βββ stores/ # Zustand stores (6 files)
β β βββ utils/ # Utilities (10 files)
β β βββ pages/ # Page components (13 pages)
β βββ tests/ # Vitest tests
βββ backend/ # FastAPI + Python backend
β βββ app/
β β βββ routers/ # API endpoints (70+ endpoints)
β β βββ services/ # Business logic (17+ services)
β β βββ models/ # SQLAlchemy models (9 models)
β β βββ core/ # Config, DB, exceptions, retry
β βββ tests/
β βββ services/ # Unit tests (35+ files)
β βββ integration/ # Integration tests (8 files)
βββ docs/ # Documentation (Diataxis framework)
βββ docker-compose.lite.yml # Production stack
βββ scripts/ # Deployment scripts
Documentation follows the Diataxis framework:
| Category | Description | Link |
|---|---|---|
| Guides | Step-by-step tutorials and how-to guides | docs/guides/ |
| Reference | API, database, component specifications | docs/reference/ |
| Explanations | Architecture and design decisions | docs/explanations/ |
| Operations | Deployment and maintenance | docs/operations/ |
Quick Links:
Proprietary software. All rights reserved.
See LICENSE for more information.
- epub.js - EPUB rendering
- TanStack Query - Server state management
- FastAPI - Python web framework
- Google AI - Gemini and Imagen APIs
- Best-README-Template - README inspiration
Website Β· Documentation Β· Report Bug
Made with passion for readers everywhere