Smart library system
A full-stack library management system where users browse, search, and borrow books. Librarians manage inventory and approve requests through an admin panel. AI features natural language search, a streaming chatbot, and post-checkout recommendations.

The Problem
The Solution
My Role
Tech Stack
Key Decisions
- 1
AI key in the browser, not the server — storing the key in sessionStorage and forwarding it per-request means zero AI infrastructure cost and zero key-leakage risk on the server. The tradeoff is that AI features require the user to bring their own key.
- 2
Decrement stock on APPROVE, not PENDING — reducing copiesAvailable only when a librarian approves prevents false "out of stock" states for books that might never get approved. All stock changes happen inside Prisma transactions to prevent race conditions.
- 3
Auth.js Edge split — Next.js middleware runs on the Edge Runtime, which can't use Node.js APIs. Splitting the config into auth.config.ts (edge-safe, no DB) and auth.ts (full Node.js) was necessary to protect routes without breaking the build.
- 4
Score-based AI fallback — every AI feature degrades gracefully: recommendations fall back to a genre/author scoring algorithm, search falls back to standard text search. The app is fully usable without any API key.
- 5
Hybrid DB + LLM recommendations — rather than sending the entire catalog to the LLM, a DB query first narrows candidates to in-stock books in matching genres/authors (max 20). The LLM only ranks those 20, keeping prompts small and latency low.
Screenshot Gallery




