Skip to content

Latest commit

Β 

History

History
364 lines (289 loc) Β· 10.1 KB

File metadata and controls

364 lines (289 loc) Β· 10.1 KB

Library Management System

A comprehensive library management system built with Node.js, Express.js, MongoDB, and React.js. This system supports individual and group borrowing, fine calculation, feedback management, and admin dashboard.

πŸ—οΈ Project Structure

libraryManagementSystem/
β”œβ”€β”€ server/                 # Backend API (Node.js + Express + MongoDB)
β”‚   β”œβ”€β”€ models/            # MongoDB models
β”‚   β”œβ”€β”€ routes/            # API routes
β”‚   β”œβ”€β”€ middleware/        # Authentication middleware
β”‚   β”œβ”€β”€ utils/             # Utility functions
β”‚   β”œβ”€β”€ server.js          # Main server file
β”‚   β”œβ”€β”€ package.json       # Server dependencies
β”‚   └── env.example        # Server environment variables
β”œβ”€β”€ client/                # Frontend (React + Create React App)
β”‚   β”œβ”€β”€ public/            # Static files
β”‚   β”œβ”€β”€ src/               # React source code
β”‚   β”‚   β”œβ”€β”€ components/    # Reusable components
β”‚   β”‚   β”œβ”€β”€ pages/         # Page components
β”‚   β”‚   β”œβ”€β”€ services/      # API services
β”‚   β”‚   β”œβ”€β”€ contexts/      # React contexts
β”‚   β”‚   └── hooks/         # Custom hooks
β”‚   β”œβ”€β”€ package.json       # Client dependencies
β”‚   └── env.example        # Client environment variables
└── README.md              # This file

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (local or cloud instance)
  • npm or yarn

1. Install Dependencies

Server Dependencies

cd server
npm install

Client Dependencies

cd client
npm install

2. Environment Setup

Server Environment

# Copy server environment file
cp server/env.example server/.env

# Edit server/.env with your configuration
NODE_ENV=development
PORT=5000

# MongoDB Configuration
# For local MongoDB:
# MONGODB_URI=mongodb://localhost:27017/library_management

# For MongoDB Atlas (recommended):
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/library_management?retryWrites=true&w=majority

JWT_SECRET=your_jwt_secret_key_here
JWT_EXPIRE=7d

# Email configuration for notifications
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password

# Admin credentials
ADMIN_EMAIL=admin@library.com
ADMIN_PASSWORD=admin123

πŸ“š Need help setting up MongoDB Atlas? Check out our detailed MongoDB Atlas Setup Guide

Client Environment

# Copy client environment file
cp client/env.example client/.env

# Edit client/.env with your configuration
REACT_APP_API_URL=http://localhost:5000/api

3. Start the Application

Start Server (Terminal 1)

cd server
npm run dev

Start Client (Terminal 2)

cd client
npm start

4. Access the Application

πŸ“‹ Available Scripts

Server Scripts (from server/ directory)

  • npm start - Start the server in production mode
  • npm run dev - Start the server in development mode with nodemon

Client Scripts (from client/ directory)

  • npm start - Start the client development server
  • npm run build - Build the client for production
  • npm test - Run client tests
  • npm run eject - Eject from Create React App (not recommended)

🎯 Features

βœ… Core Features

  • User Authentication (JWT-based)
  • Book Management (CRUD operations)
  • Individual Book Borrowing
  • Group Book Borrowing (3-6 members)
  • Fine Calculation System
  • Feedback System
  • Admin Dashboard
  • Email Notifications

βœ… Book Management

  • Each book has 3 copies available
  • Real-time availability tracking
  • Book search and filtering
  • Genre-based categorization
  • ISBN validation

βœ… Borrowing System

  • 1-month borrowing duration
  • Individual and group borrowing support
  • Automatic due date calculation
  • Overdue book tracking
  • Return condition tracking

βœ… Fine System

  • β‚Ή50 fine for overdue books
  • 200% of book cost + β‚Ή50 for lost books after 1 month
  • 200% of book cost for lost books within 1 month
  • 10% fine for minor damage
  • 50% fine for major damage
  • Group fines distributed equally among members

βœ… Group Management

  • Groups can have 3-6 members
  • Group leader management
  • Leadership transfer
  • Group disbanding with proper checks

βœ… Admin Features

  • User management
  • Book management
  • Borrow record tracking
  • Fine management
  • Feedback moderation
  • Dashboard analytics

βœ… Automated Features

  • Daily overdue book checks (cron jobs)
  • Email notifications for fines and overdue books
  • Automatic fine calculation
  • Book availability updates

πŸ—„οΈ Database Schema

Collections

  • users: User information and authentication
  • books: Book catalog and availability
  • borrowRecords: Borrowing history and fine tracking
  • groups: Group information and member management
  • feedback: User feedback and ratings

πŸ”§ API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - User login
  • GET /api/auth/me - Get current user
  • PUT /api/auth/profile - Update user profile

Books

  • GET /api/books - Get all books (with search and filters)
  • GET /api/books/:id - Get single book
  • POST /api/books - Create book (Admin only)
  • PUT /api/books/:id - Update book (Admin only)
  • DELETE /api/books/:id - Delete book (Admin only)

Borrowing

  • POST /api/borrow/individual - Borrow book individually
  • POST /api/borrow/group - Borrow book for group
  • PUT /api/borrow/return/:id - Return book
  • GET /api/borrow/history - Get borrow history
  • GET /api/borrow/current - Get current borrowings

Groups

  • POST /api/groups - Create group
  • GET /api/groups/my-group - Get user's group
  • PUT /api/groups/:id/add-member - Add member to group
  • PUT /api/groups/:id/remove-member - Remove member from group

Feedback

  • POST /api/feedback - Submit feedback
  • GET /api/feedback - Get all public feedback
  • GET /api/feedback/my-feedback - Get user's feedback

Admin

  • GET /api/admin/dashboard - Get dashboard statistics
  • GET /api/admin/users - Get all users
  • GET /api/admin/borrow-records - Get all borrow records
  • PUT /api/admin/feedback/:id/status - Update feedback status

🎨 Frontend Features

βœ… User Interface

  • Responsive design with CSS
  • Modern React components
  • Form validation with Formik + Yup
  • Toast notifications
  • Loading states and error handling

βœ… Pages Implemented

  • Login/Register pages
  • Dashboard with statistics
  • Book catalog with search
  • Book detail page
  • My Books (borrowing history)
  • Groups management
  • Feedback system
  • User profile
  • Admin dashboard
  • Admin book management
  • Admin user management
  • Admin borrow records
  • Admin feedback management

πŸ” Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • Role-based access control
  • Input validation and sanitization
  • CORS configuration
  • Environment variable protection

πŸ“§ Email Notifications

  • Welcome emails for new users
  • Overdue book notifications
  • Fine notifications with detailed breakdown
  • Admin notifications for system events

πŸš€ Deployment

Backend Deployment

  1. Set up MongoDB database (local or cloud)
  2. Configure environment variables in server/.env
  3. Deploy the server/ directory to your preferred platform
  4. Ensure MongoDB connection is accessible

Frontend Deployment

  1. Build the React app: npm run build-client
  2. Deploy the client/build folder to your hosting platform
  3. Update API URL in client/.env for production

Full Stack Deployment

  1. Deploy server to your backend platform
  2. Deploy client to your frontend platform
  3. Update client environment variables to point to production API

πŸ§ͺ Testing

Manual Testing Checklist

  • User registration and login
  • Book browsing and search
  • Individual book borrowing
  • Group creation and management
  • Group book borrowing
  • Book return with different conditions
  • Fine calculation and payment
  • Feedback submission
  • Admin dashboard functionality
  • Email notifications

πŸ“ Default Admin Account

After setting up the system, you can create an admin account using the API:

curl -X POST http://localhost:5000/api/admin/create-admin \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -d '{
    "name": "Admin User",
    "email": "admin@library.com",
    "password": "admin123",
    "phone": "1234567890",
    "address": "Admin Address"
  }'

πŸ†˜ Troubleshooting

Common Issues

  1. MongoDB Connection Error

    • Ensure MongoDB is running
    • Check connection string in server/.env
    • Verify network access if using cloud MongoDB
  2. Email Notifications Not Working

    • Check email configuration in server/.env
    • Verify SMTP credentials
    • Test with a simple email service first
  3. Frontend Not Connecting to Backend

    • Verify REACT_APP_API_URL in client/.env
    • Check if backend server is running
    • Ensure CORS is properly configured
  4. Authentication Issues

    • Check JWT_SECRET in server/.env
    • Verify token expiration settings
    • Clear browser localStorage if needed

πŸ“š Additional Resources

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.


Happy Coding! πŸŽ‰

For any issues or questions, please check the troubleshooting section or create an issue in the repository.