Skip to content

About

Self-hosted React Native & Node.js app for managing e-books/audiobooks on VPS via Docker and GitHub Actions

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

Personal Library Application

TypeScript React Native Expo Node.js Express Docker

A modern, full-stack personal library management system

Features • Installation • API Reference • Tech Stack


Architecture

Technology Stack

Frontend (Mobile)

  • React Native with Expo
  • TypeScript for type safety
  • Axios for HTTP client
  • expo-document-picker for file uploads

Backend (API Server)

  • Node.js with Express
  • Multer for multipart uploads
  • pdf2pic for cover generation
  • GraphicsMagick & Ghostscript for PDF processing

Project Structure

my-library-project/
├── backend/                  # Node.js API server
│   ├── server.js            # Express application
│   ├── Dockerfile           # Container configuration
│   ├── docker-compose.yml   # Docker orchestration
│   └── books/               # Storage directory
│
└── frontend/                # React Native mobile app
    └── mobile/              # Expo project
        ├── src/
        │   ├── core/        # Configuration (config.ts)
        │   ├── services/    # API integration (api.ts)
        │   ├── types/       # TypeScript definitions
        │   ├── components/  # UI components (BookCard, UploadButton)
        │   └── screens/     # Application views (HomeScreen)
        ├── App.tsx          # Application entry point
        ├── package.json     # Dependencies
        └── app.json         # Expo configuration

Features

Core Functionality

Library Management

  • Browse complete book collection
  • Pull-to-refresh synchronization
  • Tap-to-open integration with system PDF viewer
  • Real-time upload status tracking

File Upload

  • Native document picker integration
  • Multi-format support (PDF, EPUB, FB2, CBZ, MP3, M4B)
  • Progress indicators during upload
  • Automatic metadata extraction

PDF Cover Generation

  • Automatic first-page extraction
  • Server-side rendering at 600x800px
  • Cached JPG thumbnails for performance
  • Fallback icons for non-PDF formats

User Experience

Dark Mode Theme

  • Background: #121212
  • Surface: #1E1E1E
  • Accent: #BB86FC
  • Optimized for OLED displays

Responsive Design

  • Book cover aspect ratio: 1:1.4
  • Rounded corners: 8px
  • Smooth animations and transitions
  • Loading states for async operations

API Reference

Authentication

All requests require API key header:

x-api-key: admin

Endpoints

GET /api/books

Returns array of books with metadata.

Response:

[
  {
    "id": "book.pdf",
    "name": "My Book",
    "url": "/books/book.pdf?key=admin",
    "coverUrl": "/books/book-cover.jpg?key=admin"
  }
]

POST /api/upload

Upload a new book file.

Request:

  • Content-Type: multipart/form-data
  • Field name: book

Response:

{
  "message": "Success",
  "filename": "uploaded-file.pdf"
}

Installation & Setup

Prerequisites

  • Node.js 16+
  • Docker & Docker Compose (for backend)
  • Expo CLI (installed automatically)

Backend Deployment

  1. Navigate to backend directory:
cd backend
  1. Build and start Docker container:
docker-compose up -d --build
  1. Verify installation:
docker logs my-library-backend
docker exec my-library-backend gm version

Frontend Setup

  1. Navigate to frontend directory:
cd frontend/mobile
  1. Install dependencies:
powershell -ExecutionPolicy Bypass -Command "npm install"
  1. Configure API endpoint:

Edit src/core/config.ts:

export const config = {
  API_URL: 'http://YOUR_VPS_IP:3000',  // Update this
  API_KEY: 'admin',
} as const;
  1. Start development server:
powershell -ExecutionPolicy Bypass -Command "npm start"
  1. Run on device:
  • Install Expo Go app on iOS/Android
  • Scan QR code from terminal
  • Or press a for Android emulator / i for iOS simulator

Development

Frontend Architecture

Clean Architecture Principles

src/
├── core/           # Application configuration
├── services/       # External service integration
├── types/          # Type definitions
├── components/     # Presentational components
└── screens/        # Container components

Component Structure

  • BookCard: Displays book with cover or fallback icon
  • UploadButton: File picker with upload progress
  • HomeScreen: Main view with list and refresh control

Backend Architecture

Cover Generation Flow

  1. File uploaded via POST /api/upload
  2. If PDF, trigger background cover generation
  3. Extract first page using pdf2pic
  4. Convert to 600x800px JPEG
  5. Save as {filename}-cover.jpg
  6. Subsequent API calls include coverUrl

Performance Optimization

  • Non-blocking cover generation
  • Cached thumbnails
  • Quality optimized at 100 DPI
  • Average processing: 1-3 seconds per PDF

Configuration

Backend Environment

Dockerfile:

  • Base: node:18-alpine
  • System deps: graphicsmagick, ghostscript
  • Port: 3000
  • Volume: ./books

Server Settings:

const PORT = 3000;
const API_KEY = 'admin';
const BOOKS_DIR = path.join(__dirname, 'books');

Frontend Configuration

TypeScript:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Expo:

{
  "expo": {
    "userInterfaceStyle": "dark",
    "orientation": "portrait"
  }
}

Production Deployment

Security Considerations

  1. Change Default API Key
// backend/server.js
const API_KEY = process.env.API_KEY || 'your-secure-key';
  1. Enable HTTPS
  • Use reverse proxy (nginx, Caddy)
  • Configure SSL certificates
  • Update frontend API_URL to https://
  1. Rate Limiting
  • Implement request throttling
  • Add file size limits
  • Configure CORS appropriately

Scaling

Storage:

  • Mount external volume for books/
  • Consider S3-compatible storage
  • Implement periodic backups

Performance:

  • Enable gzip compression
  • Add CDN for book delivery
  • Cache API responses

Troubleshooting

Common Issues

PowerShell Execution Policy

Error: "running scripts is disabled"

Solution:

powershell -ExecutionPolicy Bypass -Command "your-command"

Cover Generation Failed

Check server logs:

docker logs my-library-backend

Verify GraphicsMagick:

docker exec my-library-backend gm version

Android Emulator Connection

Use special localhost address:

API_URL: 'http://10.0.2.2:3000'

TypeScript Errors

Install dependencies first:

cd frontend/mobile
npm install

Technical Specifications

Image Processing

Cover Generation:

  • Library: pdf2pic v3.1.3
  • Format: JPEG
  • Server dimensions: 600×800px
  • Mobile display: 56×78px
  • Aspect ratio: 1:1.4
  • Quality: 100 DPI

File Support:

  • PDF (with cover generation)
  • EPUB, FB2 (icon fallback)
  • CBZ (comic books)
  • MP3, M4B (audiobooks)

Performance Metrics

  • Upload response: <500ms (excluding cover generation)
  • Cover generation: 1-3 seconds (background)
  • API list response: <100ms
  • Mobile app startup: <2 seconds

License

MIT License - See LICENSE file for details


Contributing

This project follows clean architecture and TypeScript strict mode. Pull requests welcome.

Code Style

  • Use TypeScript strict mode
  • Follow ESLint configuration
  • Document public APIs
  • Write self-documenting code

Commit Guidelines

  • Use conventional commits format
  • Include relevant test coverage
  • Update documentation as needed

Built with Clean Architecture principles for maintainability and scalability.

About

Self-hosted React Native & Node.js app for managing e-books/audiobooks on VPS via Docker and GitHub Actions

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages