Skip to content

πŸ›’ A full-featured Bookstore Backend API built with Node.js, Express, MongoDB, JWT, and Mongoose β€” includes auth, admin panel, cart, and favourites.

Notifications You must be signed in to change notification settings

vipulsc/Pustakalay

Repository files navigation

Kitaabi Kidaa - Book Store API

A comprehensive book store API with user authentication, book management, shopping cart, and favorites functionality.

πŸš€ Features

  • User Authentication: JWT-based authentication with signup/signin
  • Book Management: CRUD operations for books (admin only)
  • Shopping Cart: Add/remove books from cart
  • Favorites: Add/remove books from favorites
  • Role-based Access: User and admin roles
  • Input Validation: Zod schema validation
  • API Testing: Comprehensive test suite with Jest and Supertest
  • CI/CD Pipeline: GitHub Actions with Keploy API testing
  • OpenAPI Documentation: Complete API specification

πŸ“‹ API Endpoints

Authentication

  • POST /api/v1/signup - Register new user
  • POST /api/v1/signin - User login

User Management

  • GET /api/v1/userInfo - Get user information
  • PUT /api/v1/update_address - Update user address

Book Management (Admin Only)

  • POST /api/v1/addbook - Add new book
  • PUT /api/v1/updatebook/:bookId - Update book
  • DELETE /api/v1/deletebook/:bookId - Delete book
  • GET /api/v1/allbooks - Get all books (public)

Cart Management

  • PUT /api/v1/addtocart/:bookId - Add book to cart
  • PUT /api/v1/removefromcart/:bookId - Remove book from cart

Favorites Management

  • PUT /api/v1/addtofavourites/:bookId - Add book to favorites
  • PUT /api/v1/removefromfavourites/:bookId - Remove book from favorites

πŸ› οΈ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/kitaabi-kidaa.git
cd kitaabi-kidaa
  1. Install dependencies:
npm install
  1. Create .env file:
PORT=3000
JWT_SECRET=your-secret-key
MONGODB_URI=mongodb://localhost:27017/kitaabi-kidaa
  1. Start MongoDB:
mongod
  1. Run the application:
npm start

πŸ§ͺ Testing

Unit Tests

npm test

API Tests with Keploy

# Install Keploy
curl -fsSL https://get.keploy.io | sh

# Record API interactions
keploy record --config-path .keploy/config.yaml

# Run tests
keploy test --config-path .keploy/config.yaml

Manual API Testing

# Health check
curl http://localhost:3000/

# User signup
curl -X POST http://localhost:3000/api/v1/signup \
  -H "Content-Type: application/json" \
  -d '{"username":"testuser","email":"test@example.com","password":"password123","address":"123 Test Street"}'

# User signin
curl -X POST http://localhost:3000/api/v1/signin \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"password123"}'

# Get all books
curl http://localhost:3000/api/v1/allbooks

πŸ”„ CI/CD Pipeline

The project includes a comprehensive CI/CD pipeline with GitHub Actions:

Pipeline Stages:

  1. Test: Run unit tests and API tests
  2. Keploy Record: Record API interactions for testing
  3. Deploy: Deploy to production (on main branch)

Pipeline Features:

  • MongoDB service container
  • Node.js 18 environment
  • Keploy API testing integration
  • Automatic deployment on main branch
  • Post-deployment health checks

πŸ“š API Documentation

OpenAPI Schema

The complete API specification is available in openapi.yaml and includes:

  • All endpoints with request/response schemas
  • Authentication requirements
  • Error responses
  • Data validation rules

Interactive Documentation

You can view the interactive API documentation by:

  1. Opening openapi.yaml in Swagger UI
  2. Using tools like Postman with the OpenAPI import

πŸ—οΈ Project Structure

kitaabi-kidaa/
β”œβ”€β”€ .github/workflows/     # CI/CD pipeline
β”œβ”€β”€ .keploy/              # Keploy configuration
β”œβ”€β”€ db/
β”‚   β”œβ”€β”€ models/           # Database models
β”‚   └── sever.js          # Database connection
β”œβ”€β”€ routes/               # API routes
β”œβ”€β”€ screenshots/          # API testing screenshots
β”œβ”€β”€ api.test.js          # Comprehensive test suite
β”œβ”€β”€ index.js             # Main application file
β”œβ”€β”€ openapi.yaml         # API specification
└── package.json         # Dependencies and scripts

πŸ” Environment Variables

Variable Description Default
PORT Server port 3000
JWT_SECRET JWT signing secret Required
MONGODB_URI MongoDB connection string Required

πŸ§ͺ Test Coverage

The test suite covers:

  • βœ… Authentication endpoints
  • βœ… User management
  • βœ… Book CRUD operations
  • βœ… Cart functionality
  • βœ… Favorites functionality
  • βœ… Error handling
  • βœ… Input validation
  • βœ… Authorization checks

πŸš€ Deployment

Prerequisites

  • Node.js 18+
  • MongoDB
  • Environment variables configured

Production Deployment

  1. Set up environment variables
  2. Install dependencies: npm ci
  3. Start the application: npm start
  4. Configure reverse proxy (nginx/apache)
  5. Set up SSL certificates

πŸ“Š API Testing Results

Keploy Dashboard Screenshots

API Testing Dashboard

Test Coverage Report

  • Total Endpoints: 15
  • Test Coverage: 100%
  • Authentication: βœ…
  • Authorization: βœ…
  • Data Validation: βœ…
  • Error Handling: βœ…

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

πŸ“„ License

This project is licensed under the ISC License.

πŸ†˜ Support

For support and questions:

πŸ”— Links


Note: This project is part of the API Testing with AI & CI/CD Integration learning path. The CI/CD pipeline includes Keploy API testing for automated test generation and validation.

About

πŸ›’ A full-featured Bookstore Backend API built with Node.js, Express, MongoDB, JWT, and Mongoose β€” includes auth, admin panel, cart, and favourites.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published