Full-stack library management system built with the MERN stack. It supports book browsing, session-based authentication, borrowing and return flows, profile access, and an admin dashboard for book management.
The repository is organized as a two-part monorepo:
- Backend: Express, MongoDB, sessions, rate limiting, and email OTP support
- Frontend: React, Vite, React Router, React Query, Axios, and toast notifications
- DeepWiki reference: https://deepwiki.com/Ali1180-uni/Library-System_MERN
- Overview page: https://deepwiki.com/Ali1180-uni/Library-System_MERN/1-overview
- Backend architecture: https://deepwiki.com/Ali1180-uni/Library-System_MERN/2-backend-architecture
- Frontend architecture: https://deepwiki.com/Ali1180-uni/Library-System_MERN/3-frontend-architecture
- Routing and route guards: https://deepwiki.com/Ali1180-uni/Library-System_MERN/3.1-routing-and-route-guards
- API endpoints reference: https://deepwiki.com/Ali1180-uni/Library-System_MERN/2.1-api-endpoints-reference
- User registration and login
- Session-based authentication
- Browse all books and view book details
- Borrow and return books
- Profile page with borrowed books
- Admin-only create, edit, and delete book actions
- OTP email sending flow
- Protected and guest-only routes
- Frontend: React 19, Vite, React Router, React Query, Axios, Tailwind CSS v4, React Hook Form, React Hot Toast
- Backend: Node.js, Express 5, MongoDB, Mongoose, bcrypt, express-session, express-rate-limit, cors, nodemailer
- Backend/ - Express server, database models, validation, middleware, and mail helper
- Library/ - Vite React client
- Readme.md - Project documentation
- Node.js 16+ recommended
- MongoDB Atlas or a local MongoDB server
git clone https://github.com/Ali1180-uni/Library-System_MERN.git
cd Library-System_MERNcd Backend
npm installCreate a .env file inside Backend:
MONGODB_URI=your_mongodb_connection_string
SECRET=your_session_secretStart the backend:
npm run devThe server runs on http://localhost:3000.
Open a second terminal and run:
cd Library
npm install
npm run devThe app runs on Vite's default dev server, usually http://localhost:5173.
npm run dev- start the Express server with Nodemon
npm run dev- start the Vite development servernpm run build- build the production bundlenpm run lint- run ESLintnpm run preview- preview the production build locally
The following diagrams summarize the architecture and request flow documented in DeepWiki.
flowchart LR
UI[Frontend]
API[API Client]
EXPRESS[Backend]
LOGIC[Logic]
MODELS[Models]
DB[(MongoDB)]
MAIL[Mailer]
SMTP[(SMTP)]
UI --> API
API -->|HTTP + credentials| EXPRESS
EXPRESS --> LOGIC
LOGIC --> MODELS
MODELS --> DB
EXPRESS --> MAIL
MAIL --> SMTP
flowchart TB
INDEX[Server]
STACK[Middleware]
ROUTES[Routes]
VALIDATION[Validation]
MODELS[Models]
DBCONNECT[Database]
OTP[Mailer]
BCRYPT[Hashing]
INDEX --> STACK --> ROUTES
INDEX --> DBCONNECT
ROUTES --> VALIDATION
ROUTES --> MODELS
ROUTES --> OTP
ROUTES --> BCRYPT
sequenceDiagram
participant C as Client
participant A as API
participant E as Backend
participant M as Database
C->>A: request data
A->>E: HTTP request
E->>M: query or update
M-->>E: result
E-->>A: JSON response
A-->>C: data
flowchart TD
START[Borrow request]
AUTH{Logged in?}
CHECKBOOK[Find book]
AVAILABLE{Available?}
CHECKUSER[Find user]
UPDATEUSER[Add book to user]
UPDATEBOOK[Mark unavailable]
SUCCESS[Success]
START --> AUTH
AUTH -- No --> UNAUTH[Not allowed]
AUTH -- Yes --> CHECKBOOK
CHECKBOOK --> AVAILABLE
AVAILABLE -- No --> UNAVAILABLE[Not available]
AVAILABLE -- Yes --> CHECKUSER
CHECKUSER --> UPDATEUSER --> UPDATEBOOK --> SUCCESS
flowchart TD
MAIN[Entry]
QC[QueryClientProvider]
SM[StrictMode]
ROOT[Root]
BR[BrowserRouter]
TOASTER[Toaster]
NAV[Navbar]
ROUTES[Routes]
FOOTER[Footer]
MAIN --> QC --> SM --> ROOT --> BR --> TOASTER --> NAV --> ROUTES --> FOOTER
flowchart TD
MOUNT[Mount]
CHECK[Auth check]
LOADING{Loading?}
AUTH{Logged in?}
GUEST[Guest route]
PROTECT[Protected route]
LOGIN[Go to login]
BOOKS[Show page]
MOUNT --> CHECK --> LOADING
LOADING -- Yes --> WAIT[Return null]
LOADING -- No --> AUTH
AUTH -- Yes --> BOOKS
AUTH -- No --> LOGIN
GUEST --> BOOKS
PROTECT --> BOOKS
flowchart TD
HOME[Home]
ABOUT[About]
GUEST[Guest]
PROTECTED[Protected]
ADMIN[Admin only]
LOGIN[Login]
REGISTER[Register]
CATALOG[Books]
BORROW[Borrow]
PROFILE[Profile]
ADMINHOME[Admin dashboard]
EDIT[Edit book]
HOME --> ABOUT
HOME --> GUEST --> LOGIN
GUEST --> REGISTER
HOME --> PROTECTED --> CATALOG
PROTECTED --> BORROW
PROTECTED --> PROFILE
PROTECTED --> ADMIN --> ADMINHOME
ADMIN --> EDIT
flowchart LR
FETCH[fetchBooks]
LOGIN[login]
SIGNUP[signup]
BORROW[borrowBook]
RETURN[returnBook]
PROFILE[fetchProfile]
GETBOOKS[GET books]
POSTLOGIN[POST login]
POSTSIGNUP[POST signup]
POSTBORROW[POST borrow]
POSTRETURN[POST return]
GETPROFILE[GET profile]
FETCH --> GETBOOKS
LOGIN --> POSTLOGIN
SIGNUP --> POSTSIGNUP
BORROW --> POSTBORROW
RETURN --> POSTRETURN
PROFILE --> GETPROFILE
The frontend currently talks to http://localhost:3000.
GET /books- list all booksGET /books/:id- get a single bookGET /books/auth-check- check current sessionGET /books/me- get authenticated user profileGET /books/logout- destroy the sessionPOST /signup- register a new userPOST /login- log in a userPOST /books/otp- send an OTP email
POST /books- add a book, admin onlyPUT /books/:id- update a book, admin onlyDELETE /books/:id- delete a book, admin onlyPOST /books/borrow/:id- borrow a bookPOST /books/return/:id- return a book
/- home page/about- about page/login- login page/register- registration page/books- book catalog/books/borrow/:id- borrow flow/books/admin- admin dashboard/books/admin/edit/:id- edit book page/profile/:id- user profile
- The backend is configured for CORS with
http://localhost:5173and the deployed Vercel frontend. - If you move the API to another host, update the hardcoded base URLs in
Library/src/api/api.jsandLibrary/src/main.jsx. - The project uses session cookies, so requests must include credentials.
Pull requests are welcome. If you extend the project, keep the documentation in sync with the actual scripts, routes, and environment variables.