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.
- 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
POST /user/register— Register a new userPOST /user/login— Login with email/passwordGET /user/auth/google— Google OAuth loginGET /user/auth/google/callback— Google OAuth callbackGET /user/logout— LogoutGET /user/profile— Get user profile (auth required)PATCH /user/profile— Update user profile (auth required)PATCH /user/promote— Promote user to admin (admin only)
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)
- Google OAuth: Social login for users
- Redis: Caching for book data
- ImageKit: Image storage and management
- Google Gemini AI: Automatic tagging of books
- 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
- User: fullName, email, password (hashed), role (user/admin)
- Book: name, price, category, images (ImageKit), title, ai_tags
- Install dependencies:
npm install
- Set up environment variables in a
.envfile:MONGODB_URIJWT_SECRETIMAGEKIT_PUBLIC_KEY,IMAGEKIT_PRIVATE_KEY,IMAGEKIT_URL_ENDPOINTREDIS_URL- Google OAuth credentials
- Start the server:
npm start
- Run tests:
npm test
-
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.