Skip to content

chiatzenw-cur/ReaderCompanion

Repository files navigation

πŸ“š Reader Companion

TypeScript React Electron PDF.js License: MIT

A modern desktop PDF reader with AI-powered analysis capabilities. Built with TypeScript, Electron, React, and PDF.js.

δΈ­ζ–‡ζ–‡ζ‘£ | English

✨ Features

πŸ“– PDF Reading

  • Modern PDF Viewer: Built with PDF.js for reliable PDF rendering
  • Text Selection: Select text with mouse or OCR-based area selection
  • Cross-Platform: Windows, macOS, and Linux support
  • Dark/Light Theme: Automatic system theme detection with manual override

πŸ€– AI Integration

  • Multiple AI Providers: Support for OpenAI GPT and DeepSeek models
  • Contextual Analysis: AI analyzes selected PDF text and provides insights
  • Smart Conversations: Maintains conversation history for context-aware responses
  • Custom System Prompts: Customize AI behavior for different document types

πŸ’¬ Chat Interface

  • Markdown Support: Rich text rendering with syntax highlighting
  • Export Options: Export conversations as Markdown files
  • Copy Functionality: Copy individual messages or entire conversations
  • Message Regeneration: Regenerate AI responses if needed

βš™οΈ Configuration

  • Persistent Settings: All configurations saved automatically
  • API Key Management: Secure storage of API keys
  • Auto-save: Settings and API keys saved automatically
  • Language Support: Chinese and English interface

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn package manager

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/reader-companion.git
    cd reader-companion
  2. Install dependencies

    npm install
  3. Start development server

    npm run dev

Building for Production

# Build for current platform
npm run build

# Build for all platforms
npm run build:all

# Build for specific platform
npm run build:win    # Windows
npm run build:mac    # macOS
npm run build:linux  # Linux

πŸ”§ Configuration

AI Provider Setup

  1. Open Settings: Click the settings icon in the chat panel
  2. Choose Provider: Select OpenAI or DeepSeek
  3. Add API Key: Enter your API key (auto-saved)
  4. Select Model: Choose from available models
  5. Test Connection: Verify your configuration works

Supported AI Models

OpenAI

  • GPT-4
  • GPT-4 Turbo
  • GPT-3.5 Turbo
  • GPT-3.5 Turbo 16K

DeepSeek

  • DeepSeek Chat
  • DeepSeek Coder

Custom Endpoints

You can configure custom API endpoints for self-hosted or third-party compatible APIs.

πŸ’‘ Usage

Basic Workflow

  1. Open PDF: Use Ctrl+O or menu to open a PDF file
  2. Select Text: Click and drag to select text in the PDF
  3. AI Analysis: Selected text is automatically sent to AI for analysis
  4. Chat: Continue the conversation with follow-up questions
  5. Export: Save your conversation as a Markdown file

Text Selection Methods

  • PDF Text Layer: Direct text selection from PDF (when available)
  • OCR Selection: Draw rectangles to select areas for OCR text recognition
  • Automatic Fallback: System automatically switches to OCR if text layer fails

Keyboard Shortcuts

  • Ctrl+O: Open PDF file
  • Enter: Send message in chat
  • Shift+Enter: New line in chat input

πŸ—οΈ Architecture

Technology Stack

  • Frontend: React 18 with TypeScript
  • Desktop: Electron for cross-platform desktop app
  • PDF Rendering: PDF.js for reliable PDF display
  • OCR: Tesseract.js for optical character recognition
  • Styling: Tailwind CSS with dark mode support
  • State Management: React Context API
  • Build: Vite for fast development and building

Project Structure

src/
β”œβ”€β”€ components/          # React components
β”‚   β”œβ”€β”€ ChatPanel.tsx   # Chat interface
β”‚   β”œβ”€β”€ PDFViewer.tsx   # PDF display and selection
β”‚   β”œβ”€β”€ SettingsPanel.tsx # Configuration UI
β”‚   └── MessageBubble.tsx # Chat message display
β”œβ”€β”€ contexts/           # React contexts
β”‚   β”œβ”€β”€ AppContext.tsx  # Global app state
β”‚   β”œβ”€β”€ ChatContext.tsx # Chat functionality
β”‚   └── PDFContext.tsx  # PDF state management
β”œβ”€β”€ services/           # Business logic
β”‚   └── aiService.ts    # AI API integration
β”œβ”€β”€ i18n/              # Internationalization
β”‚   β”œβ”€β”€ translations.ts # Translation definitions
β”‚   └── useTranslation.ts # Translation hook
β”œβ”€β”€ types/             # TypeScript definitions
└── App.tsx           # Main application component

Data Flow

  1. PDF Loading: Electron main process handles file dialogs and loading
  2. Text Selection: Component captures selection and stores in context
  3. AI Processing: Service layer handles API requests to AI providers
  4. UI Updates: React contexts trigger re-renders with new data
  5. Persistence: Settings automatically saved via Electron APIs

πŸ”’ Privacy & Security

  • Local Storage: All settings and conversations stored locally
  • API Key Security: Keys encrypted and stored in system keychain
  • No Data Collection: No telemetry or usage data sent externally
  • Offline Capable: OCR processing works offline

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Use existing component patterns
  • Write clear commit messages
  • Test on multiple platforms when possible

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Screenshots

!()[./readme_pics/ss1.png] !()[./readme_pics/ss2.png]

Vibe coded with Claude code