A comprehensive full-stack digital library management system built with Node.js, featuring user authentication, book management, reviews, favorites, and email notifications.
- User Management: Complete user registration, authentication, email verification, and password reset functionality
- Book Management: Full CRUD operations for books with cover image uploads
- Review System: User reviews and ratings for books with aggregated statistics
- Favorites: Personal bookmark system for users to save their favorite books
- Search & Filter: Advanced book search with filtering, sorting, and pagination
- Profile Management: User profile viewing and management
- CI/CD Pipeline: Automated code quality checks via GitHub Actions
- JWT Authentication: Secure token-based authentication with access tokens
- OAuth Integration: Google and GitHub OAuth2 support for social login
- Email Verification: Email-based account verification system
- Password Security: bcrypt hashing with secure password reset flow
- Rate Limiting: Protection against abuse and DDoS attacks (5000 requests per 15 minutes)
- Session Management: Secure session handling with Passport.js
- CORS Protection: Configurable cross-origin resource sharing
- Direct Email Delivery: Reliable email delivery using Nodemailer
- Multiple Templates: Welcome emails, verification, password reset, and security alerts
- Development Support: MailHog integration for local email testing
- Production Ready: Gmail SMTP support for production environments
- RESTful API: Well-structured REST endpoints following best practices
- Swagger Documentation: Interactive API documentation at
/docs - Input Validation: Zod schema validation for all inputs
- Error Handling: Comprehensive error management with custom error classes
- Logging: Detailed application and HTTP logging using Winston and Morgan
- Server-Side Rendering: EJS templates for dynamic content
- Dark & Light Themes: Instant theme switching with persistent preferences and zero flicker
- Responsive Design: Mobile-friendly interface
- Book Catalog: Browse and search books with uniform card sizing, clean ellipsis truncation, and pagination
- Book Details: Detailed book information with reviews
- User Profile: View and manage user profile
- Favorites Page: Manage favorite books
| Dark Mode | Light Mode |
|---|---|
![]() |
![]() |
This project follows a monolithic architecture with modular design:
βββββββββββββββββββ
β Client/Views β
β (EJS Pages) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Express API βββββΊβ Email Service β
β (Backend) β β (Nodemailer) β
ββββββββββ¬βββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β MongoDB β
β (Database) β
βββββββββββββββββββ
graph TD
Client[Client/Views - EJS Pages]
API[Express API - Backend]
Email[Email Service - Nodemailer]
DB[(MongoDB - Database)]
Client --> API
API --> Email
API --> DB
book-library-management-api/
βββ .github/ # GitHub configuration
β βββ workflows/ # CI/CD pipelines (GitHub Actions)
β βββ ISSUE_TEMPLATE/ # Standardized issue templates
β βββ pull_request_template.md
βββ src/
β βββ controllers/ # Route handlers and business logic
β βββ models/ # Mongoose database models
β β βββ auth/ # User and token models
β βββ routes/ # API route definitions
β βββ middlewares/ # Custom middleware
β βββ utils/ # Utility functions & email templates
β βββ schema/ # Zod validation schemas
β βββ logger/ # Logging configuration (Winston + Morgan)
β βββ services/ # Business services (email, MongoDB, passport)
β βββ views/ # EJS templates
β βββ seeds/ # Database seeders
β βββ data/ # Static data (books.json)
β βββ scripts/ # Utility scripts (DB teardown)
β βββ swagger.yaml # API documentation
β βββ app.js # Express app configuration
β βββ index.js # Application entry point
β βββ envs.js # Environment variable exports
β βββ constants.js # Application constants
βββ public/ # Static assets (css, images)
βββ logs/ # Application logs
βββ docker-compose.yml # Development services & Full App orchestration
βββ Dockerfile # Application containerization
βββ package.json
βββ pnpm-lock.yaml
βββ .env.example
βββ .prettierc.yaml # Code formatting configuration
βββ .prettierignore
βββ nodemon.json
βββ README.md
βββ CONTRIBUTING.md
βββ CODE_OF_CONDUCT.md
βββ LICENSE
- Runtime: Node.js (v14+) with ES6 modules
- Framework: Express.js v5
- Database: MongoDB with Mongoose ODM
- Authentication: JWT, Passport.js (Google, GitHub OAuth)
- Validation: Zod schema validation
- Documentation: Swagger/OpenAPI
- Logging: Winston + Morgan
- Security: bcryptjs, express-rate-limit, CORS
- File Upload: Multer
- Email: Nodemailer
- Template Engine: EJS
- Formatting: Prettier
- CI/CD: GitHub Actions
- Database: MongoDB
- Email Testing: MailHog
- Containerization: Docker & Docker Compose
- Package Manager: pnpm
- Development: Nodemon for hot reloading
- Node.js (v14 or higher)
- pnpm (v8 or higher)
- Docker and Docker Compose
- Git
-
Clone the repository
git clone https://github.com/ichshakib/book-library-management-api.git cd book-library-management-api -
Start development services
# Start MongoDB and MailHog docker-compose up -d -
Install dependencies
pnpm install
-
Set up environment variables
Copy
.env.exampleto.envand update the values:cp .env.example .env
Required environment variables:
# Server Configuration PORT=7000 BACKEND_URL=http://localhost:7000 CLIENT_SSO_REDIRECT_URL=http://localhost:7000 NODE_ENV=development # Database MONGODB_URI=mongodb://localhost:27017 DB_NAME=book-library # JWT Secrets (change these!) ACCESS_TOKEN_SECRET=your_secure_access_token_secret EXPRESS_SESSION_SECRET=your_secure_session_secret # OAuth (optional for development) GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret GOOGLE_CALLBACK_URL=http://localhost:7000/auth/google/callback GITHUB_CLIENT_ID=your_github_client_id GITHUB_CLIENT_SECRET=your_github_client_secret GITHUB_CALLBACK_URL=http://localhost:7000/auth/github/callback # Email Configuration # For development (MailHog) MAILHOG_SMTP_HOST=localhost MAILHOG_SMTP_PORT=1025 # For production (Gmail) GMAIL_USER=your-email@gmail.com GMAIL_PASS=your-app-password
-
Start the application
# Development mode with hot reload pnpm dev # Production mode pnpm start
-
Access the application
- Application: http://localhost:7000
- API Documentation: http://localhost:7000/docs
- Health Check: http://localhost:7000/health
- MailHog UI: http://localhost:8025 (for email testing)
graph LR
SignUp[Sign Up] --> Verify[Verify Email]
Verify --> SignIn[Sign In]
SignIn --> Session[Session/JWT]
OAuth[Google/GitHub Login] --> Session
POST /auth/sign-up- User registrationPOST /auth/sign-in- User loginPOST /auth/sign-out- User logoutPOST /auth/forget-password- Request password resetPOST /auth/reset-password- Reset password with tokenPOST /auth/verify-email- Verify email addressGET /auth/google- Google OAuth loginGET /auth/github- GitHub OAuth login
GET /books- Get all books (with pagination, filtering, sorting)GET /books/:id- Get book by IDPOST /books- Create new book (Admin only)PUT /books/:id- Update book (Admin only)DELETE /books/:id- Delete book (Admin only)POST /books/:id/upload-image- Upload book cover image
GET /reviews- Get all reviewsGET /reviews/book/:bookId- Get reviews for a specific bookPOST /reviews- Create new review (Authenticated users)PUT /reviews/:id- Update review (Review owner only)DELETE /reviews/:id- Delete review (Review owner only)
GET /favorites- Get user's favorite booksPOST /favorites- Add book to favoritesDELETE /favorites/:bookId- Remove book from favorites
GET /- Home page with book catalogGET /book/:id- Book details pageGET /profile- User profile pageGET /favorites- User favorites page
For complete API documentation with request/response examples, visit: http://localhost:7000/docs
pnpm start # Start production server
pnpm dev # Start development server with hot reload
pnpm build # Run build validation
pnpm format # Format code with Prettier
pnpm format:check # Check code formatting
pnpm seed # Seed admin user and books into the database
pnpm mongodb:teardown # Drop the database (use with caution)To populate the database with sample books:
# The seed endpoint is available at /seeds/add-books
# Access it through the browser or make a POST request
curl -X POST http://localhost:7000/seeds/add-booksThe project uses Prettier for code formatting:
- Configuration:
.prettierc.yaml - Ignore file:
.prettierignore
- Winston: Application-level logging (info, error, debug)
- Morgan: HTTP request logging
- Log files are stored in the
logs/directory
The project includes Docker Compose for easy development setup:
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Rebuild services
docker-compose up -d --buildServices included:
- MongoDB: Database server (port 27017)
- MailHog: Email testing server (ports 1025, 8025)
- Rate Limiting: 5000 requests per 15 minutes per IP
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcryptjs for password security
- CORS Protection: Configurable cross-origin resource sharing
- Input Validation: Zod schema validation for all inputs
- Session Management: Secure session handling with Passport.js
- Email Verification: Email-based account verification
- OAuth Integration: Secure third-party authentication
- File Upload Security: Multer with file type and size restrictions
The email service provides:
- Direct Delivery: Synchronous email delivery using Nodemailer
- Multiple Templates: Welcome, verification, password reset, security alerts
- Development Support: MailHog integration for testing
- Production Ready: Gmail SMTP support for production
- HTML Templates: Professional email templates with inline CSS
- Start MailHog:
docker-compose up -d mailhog - Access MailHog UI: http://localhost:8025
- Trigger email actions in the application
- View sent emails in MailHog interface
Every push and pull request to the main branch triggers a GitHub Actions workflow that:
- Installs dependencies via pnpm
- Checks code formatting (
pnpm format:check) - Runs the build step (
pnpm build)
Access MailHog at http://localhost:8025 to view all emails sent during development.
NODE_ENV=production
PORT=7000
BACKEND_URL=https://your-domain.com
MONGODB_URI=mongodb://your-mongodb-uri
DB_NAME=book-library
ACCESS_TOKEN_SECRET=your-secure-secret
EXPRESS_SESSION_SECRET=your-secure-secret
GMAIL_USER=your-gmail-username
GMAIL_PASS=your-gmail-app-password- Use a production MongoDB instance (MongoDB Atlas recommended)
- Configure Gmail SMTP or other email service for email delivery
- Set up proper logging and monitoring
- Use environment-specific secrets (strong, random values)
- Configure proper CORS origins
- Set up SSL/TLS certificates
- Use a process manager (PM2 recommended)
- Set up reverse proxy (Nginx recommended)
We welcome contributions! Please see our CONTRIBUTING.md file for detailed guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
- ichshakib - GitHub Profile
- Maintainer: ichshakib
- Email: ichshakib@gmail.com
- GitHub: @ichshakib
If you encounter any issues or have questions:
- Check the API Documentation
- Review the logs in
logs/directory - Check the MailHog interface for email issues
- Open an issue on GitHub Issues
- Reach out via email at ichshakib@gmail.com
- Express.js team for the excellent web framework
- MongoDB team for the powerful database
- Nodemailer team for the reliable email solution
- All contributors who help improve this project
- Initial release with core functionality
- User authentication and management
- Book CRUD operations
- Review and favorites system
- Email notification service
- OAuth integration (Google, GitHub)
- API documentation with Swagger
- Server-side rendering with EJS
Built with β€οΈ using Node.js, Express, and MongoDB
