BookHub is a high-performance, full-stack Digital Library & Social Reading Platform designed as a scalable Turborepo Monorepo. Built using Next.js, Express, serverless PostgreSQL (Prisma), and cached Redis, it features robust Clerk authentication and deep AI integration with DeepSeek and Google Books.
BookHub utilizes a modern monorepo topology with isolated workspaces and shared packages.
graph TD
subgraph Client Layer [Frontend - Vercel]
NextJS["Next.js App Router (Hobby/Prod)"]
Zustand["Zustand State Store"]
ReactQuery["React Query (Cache Layer)"]
end
subgraph Auth Provider
Clerk["Clerk JWT Authentication"]
end
subgraph API Layer [Backend - Render]
Express["Express API Server"]
Prisma["Prisma ORM Client"]
end
subgraph Database & Cache
Postgres[(Neon PostgreSQL Serverless)]
Redis[(Upstash Redis Cache)]
end
subgraph External Integrations
DeepSeek["DeepSeek AI (E-Book Generator)"]
GoogleBooks["Google Books API"]
end
%% Relations
NextJS -->|JWT Bearer Token| Express
NextJS -->|Auth Token| Clerk
Express -->|Verify JWT| Clerk
Express -->|Prisma Pooler| Postgres
Express -->|Rate Limit / Cache| Redis
Express -->|Generate Chapters| DeepSeek
Express -->|Fetch External Volume| GoogleBooks
BOOK_REVIEW_APP/
βββ apps/
β βββ web/ # Next.js 15 App Router Frontend
β β βββ src/app/ # App routes (Dashboard, Library, Admin, Auth)
β β βββ src/store/ # Zustand Auth & UI state stores
β βββ api/ # Express.js + TS Backend API
β βββ src/controllers/ # Route controllers (AI, Auth, Books, Reviews)
β βββ src/middlewares/ # Auth (Clerk JWT), CORS Sanitizers, Error handlers
β βββ prisma/ # Neon Postgres Schemas & Migrations
βββ packages/
βββ shared/ # Shared TypeScript Type Definitions & Zod Schemas
| Layer | Component | Description |
|---|---|---|
| Monorepo | Turborepo | High-performance build cache system & task runner |
| Frontend | Next.js 15 | App Router, Server/Client components, dynamic SSR |
| Backend | Express + TS | REST API server compiled & watched via tsx |
| Auth | Clerk Express | User identity and secure session management |
| Database | Neon Postgres | Serverless PostgreSQL with PGBouncer pooling |
| Caching | Upstash Redis | Low-latency caching for API rate-limiting |
| ORM | Prisma | Typesafe database client generation & migration tool |
| Validation | Zod | Shared frontend/backend API validation schemas |
When a user views details or requests an AI E-Book for a search result returned directly from the Google Books API, the backend automatically performs a non-destructive upsert. It connects categories and authors dynamically, and binds them to a unique record. This ensures users can instantly rate, write reviews, and post vibe checks on externally fetched books without duplicate data conflicts.
The E-book module requests DeepSeek to generate a complete chapter-by-chapter reading version of the book's content (at least 5 chapters, 1,500β2,000 words per chapter).
- Fault Tolerance: If the DeepSeek API fails (e.g., token balance limits, network timeout), the backend automatically catches the exception, logs it, and falls back to a high-quality mock chapter generation engine, ensuring
500server errors are never exposed to the client.
To prevent browser preflight checks (OPTIONS) from failing due to minor configuration discrepancies (like adding a trailing slash to environment variables on Render), the Express server runs a custom sanitizer middleware:
let allowedOrigin = process.env.CLIENT_URL || "http://localhost:3000";
if (allowedOrigin.endsWith("/")) {
allowedOrigin = allowedOrigin.slice(0, -1);
}POST /api/auth/registerβ Create local user account matching Clerk ID.POST /api/auth/loginβ Sign in and create local session token.POST /api/auth/refreshβ Refresh expired JWT token.
GET /api/booksβ Fetch catalog books (supports filtering, search, pagination).POST /api/booksβ Store/import a book to the local database.GET /api/books/:idβ Fetch detailed book information, stats, and reviews.POST /api/books/:id/digital-bookβ Retrieve or generate full AI E-book chapters.
POST /api/reviewsβ Post a review (headline, vibe, rating, optional sticker badge).POST /api/reviews/:id/likeβ Toggle a like on a review.POST /api/reviews/:id/reportβ Report a review for moderation.
git clone https://github.com/UnknownHawkins/BOOK_REVIEW_APP.git
cd BOOK_REVIEW_APP
npm installCreate /apps/api/.env:
DATABASE_URL="postgresql://neondb_owner:...&pgbouncer=true"
DIRECT_URL="postgresql://neondb_owner:..."
PORT=5000
NODE_ENV=development
JWT_SECRET="dev_secret_key"
DEEPSEEK_API_KEY="your_api_key"
GEMINI_API_KEY="your_api_key"
GOOGLE_BOOKS_API_KEY="your_api_key"
UPSTASH_REDIS_REST_URL="https://..."
UPSTASH_REDIS_REST_TOKEN="..."
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_test_..."
CLERK_SECRET_KEY="sk_test_..."Create /apps/web/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:5000/api
NEXT_PUBLIC_SITE_URL=http://localhost:3000
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/auth/login
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/auth/register
NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/
NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/Run the parallel workspace developers:
npm run dev- Frontend: http://localhost:3000
- Backend: http://localhost:5000
- API Documentation: http://localhost:5000/api/docs
- Set the Root Directory to
apps/web. - Turn ON "Include files outside of the Root Directory in the Build Step".
- Set Build Command to:
cd ../.. && npx turbo run build --filter=bookhub-web
- Set Output Directory to Default (
.next).
- Create a Web Service with Root Directory set to
apps/api. - Build Command:
npm install && npx prisma generate - Start Command:
npx tsx src/index.ts - Set
CLIENT_URLenv variable to Vercel's live deployment URL (no trailing slash).