Skip to content

Aditya-Bhadauria/Backend-BookStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book Store Application

Overview

The Book Store Application is a web-based API that allows authenticated users to manage books, including creating, updating, searching, deleting book entries, viewing personal profiles, maintaining a personal wishlist, and generating AI-based book reviews. The system implements JWT-based authentication with role-based authorization and integrates Gemini AI API for generating spoiler-free book reviews.

Live Frontend Deployment:
🌐 Visit Frontend

Screenshot from 2025-06-17 22-56-57

Screenshot from 2025-06-17 22-57-32

Screenshot from 2025-06-17 22-59-50

Screenshot from 2025-06-17 23-01-04

Features

  • User Authentication: Register and login with secure password hashing.
  • JWT-based Authorization: Access control using JSON Web Tokens.
  • Role-Based Access Control:
    • User Role: Can view books, manage their own profile, and maintain a personal wishlist.
    • Admin Role: Can add, update, and delete books from the global book library.
  • Book Management: CRUD operations for books (restricted based on roles).
  • Filtering & Search:
    • Filter books by author, category, and rating.
    • Search books by title with partial matching.
  • User Profile Management: Authenticated users can view their personal details.
  • Wishlist Management: Users can add and manage their favorite books in a personal wishlist.
  • AI-Powered Book Review:
    Generate spoiler-free, AI-generated book reviews using Gemini API for any book.
  • Cloudinary Image Hosting: Serve book cover images via Cloudinary URLs.

Tech Stack

  • Backend: Spring Boot, Spring Security, JWT
  • Database: MongoDB (NoSQL Database)
  • Authentication: JSON Web Token (JWT)
  • Image Storage: Cloudinary API
  • AI Integration: Gemini API for book reviews
  • Tools: Postman (for API testing), Maven (for dependency management)

System Architecture

  1. User registers/login ➝ Gets JWT token.
  2. JWT Authentication Filter verifies the token before processing requests.
  3. Role-Based Authorization decides what each user type can access:
    • Users can view and search books, manage their profile and wishlist.
    • Admins can manage (add/update/delete) books globally.
  4. Profile Controller manages user profile operations.
  5. Wishlist Controller handles adding/removing books from the wishlist.
  6. Book Controller handles book-related operations with role checks.
  7. MongoDB Database securely stores user and book data.
  8. AI Controller communicates with Gemini API to generate reviews.
  9. Cloudinary serves book cover images.

📂 Project Structure

📦 BookStoreApp
├── 📁 src/main/java/com/example/bookstore
│   ├── 📂 config      # Security Configuration
│   ├── 📂 controller  # API Controllers
│   ├── 📂 model       # Book & User Models
│   ├── 📂 repository  # MongoDB Repositories
│   ├── 📂 service     # Business Logic Services
│   ├── 📂 security    # JWT Utility & Filters
│   └── Application.java # Main entry point
├── 📄 pom.xml         # Maven Dependencies
└── 📄 README.md       # Documentation

Authentication & Security

  • Uses JWT tokens for authentication.
  • Spring Security for securing API endpoints.
  • Role-Based Access Control:
    • Users are assigned either User or Admin roles.
    • Only Admin users can add, update, or delete books from the global collection.
    • Normal Users can view books and manage their own wishlist and profile.

API Endpoints

Auth Endpoints

Method Endpoint Description
POST /api/auth/register Register a new user
POST /api/auth/login Authenticate and get JWT token

Book Endpoints (Requires JWT Authentication)

Method Endpoint Description
POST /api/books Create a new book
GET /api/books Get all books
GET /api/books/{id} Get a book by ID
PUT /api/books/{id} Update a book by ID
DELETE /api/books/{id} Delete a book by ID

Filtering & Search

Query Description
/api/books?author=xyz Filter books by author
/api/books?category=xyz Filter books by category
/api/books?rating=4.5 Filter books by rating
/api/books?search=title Search books by title

Profile Endpoints (Requires JWT Authentication)

Method Endpoint Description
GET /api/profile Get authenticated user's profile details

Wishlist Endpoints (Requires JWT Authentication)

Method Endpoint Description
POST /api/wishlist/{bookId} Add a book to wishlist
GET /api/wishlist View wishlist
DELETE /api/wishlist/{bookId} Remove a book from wishlist

🔧 Setup & Installation

Prerequisites

  • Java 17+
  • Maven
  • MongoDB

Steps to Run

  1. Clone the repository:
    git clone https://github.com/your-repo/bookstore.git
    cd bookstore
  2. Install dependencies:
    mvn clean install
  3. Run the application:
    mvn spring-boot:run
  4. Test API using Postman or any API client.
  5. Make sure to include your mongodbUri in application.properties for testing.

Notes

  • Cloudinary API is integrated to serve book cover images. Admins provide Cloudinary image URLs while adding books.

  • Admin credentials (username and password) are required to access admin controls like adding, updating, or deleting books.

  • Non-admin users can only view books, manage their profile, and maintain their personal wishlist.

  • AI Reviews are powered by Gemini API,providing spoiler-free, intelligent summaries and reviews for each book on demand.