← Back to Projects
BookHub

BookHub

Book catalog with optimistic UI updates and consistent REST API design.

Live Code

Overview

Built as a deliberate exercise in REST API fundamentals before adding complexity in later projects. Every endpoint returns a consistent response envelope (status, data, message); error responses include machine-readable codes alongside human-readable messages; all mutations return the updated resource rather than a generic success flag. Optimistic updates on the frontend keep the UI responsive — edits appear immediately and roll back cleanly from a pre-mutation snapshot if the API call fails. This pattern was carried forward into every subsequent MERN project as a baseline.

Key Features

  • Consistent API response envelope across all endpoints — predictable shape for every frontend consumer
  • Optimistic UI updates with snapshot-based rollback on failure — no re-fetch, no stale data flash
  • Search and filter by title, author, and genre
  • Cover image management via URL-based storage
  • Machine-readable error codes on all failure responses — frontend can differentiate error types without string parsing

Tech Stack

Frontend: React

Backend: Node.js, Express

Database: MongoDB

Challenges

  • Ensuring rollback logic was reliable — a failed optimistic update that doesn't revert cleanly leaves the UI in a broken state that's difficult to recover from without a page reload

Solutions

  • Stored pre-mutation state in a local variable before applying the optimistic update; the catch block restores from that snapshot rather than re-fetching — faster recovery and avoids a flash of stale server data

Future Improvements

  • User authentication with personal reading lists and progress tracking
  • ISBN lookup via Open Library API to auto-fill book metadata on add