BookNook
Full-Stack Online Library Management System with Atomic Borrowing & JWT Route Protection

Architectural Overview
BookNook is an enterprise-grade library management application engineered to solve real-world book circulation and borrowing workflows. Built on the Next.js App Router and a modular Express backend, it provides seamless catalog navigation, instant regex-powered book discovery, and strict state management. The borrowing lifecycle ensures zero stock inconsistencies by applying atomic MongoDB filter updates. Protected routes leverage stateless JWT verification using the `jose` library across both client-side middleware and server endpoints.
Key Features
- ✓Dynamic Book Cataloging: Comprehensive category navigation, genre grouping, and real-time regex search filtering.
- ✓Atomic Borrowing Engine: Ensures race-condition prevention when stock reaches 0 using atomic MongoDB queries (`$inc: { copies: -1 }` with `{ copies: { $gt: 0 } }`).
- ✓Interactive Borrow Modal: Custom modal dialogs with borrower verification, automated return date calculation, and instant UI state updates.
- ✓Stateless JWT Authentication: Secure user sessions authenticated via `jose` across Next.js middleware and protected Express endpoints.
- ✓Book Return & Replenishment: Clean return workflows that atomically increment available inventory and record borrowing histories.
Challenges Faced While Developing the Project
Preventing Inventory Race Conditions During Simultaneous Borrowing
High concurrent borrow attempts on books with 1 copy remaining risked negative inventory counts. Resolved this by swapping read-then-write updates with single atomic MongoDB operations combining an increment filter (`$inc: { copies: -1 }`) and query predicate (`copies: { $gt: 0 }`), ensuring safe and consistent concurrency.
Next.js App Router Prerender ECONNREFUSED Errors
During production static build runs, dynamic pages attempted fetching from backend APIs before the server was up. Resolved this by implementing dynamic runtime segment configs (`export const dynamic = 'force-dynamic'`) and graceful fallback skeletons on SSR boundaries.
Desktop Book Cover Aspect Ratio Distortion
Varying user-uploaded book cover dimensions caused erratic card heights and cropped artwork. Solved using standardized Next.js Image containers with fixed `aspect-[3/4]` ratios and CSS object-cover with padded backdrop blur.
Potential Improvements & Future Plans
Automated Due-Date Notifications: Integration with nodemailer and cron workers for 48-hour return reminders.
Admin Analytics Dashboard: Real-time circulation charts, overdue tracking, and most-read genre metrics.
AI-Powered Book Recommendations: Vector embeddings or genre-similarity algorithms recommending next reads based on user borrowing history.