Bookify is a comprehensive online book marketplace platform that connects buyers and sellers. This repository contains the server-side implementation built with Node.js, Express, and MongoDB, with integrated messaging via Kafka/Redpanda for event streaming.
- Features
- Architecture
- Tech Stack
- Getting Started
- Docker Setup
- Kubernetes Deployment
- Redpanda Kafka Integration
- API Endpoints
- Environment Variables
- Project Structure
- Development
- User Management: Registration, authentication, and role-based access (Buyers/Sellers/Admins)
- Book Management: Add, edit, delete, and browse books with categorization
- Booking System: Secure booking and reservation functionality
- Wishlist: Save favorite books for future reference
- Inventory Management: Seller-specific product management
- Advertising: Promote books with featured listings
- Payment Integration: Secure payment processing
- Event Streaming: Real-time event handling with Kafka/Redpanda
- Caching: Redis integration for performance optimization
- Database: MongoDB with connection pooling and optimization
The Bookify server follows a microservice-inspired architecture with:
Client Applications (Web/Mobile)
β HTTP/REST API
Bookify Server (Node.js/Express)
β Internal Services
βββ Database Layer (MongoDB)
βββ Cache Layer (Redis)
βββ Message Broker (Redpanda/Kafka)
β Event Processing
βββ GraphQL Service (Consumer)
- Runtime: Node.js v24.x
- Framework: Express.js
- Database: MongoDB (with Mongoose ODM)
- Cache: Redis
- Message Broker: Redpanda (Kafka-compatible)
- Containerization: Docker & Docker Compose
- Orchestration: Kubernetes
- Language: JavaScript/TypeScript
- Package Manager: Yarn
- Node.js v24.x or higher
- Yarn package manager
- MongoDB Atlas account or local MongoDB instance
- Docker & Docker Compose (for containerized setup)
- Kubernetes cluster (for production deployment)
- Clone the repository:
git clone <repository-url>
cd Bookify/server- Install dependencies:
yarn install- Create environment file:
cp .env.example .env-
Configure environment variables (see Environment Variables section)
-
Start the development server:
yarn devThe application is configured with a multi-stage Docker build process for optimized production deployment.
# Build the production image
docker build -t bookify-server .
# Build specific stage (e.g., dev environment)
docker build --target dev -t bookify-server:dev .The server includes a Kafka/Redpanda setup in a separate Docker Compose file:
# Start Kafka/Redpanda services
docker-compose -f docker-compose.kafka.yml up -d
# Stop Kafka/Redpanda services
docker-compose -f docker-compose.kafka.yml downThe Docker image includes:
- Multi-stage build (builder, pruner, runner)
- Production-optimized dependency installation
- Health checks
- Security best practices (non-root user)
The project includes Kubernetes configuration files in the k8s/ directory for production deployment.
- Ensure you have
kubectlconfigured to your cluster - Apply the Kubernetes manifests:
kubectl apply -f k8s/- Deployments for the main server
- Services for internal and external communication
- ConfigMaps for environment configuration
- Secrets for sensitive data
- Persistent Volumes for data storage
- Network Policies for security
- Health checks and resource limits
The Bookify server uses Redpanda (a Kafka-compatible message broker) for event streaming and real-time communication between services.
services.created.v1- Events for new services/book listings- Additional topics are configured in the application
# Start Redpanda with Docker Compose
cd server
docker-compose -f docker-compose.kafka.yml up -d
# Check Redpanda status
docker exec -it redpanda-bookify rpk cluster infoThe application automatically connects to Kafka on startup and handles event publishing and consumption.
POST /api/users/register- Register new userPOST /api/users/login- User loginGET /api/users- Get all usersGET /api/users/:id- Get specific userDELETE /api/users/:id- Delete userGET /api/users/admin/:email- Check if user is adminGET /api/users/sellers- Get all sellersGET /api/users/buyers- Get all buyers
GET /api/books- Get all booksGET /api/books/:id- Get specific bookPOST /api/books- Add new bookPUT /api/books/:id- Update bookDELETE /api/books/:id- Delete bookGET /api/books/category/:category- Get books by category
GET /api/categories- Get all categoriesGET /api/categories/:category- Get books in specific category
POST /api/bookings- Create new bookingGET /api/bookings- Get all bookingsGET /api/bookings/:id- Get specific bookingDELETE /api/bookings/:id- Cancel booking
POST /api/wishlist- Add to wishlistGET /api/wishlist- Get wishlist itemsDELETE /api/wishlist/:id- Remove from wishlist
POST /api/payments- Process paymentGET /api/payments/:id- Get payment status
Create a .env file in the root directory with the following variables:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database Configuration
DB_USER=your_mongodb_username
DB_PASSWORD=your_mongodb_password
DB_NAME=Bookify
MONGODB_URI=mongodb+srv://<user>:<password>@cluster0.dafmrk2.mongodb.net/Bookify
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# Kafka Configuration
KAFKA_CLIENT_ID=bookify-server
KAFKA_BROKERS=localhost:29092
KAFKA_SERVICES_CREATED_TOPIC=services.created.v1
# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=24h
# Payment Gateway (if implemented)
PAYMENT_GATEWAY_API_KEY=your_payment_gateway_key
# CORS Configuration
ALLOWED_ORIGINS=http://localhost:3000,https://your-frontend-domain.comserver/
βββ index.js # Legacy server entry point
βββ src/ # Source code directory
β βββ server.js # Main server entry point
β βββ config/ # Configuration files
β β βββ db.js # Database connection
β βββ controllers/ # Business logic controllers
β βββ messaging/ # Kafka/Redpanda integration
β β βββ kafka.js # Kafka initialization
β βββ middleware/ # Express middleware
β βββ models/ # Database models
β βββ routes/ # API route definitions
β βββ services/ # Business logic services
β βββ utils/ # Utility functions
β β βββ redis.js # Redis connection
β βββ validations/ # Input validation schemas
βββ Dockerfile # Multi-stage Docker build
βββ docker-compose.kafka.yml # Kafka/Redpanda setup
βββ k8s/ # Kubernetes manifests
βββ KAFKA_SETUP.md # Kafka setup documentation
βββ redpanda-console-config.yml # Redpanda console configuration
βββ README.md # This file
# Install dependencies
yarn install
# Start in development mode with auto-reload
yarn dev
# Build for production
yarn build
# Run production build
yarn startThe project uses Yarn for dependency management and task execution. Common scripts include:
yarn dev- Start development server with nodemonyarn build- Build production-ready codeyarn start- Start production serveryarn lint- Lint the codebaseyarn test- Run testsyarn clean- Clean build artifacts
- ESLint for code linting
- Prettier for code formatting
- JSDoc for documentation
The project includes comprehensive testing setup:
# Run all tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test:coverageKafka Connection Issues:
- Ensure Redpanda is running:
docker ps | grep redpanda - Check broker connectivity:
telnet localhost 29092 - Verify environment variables are set correctly
Database Connection Issues:
- Verify MongoDB connection string is correct
- Check network connectivity to MongoDB Atlas
- Ensure credentials have proper permissions
Redis Connection Issues:
- Ensure Redis server is running
- Check Redis host and port configuration
- Verify Redis password if authentication is enabled
Docker Build Issues:
- Ensure Docker is running and properly configured
- Check Dockerfile syntax
- Verify multi-stage build dependencies
- Environment Setup: Always use a
.envfile for configuration - Database Migrations: Use proper migration scripts for schema changes
- API Documentation: Update API documentation when adding new endpoints
- Error Handling: Implement comprehensive error handling and logging
- Security: Sanitize all user inputs and validate API requests
The application includes comprehensive logging:
- Console logs for development
- Structured logs for production
- Error tracking and reporting
- Performance monitoring hooks
The application is designed for horizontal scaling:
- Stateless design allows multiple instances
- Database connection pooling
- Redis for session storage and caching
- Load balancing via Kubernetes services
- Redis caching for frequently accessed data
- Connection pooling for database operations
- Event-driven architecture for non-blocking operations
- Proper indexing in MongoDB
- Efficient API endpoint design
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the existing issues
- Create a new issue with detailed information
- Consult the documentation in the
docs/directory - Contact the maintainers directly