Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library Management System

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.

Overview

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 Documentation

Features

  • 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

Tech Stack

  • 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

Project Structure

  • Backend/ - Express server, database models, validation, middleware, and mail helper
  • Library/ - Vite React client
  • Readme.md - Project documentation

Setup

Prerequisites

  • Node.js 16+ recommended
  • MongoDB Atlas or a local MongoDB server

1. Clone the repository

git clone https://github.com/Ali1180-uni/Library-System_MERN.git
cd Library-System_MERN

2. Backend

cd Backend
npm install

Create a .env file inside Backend:

MONGODB_URI=your_mongodb_connection_string
SECRET=your_session_secret

Start the backend:

npm run dev

The server runs on http://localhost:3000.

3. Frontend

Open a second terminal and run:

cd Library
npm install
npm run dev

The app runs on Vite's default dev server, usually http://localhost:5173.

Available Scripts

Backend

  • npm run dev - start the Express server with Nodemon

Frontend

  • npm run dev - start the Vite development server
  • npm run build - build the production bundle
  • npm run lint - run ESLint
  • npm run preview - preview the production build locally

DeepWiki Diagrams

The following diagrams summarize the architecture and request flow documented in DeepWiki.

1. System Architecture

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
Loading

2. Backend Wiring

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
Loading

3. Request Flow to Code Entities

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
Loading

4. Borrowing Flow

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
Loading

5. App Initialization Hierarchy

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
Loading

6. Auth State and Guard Flow

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
Loading

7. Route Hierarchy

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
Loading

8. Client to Server Mapping

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
Loading

API Endpoints

The frontend currently talks to http://localhost:3000.

Public and Auth Routes

  • GET /books - list all books
  • GET /books/:id - get a single book
  • GET /books/auth-check - check current session
  • GET /books/me - get authenticated user profile
  • GET /books/logout - destroy the session
  • POST /signup - register a new user
  • POST /login - log in a user
  • POST /books/otp - send an OTP email

Book Actions

  • POST /books - add a book, admin only
  • PUT /books/:id - update a book, admin only
  • DELETE /books/:id - delete a book, admin only
  • POST /books/borrow/:id - borrow a book
  • POST /books/return/:id - return a book

Frontend Routes

  • / - 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

Notes

  • The backend is configured for CORS with http://localhost:5173 and the deployed Vercel frontend.
  • If you move the API to another host, update the hardcoded base URLs in Library/src/api/api.js and Library/src/main.jsx.
  • The project uses session cookies, so requests must include credentials.

Contributing

Pull requests are welcome. If you extend the project, keep the documentation in sync with the actual scripts, routes, and environment variables.

Releases

Packages

Contributors

Languages