Skip to content

XKlibure/home-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Bookoholik β€” Home Library Management System

A modern, multilingual, self-hosted web application for managing your personal home library. Track books across multiple locations, scan book covers with AI, manage writers and publishers, lend books to friends, and generate reports β€” all from a responsive mobile-friendly interface.

Vue.js PHP PostgreSQL Docker GitHub stars License: MIT Docker SonarCloud


✨ Features

πŸ“· AI Book Scanner (NEW)

  • Scan book covers with your phone camera to extract title and author
  • Scan back pages to extract ISBN, publisher, and publication year
  • Powered by Google Gemini Flash Vision AI (free tier β€” 1,500 scans/day)
  • Supports Arabic calligraphy, French, and English book covers
  • Falls back to Tesseract OCR if no API key configured
  • Editable results β€” correct OCR output before searching/adding
  • Automatically searches your library for matches
  • One-tap "Add Book" with pre-filled details from scan

πŸ“– Book Management

  • Full CRUD for your book collection
  • Search by title, author, genre, language, year
  • Filter by read status, borrowed status, location
  • ISBN lookup via Open Library API
  • Assign books to specific shelves (Address β†’ Room β†’ Shelf)
  • Link books to publishers from your registry
  • Mark books as read/unread

πŸ“ Multi-Location Library (NEW)

  • Manage multiple physical addresses (Home, Office, Summer House, etc.)
  • Set a primary location for your library
  • Create rooms within each address (Living Room, Study, etc.)
  • Create shelves within each room with capacity tracking
  • Full hierarchy: Address β†’ Rooms β†’ Shelves β†’ Books
  • Visual tree view of your entire library layout
  • Book count per location/room/shelf

🏒 Publishers Management (NEW)

  • Dedicated publisher/edition house registry
  • Multilingual names (English, Arabic, French)
  • Contact info: address, city, country, phone, email, website
  • Link publishers to books
  • View book count per publisher

✍️ Writers Management

  • Dedicated writers/authors registry
  • Multilingual names (English, Arabic, French)
  • Nationality, birth/death year, biography
  • Select writers when adding a book (dropdown + manual entry)
  • View book count per writer

πŸ“– Genres Management

  • Create, edit, and delete genres
  • Multilingual genre names (English, Arabic, French)
  • Select genres when adding books

🀝 Lending System

  • Lend books to friends with due dates
  • Track overdue books with alerts
  • Mark books as returned
  • Full lending history per book

πŸ“Š Reports & Analytics

  • Dashboard with reading statistics
  • Reports by genre, author, year, location
  • Language distribution visualization
  • Export to CSV and PDF

πŸ‘₯ User Management (Admin)

  • Role-based access control (Admin, User, Viewer)
  • Create/disable/delete users
  • JWT-based authentication

βš™οΈ User Settings (NEW)

  • Update profile information (name, username, email)
  • Change password with strength validation
  • View account info and role

πŸ’Ύ Backup System

  • Automatic daily database backups (2:00 AM)
  • Manual backup creation
  • Download and manage backup files
  • Secure .pgpass authentication (no env var exposure)

🌍 Multilingual Interface

  • English πŸ‡¬πŸ‡§
  • Arabic πŸ‡ΈπŸ‡¦ (with full RTL support)
  • French πŸ‡«πŸ‡·
  • Language switcher in the UI, preference saved per user

πŸ“± Mobile Responsive (NEW)

  • Hamburger menu navigation on mobile
  • Touch-friendly card layouts
  • Camera capture directly from phone
  • Optimized for phone-first usage

