Skip to content

destinykrishna/BookStore

Repository files navigation

Bookstore Backend

This is the backend for a MERN stack Bookstore application. It provides RESTful APIs for user authentication, book management, and integrates with Google OAuth, Redis caching, ImageKit for image storage, and Google Gemini AI for book tagging.

Features

  • User registration, login (email/password & Google OAuth)
  • JWT-based authentication and role-based authorization (user/admin)
  • Book CRUD (Create, Read, Update, Delete) with image upload and AI-generated tags
  • Rate limiting for login and general requests
  • Input validation using Joi
  • Redis caching for book data
  • ImageKit integration for image storage
  • Google Gemini AI integration for book tagging

API Endpoints

User APIs

  • POST /user/register — Register a new user
  • POST /user/login — Login with email/password
  • GET /user/auth/google — Google OAuth login
  • GET /user/auth/google/callback — Google OAuth callback
  • GET /user/logout — Logout
  • GET /user/profile — Get user profile (auth required)
  • PATCH /user/profile — Update user profile (auth required)
  • PATCH /user/promote — Promote user to admin (admin only)

Book APIs

  • GET /book/ — List all books (with Redis caching)
  • POST /book/create — Create a new book (admin only, image upload, AI tags)
  • GET /book/:id — Get single book (auth required)
  • PATCH /book/update/:id — Update book (admin only)
  • DELETE /book/delete/:id — Delete book (admin only)
  • PATCH /book/image/delete/:bookId/:fileId — Delete book image (admin only)

Integrations

  • Google OAuth: Social login for users
  • Redis: Caching for book data
  • ImageKit: Image storage and management
  • Google Gemini AI: Automatic tagging of books

Middleware

  • Authentication: JWT token verification
  • Authorization: Role-based access control
  • Validation: Joi schemas for request validation
  • Rate Limiting: Prevent brute-force and abuse
  • Multer: File upload handling

Models

  • User: fullName, email, password (hashed), role (user/admin)
  • Book: name, price, category, images (ImageKit), title, ai_tags

Setup

  1. Install dependencies:
    npm install
  2. Set up environment variables in a .env file:
    • MONGODB_URI
    • JWT_SECRET
    • IMAGEKIT_PUBLIC_KEY, IMAGEKIT_PRIVATE_KEY, IMAGEKIT_URL_ENDPOINT
    • REDIS_URL
    • Google OAuth credentials
  3. Start the server:
    npm start

Testing

  • Run tests:
    npm test

Folder Structure

  • controller/ — Route handlers for books and users

  • models/ — Mongoose models

  • route/ — Express route definitions

  • middleware/ — Auth, validation, rate limiting, file upload

  • config/ — Third-party integrations (ImageKit, Redis, Google Gemini, Passport)


bookstore.mp4

For more details, see the source code in each folder.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published