Laravel 12 REST API backend for the LivroLog personal library management system.
- Laravel 12 with PHP 8.4
- MySQL 8.0 for primary database
- Redis 7.0 for caching and sessions
- Laravel Sanctum for API authentication
- Google Books API for book enrichment
- Swagger/OpenAPI for API documentation
- Docker for containerization
- Docker & Docker Compose
- Composer (for local development)
- PHP 8.4+ (for local development)
# Start API service
docker-compose up -d livrolog-api
# Install dependencies
docker exec livrolog-api composer install
# Setup application
docker exec livrolog-api php artisan key:generate
docker exec livrolog-api php artisan migrate
docker exec livrolog-api php artisan db:seedThe API will be available at: http://localhost:8000
cd api/
# Install dependencies
composer install
# Setup environment
cp .env.example .env
php artisan key:generate
# Run migrations
php artisan migrate
php artisan db:seed
# Start development server
php artisan serve# Format code with Laravel Pint
docker exec livrolog-api ./vendor/bin/pint
# Run tests
docker exec livrolog-api php artisan test
# Run specific test
docker exec livrolog-api php artisan test --filter=AuthTest# Run migrations
docker exec livrolog-api php artisan migrate
# Fresh migration with seeding
docker exec livrolog-api php artisan migrate:fresh --seed
# Run seeders only
docker exec livrolog-api php artisan db:seed
# Create migration
docker exec livrolog-api php artisan make:migration create_example_table# Process queued jobs
docker exec livrolog-api php artisan queue:work
# Clear failed jobs
docker exec livrolog-api php artisan queue:flush# Enrich all books with Google Books data
docker exec livrolog-api php artisan books:enrich
# Enrich specific book
docker exec livrolog-api php artisan books:enrich --book-id=B-3D6Y-9IO8
# Preview enrichment (dry run)
docker exec livrolog-api php artisan books:enrich --dry-run
# Force re-enrichment
docker exec livrolog-api php artisan books:enrich --forceapi/
├── app/
│ ├── Console/Commands/ # Artisan commands
│ ├── Http/
│ │ ├── Controllers/Api/ # API controllers
│ │ ├── Middleware/ # HTTP middleware
│ │ └── Requests/ # Form requests
│ ├── Models/ # Eloquent models
│ ├── Services/ # Business logic services
│ └── Jobs/ # Queued jobs
├── database/
│ ├── migrations/ # Database migrations
│ ├── seeders/ # Database seeders
│ └── factories/ # Model factories
├── routes/
│ ├── api.php # API routes
│ └── web.php # Web routes
├── storage/
│ └── logs/ # Application logs
└── tests/
├── Feature/ # Feature tests
└── Unit/ # Unit tests
POST /auth/register- Register new userPOST /auth/login- Login with credentialsPOST /auth/google- Google OAuth sign-inPOST /auth/logout- Logout current userGET /auth/me- Get authenticated user profile
GET /books- List all books with paginationPOST /books- Create new bookGET /books/{id}- Get book detailsPUT /books/{id}- Update book informationDELETE /books/{id}- Delete bookGET /books/search?q={query}- Search Google Books APIPOST /books/create-enriched- Create book with enriched dataPOST /books/{id}/enrich- Enrich existing book dataPOST /books/enrich-batch- Batch enrich multiple books
GET /user/books- Get authenticated user's libraryPOST /user/books- Add book to user's libraryDELETE /user/books/{book_id}- Remove book from libraryPATCH /user/books/{book_id}/read-date- Update reading date
POST /users/{id}/follow- Follow another userDELETE /users/{id}/follow- Unfollow userGET /users/{id}/followers- Get user's followersGET /users/{id}/following- Get users being followed
GET /reviews- List book reviewsPOST /reviews- Create book reviewPUT /reviews/{id}- Update reviewDELETE /reviews/{id}- Delete reviewPOST /reviews/{id}/helpful- Mark review as helpful
GET /showcase- Get featured books showcasePOST /showcase- Add book to showcaseDELETE /showcase/{id}- Remove from showcase
-- Users and Authentication
users (id, name, email, google_id, avatar, created_at, updated_at)
-- Book Catalog
books (id, google_books_id, title, authors, isbn, thumbnail, pages, published_date, description, ...)
authors (id, name, created_at, updated_at)
-- User Library (Many-to-Many)
user_books (user_id, book_id, read_date, created_at, updated_at)
-- Social Features
follows (follower_id, following_id, created_at)
reviews (id, user_id, book_id, rating, review, helpful_count, created_at, updated_at)
-- Content Discovery
showcase (id, book_id, created_at, updated_at)
related_books (id, book_id, related_book_id, relationship_type, created_at, updated_at)- User ↔ Books: Many-to-many through
user_books - User ↔ Reviews: One-to-many
- User ↔ Follows: Many-to-many self-referential
- Books ↔ Authors: Many-to-many
- Books ↔ Reviews: One-to-many
// API authentication with Bearer tokens
'guards' => [
'api' => [
'driver' => 'sanctum',
'provider' => 'users',
],
],# Required environment variables
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_BOOKS_API_KEY=your-google-books-api-key- CORS configured for frontend domain
- Rate limiting on API routes
- Request validation and sanitization
- Protected routes with Sanctum middleware
- SQL injection protection via Eloquent ORM
The system automatically enriches book data using Google Books API:
// Enrich single book
$bookService->enrichBook($book);
// Batch enrichment
$bookService->enrichBooks($books);- Basic Info: Title, authors, ISBN, description
- Publishing: Publisher, publication date, page count
- Physical: Dimensions, format (paperback/hardcover)
- Content: Categories, language, maturity rating
- Media: High-resolution thumbnails and previews
- Respects Google Books API quotas
- Implements exponential backoff for rate limits
- Queued processing for large batch operations
# Run all tests
docker exec livrolog-api php artisan test
# Run specific test suite
docker exec livrolog-api php artisan test tests/Feature/AuthTest.php
# Run with coverage
docker exec livrolog-api php artisan test --coverage- Feature Tests: End-to-end API testing
- Unit Tests: Individual class and method testing
- Database: Uses SQLite in-memory for fast test execution
- Factories: Generate realistic test data
- Seeders: Consistent test database state
# Application
APP_NAME=LivroLog
APP_ENV=local
APP_KEY=base64:generated-key
APP_DEBUG=true
APP_URL=http://localhost:8000
# Database
DB_CONNECTION=mysql
DB_HOST=livrolog-mysql
DB_PORT=3306
DB_DATABASE=livrolog
DB_USERNAME=root
DB_PASSWORD=password
# Redis
REDIS_HOST=livrolog-redis
REDIS_PASSWORD=null
REDIS_PORT=6379
# Google Services
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_BOOKS_API_KEY=your-google-books-api-key
# Queue
QUEUE_CONNECTION=redis
# Mail (optional)
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null- Database Indexing: Optimized queries with proper indexes
- Eager Loading: Prevent N+1 query problems
- Redis Caching: API response and query result caching
- Queue Processing: Async handling of heavy operations
- Response Compression: Gzip compression for API responses
# View application logs
docker exec livrolog-api tail -f storage/logs/laravel.log
# Monitor queue jobs
docker exec livrolog-api php artisan queue:monitor
# Database query debugging
docker exec livrolog-api php artisan telescope:install # Optional- Interactive Docs: http://localhost:8000/documentation
- JSON Spec: http://localhost:8000/docs/api.json
- Auto-generated: From controller docblocks and request validation
API endpoints can be imported into Postman using the OpenAPI specification URL.
# Production optimizations
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan optimize
# Database migration
php artisan migrate --force- Frontend Documentation
- Project Overview
- CLAUDE.md - Development guidelines