πŸ”’ Security Hardened

  • Rate limiting on login (5/15min) and registration (3/hr)
  • CORS restricted to configured origin
  • Content Security Policy headers
  • JWT with 8-hour expiry
  • No hardcoded secrets β€” fails fast if env not set
  • Container resource limits
  • Password policy enforcement (10+ chars with complexity)
  • Command injection prevention

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Frontend                       β”‚
β”‚         Vue.js 3 + Vite + Tailwind CSS          β”‚
β”‚              (nginx:alpine)                      β”‚
β”‚                 Port 3000                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚ HTTP API calls
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Backend                        β”‚
β”‚     PHP 8.3 + Apache + Tesseract OCR + GD       β”‚
β”‚         Custom REST API + Gemini Vision         β”‚
β”‚                 Port 8080                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚ PostgreSQL protocol
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Database                        β”‚
β”‚              PostgreSQL 16 Alpine                β”‚
β”‚                   Port 5432                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/XKlibure/home-library.git
    cd home-library
  2. Configure environment

    cp .env.example .env
    # Edit .env β€” generate strong passwords:
    # DB_PASSWORD, JWT_SECRET, APP_KEY (see .env.example for instructions)

    For AI book scanning, add your free Gemini key:

    GEMINI_API_KEY=your-key-from-aistudio.google.com
  3. Build and start

    docker compose up -d --build

    Or with Podman:

    podman compose up -d --build
  4. Access the application

    Service URL
    Frontend http://localhost:3000
    Backend API http://localhost:8080/api
  5. Login

    Field Value
    Username admin
    Password Admin1234!

    ⚠️ Change this password immediately via Settings page!

Access from Phone (LAN)

To use the scanner from your phone on the same network:

# In .env, set your computer's LAN IP:
API_URL=http://192.168.1.x:8080/api
CORS_ORIGIN=http://192.168.1.x:3000

Then rebuild frontend: docker compose up -d --build frontend


πŸ“ Project Structure

home-library/
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ .env.example
β”œβ”€β”€ sonar-project.properties
β”œβ”€β”€ CONTRIBUTING.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ Dockerfile.frontend     # Vue.js multi-stage build
β”‚   β”œβ”€β”€ Dockerfile.backend      # PHP 8.3 + Apache + Tesseract + GD
β”‚   β”œβ”€β”€ Dockerfile.db           # PostgreSQL + init script
β”‚   β”œβ”€β”€ Dockerfile.backup       # Backup cron service
β”‚   β”œβ”€β”€ nginx.conf              # Frontend nginx + security headers
β”‚   β”œβ”€β”€ apache.conf             # Backend Apache vhost
β”‚   β”œβ”€β”€ init.sql                # Database schema (10 tables)
β”‚   └── backup-cron.sh          # Automated backup script
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ composer.json
β”‚   β”œβ”€β”€ public/index.php        # Entry point + CORS + security headers
β”‚   β”œβ”€β”€ routes/api.php          # 50+ API routes
β”‚   └── app/
β”‚       β”œβ”€β”€ Config/Database.php
β”‚       β”œβ”€β”€ Controllers/
β”‚       β”‚   β”œβ”€β”€ AuthController.php
β”‚       β”‚   β”œβ”€β”€ BooksController.php
β”‚       β”‚   β”œβ”€β”€ WritersController.php
β”‚       β”‚   β”œβ”€β”€ GenresController.php
β”‚       β”‚   β”œβ”€β”€ PublishersController.php    # NEW
β”‚       β”‚   β”œβ”€β”€ LocationsController.php    # NEW
β”‚       β”‚   β”œβ”€β”€ ScanController.php         # NEW (AI Vision)
β”‚       β”‚   β”œβ”€β”€ LendingController.php
β”‚       β”‚   β”œβ”€β”€ ReportsController.php
β”‚       β”‚   β”œβ”€β”€ UsersController.php
β”‚       β”‚   └── BackupController.php
β”‚       β”œβ”€β”€ Middleware/
β”‚       β”‚   β”œβ”€β”€ AuthMiddleware.php
β”‚       β”‚   β”œβ”€β”€ AdminMiddleware.php
β”‚       β”‚   β”œβ”€β”€ UserMiddleware.php         # NEW
β”‚       β”‚   └── RateLimiter.php            # NEW
β”‚       └── Router.php
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ vite.config.js
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   β”œβ”€β”€ index.html
β”‚   └── src/
β”‚       β”œβ”€β”€ main.js
β”‚       β”œβ”€β”€ App.vue                 # Responsive nav + hamburger menu
β”‚       β”œβ”€β”€ i18n/                   # en.js, ar.js, fr.js
β”‚       β”œβ”€β”€ router/index.js         # 15 routes with guards
β”‚       β”œβ”€β”€ services/api.js         # Axios + token expiry check
β”‚       β”œβ”€β”€ store/                   # auth.js, toast.js
β”‚       └── views/
β”‚           β”œβ”€β”€ LoginView.vue
β”‚           β”œβ”€β”€ DashboardView.vue
β”‚           β”œβ”€β”€ BooksView.vue
β”‚           β”œβ”€β”€ BookFormView.vue
β”‚           β”œβ”€β”€ BookDetailView.vue
β”‚           β”œβ”€β”€ ScanBookView.vue       # NEW (camera + AI)
β”‚           β”œβ”€β”€ WritersView.vue
β”‚           β”œβ”€β”€ GenresView.vue
β”‚           β”œβ”€β”€ PublishersView.vue      # NEW
β”‚           β”œβ”€β”€ LocationsView.vue      # NEW (hierarchy)
β”‚           β”œβ”€β”€ LendingView.vue
β”‚           β”œβ”€β”€ ReportsView.vue
β”‚           β”œβ”€β”€ SettingsView.vue       # NEW (profile + password)
β”‚           β”œβ”€β”€ UsersView.vue
β”‚           └── BackupView.vue
└── .github/
    β”œβ”€β”€ workflows/sonarqube.yml
    └── ISSUE_TEMPLATE/
        β”œβ”€β”€ bug_report.md
        └── feature_request.md

