A robust and scalable Laravel-based RESTful API for a modern online bookstore application.
The frontend for this project is available at: BookCafe-Frontend
BookCafe is a comprehensive digital bookstore platform designed to manage books, users, and reading preferences. The backend is built with Laravel 12 and offers a complete RESTful API for book management, user authentication, and personalized library features.
The system supports two user roles:
Data is stored primarily in PostgreSQL with Redis caching for improved performance. The API design follows RESTful conventions with proper authentication and authorization checks throughout.
Clone the repository:
git clone https://github.com/tejaspanchall/BookCafe-Backend.git
cd BookCafe-Backend
Install dependencies:
composer install
Set up environment variables:
cp .env.example .env
php artisan key:generate
Update the .env
file with your database credentials:
```env
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=bookstore
DB_USERNAME=postgres
DB_PASSWORD=your_password
REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 REDIS_DB=0 REDIS_CACHE_DB=1
5. Run database migrations and seeders:
```bash
php artisan migrate
php artisan db:seed
Create a symbolic link for storage:
php artisan storage:link
Update search vectors for full-text search:
php artisan search:update-vectors
Generate Excel template for book imports:
php artisan books:create-import-template
Start the development server:
php artisan serve
The API will be available at http://localhost:8000/api
POST /api/auth/register
- Register a new userPOST /api/auth/login
- User loginPOST /api/auth/logout
- User logout (requires authentication)POST /api/auth/forgot-password
- Request password resetPOST /api/auth/reset-password
- Reset password with tokenGET /api/books/search
- Search for booksGET /api/books/get-books
- Get all booksGET /api/books/book/{id}
- Get book detailsGET /api/books/popular
- Get popular booksGET /api/books/my-library
- Get user's book library (requires authentication)POST /api/books/{book}/add-to-library
- Add book to user's library (requires authentication)DELETE /api/books/{book}/remove-from-library
- Remove book from user's library (requires authentication)POST /api/books/add
- Add a new book (requires teacher role)PUT /api/books/{book}
- Update a book (requires teacher role)DELETE /api/books/{book}
- Delete a book (requires teacher role)POST /api/excel-imports/upload
- Upload Excel file (requires teacher role)GET /api/excel-imports/files
- Get uploaded Excel files (requires teacher role)DELETE /api/excel-imports/file/{fileId}
- Delete Excel file (requires teacher role)POST /api/excel-imports/import/{fileId}
- Import books from Excel file (requires teacher role)GET /api/excel-imports/template
- Download Excel template (requires teacher role)GET /api/categories
- Get all categoriesGET /api/categories/{id}/books
- Get books by categoryPOST /api/categories
- Create a new category (requires authentication)GET /api/authors
- Get all authorsGET /api/authors/{id}/books
- Get books by authorPOST /api/authors
- Create a new author (requires authentication)The application uses Redis for caching to improve performance. Cache data is stored in database 1.
books:all
- All booksbooks:popular
- Popular booksbooks:search:*
- Search resultsbook:*
- Individual book cachecategories:all
- All categoriescategory:*:books
- Books by categoryauthors:all
- All authorsauthor:*:books
- Books by authorbooks:user:{id}:library
- User's book libraryTo view all cache keys in Redis database 1:
redis-cli
> SELECT 1
> KEYS *
The application uses PostgreSQL's powerful full-text search capabilities for efficient and accurate book searching. It implements:
After adding new books or updating existing ones, run the following command to update the search vectors:
php artisan search:update-vectors
This command:
search_vector
column for all books with data from their title and ISBN fieldsphp artisan db:seed --class=BookSeeder
This project is licensed under the MIT License - see the LICENSE file for details.