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.

Smart library system

The Problem

Traditional library systems have two pain points: clunky keyword search that forces users to know exactly what they're looking for, and no way to surface "you might also like" suggestions at the moment a user is most engaged — right after checkout. The goal was to solve both without requiring a backend AI subscription.

The Solution

Built a Next.js App Router application where AI is opt-in: users paste their OpenAI key once into the navbar, it lives only in sessionStorage, and every AI request forwards it via an X-API-Key header. Three AI features were implemented: - Natural language search — sends a compact catalog (~400 tokens) to gpt-4o-mini and gets back ranked book IDs - Streaming chatbot — library assistant with full catalog context, using Vercel AI SDK's useChat + streaming - Post-checkout recommendations — hybrid approach: DB query for genre/author matches, then LLM ranking if a key is available, score-based fallback if not

My Role

Full-stack developer

Tech Stack

Next.js 16 (App Router) TypeScriptReact 19 PostgreSQLPrisma 7Auth.js v5Tailwind CSS v4OpenAIVercel

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

Smart library system Screenshot
Smart library system Screenshot
Smart library system Screenshot
Smart library system Screenshot
Smart library system Screenshot