πŸ”Œ API Endpoints

Authentication

Method Endpoint Description
POST /api/auth/login Login (rate limited)
POST /api/auth/register Register (rate limited)
GET /api/auth/me Get current user
PUT /api/auth/profile Update profile info
PUT /api/auth/password Change password

Book Scanner

Method Endpoint Description
POST /api/scan/cover Scan front cover (AI + OCR)
POST /api/scan/back Scan back page (AI + OCR)

Books

Method Endpoint Description
GET /api/books List books (paginated, filterable)
GET /api/books/{id} Get book details + lending history
POST /api/books Create book
PUT /api/books/{id} Update book
DELETE /api/books/{id} Delete book
POST /api/books/{id}/toggle-read Toggle read status
POST /api/books/isbn-lookup Lookup by ISBN (Open Library)

Publishers

Method Endpoint Description
GET /api/publishers List publishers (searchable)
GET /api/publishers/{id} Get publisher details
POST /api/publishers Create publisher (admin)
PUT /api/publishers/{id} Update publisher (admin)
DELETE /api/publishers/{id} Delete publisher (admin)

Locations (Addresses β†’ Rooms β†’ Shelves)

Method Endpoint Description
GET /api/locations/tree Full hierarchy for dropdowns
GET /api/locations List all addresses
GET /api/locations/{id} Get address + rooms + shelves
POST /api/locations Create address (admin)
PUT /api/locations/{id} Update address (admin)
DELETE /api/locations/{id} Delete address (admin)
GET /api/locations/{id}/rooms List rooms in address
POST /api/rooms Create room (admin)
PUT /api/rooms/{id} Update room (admin)
DELETE /api/rooms/{id} Delete room (admin)
GET /api/rooms/{id}/shelves List shelves in room
POST /api/shelves Create shelf (admin)
PUT /api/shelves/{id} Update shelf (admin)
DELETE /api/shelves/{id} Delete shelf (admin)

Writers

Method Endpoint Description
GET /api/writers List all writers
GET /api/writers/{id} Get writer + books
POST /api/writers Create writer (admin)
PUT /api/writers/{id} Update writer (admin)
DELETE /api/writers/{id} Delete writer (admin)

