A modern library management system built with Next.js, allowing users to browse, borrow, and return books with an intuitive interface.
Digital Catalog
User Management
Track Borrowings
A modern library management system built with Next.js, allowing users to browse, borrow, and return books with an intuitive interface.
Preview Link:
Test Credentials:
admin@test.comAdmin@123user@test.comUser@123The Library is a full-stack web application that provides a digital library experience.
The application follows a modern full-stack architecture with clear separation of concerns:
The book borrowing system enforces business rules and manages inventory:
ACTIVE: Book is currently borrowedRETURNED: Book has been returnedGET /api/v1/books - Get paginated list of books with searchGET /api/v1/books/categories - Get book categoriesPOST /api/v1/books/[id]/borrow - Borrow a bookPOST /api/v1/books/[id]/return - Return a bookGET /api/v1/borrowings - Get user's active borrowingsGET /api/v1/borrowings/history - Get user's borrowing historyPOST /api/v1/admin/books - Create a new bookPUT /api/v1/admin/books/[id] - Update a bookDELETE /api/v1/admin/books/[id] - Delete a bookGET /api/v1/admin/inventory - Get inventory statistics and analyticsGET /api/v1/admin/borrowings - Get all borrowings across the libraryPOST /api/v1/auth/register - Register a new userPOST /api/auth/[...nextauth] - NextAuth authentication endpoints.nvmrc)Set up environment variables (see )
Run the development server:
After setting up your MongoDB database (local or cloud), you need to import the existing data to get started with sample books and test user accounts.
The project includes sample data in the tmp/ directory. Import the data using mongoimport:
For local MongoDB:
For MongoDB Atlas (cloud):
Note: Replace username, password, and cluster.mongodb.net with your actual MongoDB Atlas connection details.
After importing the data, you can use the test credentials mentioned in the section to log in.
Create a .env.local file in the root directory with the following variables:
This project is private.
the-library/āāā app/ # Next.js App Routerā āāā api/ # API routesā ā āāā auth/ # Authentication endpointsā ā āāā v1/ # API v1 endpointsā ā āāā books/ # Book-related endpointsā ā āāā borrowings/ # Borrowing endpointsā ā āāā admin/ # Admin-only endpointsā ā āāā books/ # Book management endpointsā ā āāā inventory/ # Inventory statistics endpointā ā āāā borrowings/ # All borrowings endpointā āāā auth/ # Authentication pagesā ā āāā login/ā ā āāā register/ā āāā dashboard/ # Protected dashboard pagesā ā āāā books/ # Books listing pageā ā āāā borrowed-books/ # User's borrowed booksā ā āāā borrowing-history/ # User's borrowing historyā ā āāā profile/ # User profileā ā āāā admin/ # Admin-only pagesā ā āāā books/ # Book management pageā ā āāā inventory/ # Inventory management pageā ā āāā borrowings/ # All borrowings management pageā āāā layout.tsx # Root layoutā āāā page.tsx # Home pageā āāā providers.tsx # Global providersāāā components/ # React componentsā āāā auth/ # Authentication componentsā āāā dashboard/ # Dashboard componentsā āāā navbar/ # Navigation componentsā āāā ui/ # Reusable UI componentsāāā services/ # Business logic layerā āāā auth/ # Authentication servicesā āāā books/ # Book servicesā āāā borrowing/ # Borrowing servicesā āāā user/ # User servicesāāā lib/ # Utility librariesā āāā db.ts # Database connectionā āāā query-client.ts # React Query clientā āāā utils.ts # Utility functionsāāā store/ # Redux storeāāā hooks/ # Custom React hooksāāā types/ # TypeScript type definitionsāāā auth.ts # NextAuth configurationāāā package.json # Dependenciesgit clone https://github.com/chhavipaliwal/the-librarycd the-librarypnpm installpnpm dev# Import users (includes admin and test user accounts)mongoimport --uri="mongodb://localhost:27017/the-library" --collection=users --file=tmp/the-library.users.json --jsonArray# Import booksmongoimport --uri="mongodb://localhost:27017/the-library" --collection=books --file=tmp/the-library.books.json --jsonArray# Import usersmongoimport --uri="mongodb+srv://username:password@cluster.mongodb.net/the-library" --collection=users --file=tmp/the-library.users.json --jsonArray# Import booksmongoimport --uri="mongodb+srv://username:password@cluster.mongodb.net/the-library" --collection=books --file=tmp/the-library.books.json --jsonArraypnpm buildpnpm startMONGODB_URI=mongodb://localhost:27017/the-library# or for MongoDB Atlas:# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/the-libraryNEXTAUTH_SECRET=your-secret-key-hereNEXTAUTH_URL=http://localhost:3000