Genres

Method Endpoint Description
GET /api/genres List all genres
POST /api/genres Create genre (admin)
PUT /api/genres/{id} Update genre (admin)
DELETE /api/genres/{id} Delete genre (admin)

Lending

Method Endpoint Description
GET /api/lending List lending records
POST /api/lending Lend a book
PUT /api/lending/{id} Update lending record
POST /api/lending/{id}/return Mark as returned
DELETE /api/lending/{id} Delete record
GET /api/lending/overdue Get overdue books

Reports

Method Endpoint Description
GET /api/reports/summary Dashboard stats
GET /api/reports/by-genre Books by genre
GET /api/reports/by-author Books by author
GET /api/reports/by-year Books by year
GET /api/reports/by-location Books by location
GET /api/reports/export/csv Export CSV
GET /api/reports/export/pdf Export PDF

Admin β€” Users & Backup

Method Endpoint Description
GET /api/users List users
PUT /api/users/{id} Update user
DELETE /api/users/{id} Delete user
POST /api/backup/create Create backup
GET /api/backup/list List backups
GET /api/backup/download/{file} Download backup
DELETE /api/backup/{file} Delete backup

πŸ”§ Common Operations

# Stop
docker compose down

# Reset database (fresh start)
docker compose down -v && docker compose up -d --build

# View logs
docker compose logs -f backend

# Rebuild single service
docker compose up -d --build frontend

# Access from phone (set your LAN IP in .env first)
API_URL=http://192.168.1.x:8080/api docker compose up -d --build frontend

πŸ”’ Security

This application is security-hardened against the OWASP Top 10:

Feature Status
SQL Injection protection (PDO prepared statements) βœ…
XSS prevention (Vue.js auto-escaping + htmlspecialchars) βœ…
CORS restricted to configured origin βœ…
JWT authentication with 8h expiry βœ…
Rate limiting (login: 5/15min, register: 3/hr) βœ…
Password policy (10+ chars, uppercase, lowercase, number) βœ…
Role-based access control (Admin/User/Viewer) βœ…
Security headers (CSP, X-Frame-Options, etc.) βœ…
No hardcoded secrets (fails fast if env not set) βœ…
Command injection prevention (escapeshellarg) βœ…
Container resource limits (memory/CPU) βœ…
Database port not exposed by default βœ…
Secure backup file permissions (chmod 600) βœ…
Request timeout (30s default, 60s for scans) βœ…
Token expiry check on frontend βœ…
Generic error messages (no stack traces to client) βœ…

See Security Notes below for production deployment checklist.

Production Deployment Checklist

  1. Generate strong secrets in .env (see .env.example)
  2. Change default admin password immediately
  3. Set APP_DEBUG=false
  4. Configure CORS_ORIGIN to your frontend domain
  5. Deploy behind HTTPS reverse proxy (nginx/Caddy/Traefik)
  6. Database port is NOT exposed by default βœ“
  7. Optionally disable open registration (see CONTRIBUTING.md)

πŸ› οΈ Tech Stack

Layer Technology
Frontend Vue.js 3, Vite 5, Tailwind CSS 3, Pinia, Vue Router, Vue I18n, Axios
Backend PHP 8.3, Apache, Custom Router, Firebase PHP-JWT, DomPDF, Tesseract OCR
AI Vision Google Gemini Flash (free tier)
Database PostgreSQL 16 (10 tables)
Containerization Docker / Podman Compose
Web Server Nginx Alpine (frontend), Apache (backend)
CI/CD GitHub Actions + SonarQube
Backup pg_dump + cron + gzip

🀝 Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.


πŸ“„ License

This project is licensed under the MIT License. You are free to use, modify, and distribute this software.

About

"πŸ“š Self-hosted multilingual home library management system with AI book scanning. Vue 3 + PHP + PostgreSQL. Supports Arabic, English & French."

Topics

Resources

License

Contributing

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors