BookBrain helps readers turn books into long-term vocabulary growth. It tracks words and quotes you discover, and gives you a workflow to revisit them later (so learning sticks). Users authenticate, then connect their own PostgreSQL database for content storage, so they keep ownership of their data.
Many reading apps can store notes, but they do not provide a clean path for structured vocabulary review. BookBrain focuses on:
- Capturing words and quotes with consistent structure
- Scheduling reviews (spaced repetition style) via
nextReviewAt - Keeping user data in the user's own database rather than a shared app database
- Avoids “lock-in” by letting users provide their own content database connection string
- Makes onboarding predictable by provisioning the required schema automatically
- Supports updating credentials later without breaking the redirect/setup flow
BookBrain uses two PostgreSQL databases:
Stores:
- NextAuth user accounts/sessions
- Encrypted per-user secrets (the user content DB URL and the AI API key)
Prisma schema: prisma/schema.prisma
Stores:
Book,Word,Quote, andChatMessagedata- A small metadata table (
public.bookbrain_meta) used to track provisioning/schema version
Prisma schema: prisma/schema.content.prisma
The content schema is provisioned from SQL files in prisma/content-sql/*.
Authentication is handled by NextAuth (credentials and/or Google).
On /setup, the user submits:
- Their PostgreSQL connection string for their content DB
- Their Google Gemini API key
The app saves these values in the app database (encrypted).
After saving, the app:
- Checks
/api/content-db/statusto see whether the required tables/schema exist - If not provisioned, calls
/api/content-db/provisionto create/upgrade tables
When provisioning succeeds, the user is redirected to the homepage.
Users can revisit /setup at any time to update their content DB URL and/or AI key. The app keeps the setup state in sync and avoids infinite redirect loops.
/api/settings/secretsfor saving/loading encrypted secrets (app DB)/api/content-db/statusto detect whether the content schema is already provisioned (user DB)/api/content-db/provisionto provision/upgrade the content schema into the user DB
- User content stays in the user-provided database. The app provisions the schema but does not migrate/own the user's data.
- Secrets are encrypted using
ENCRYPTION_KEY.
- Next.js (App Router)
- NextAuth
- Prisma (two Prisma schemas/clients)
- PostgreSQL
pgfor direct content DB provisioning checks/execution- Gemini integration (via
@ai-sdk/google)
- Install dependencies:
pnpm install
- Configure
.env - Start:
pnpm dev
Common environment variables:
APP_DATABASE_URL(required: app DB for auth + encrypted secrets)ENCRYPTION_KEY(required: used to encrypt the user DB URL and AI key)AUTH_SECRET(required: NextAuth)AUTH_GOOGLE_ID/AUTH_GOOGLE_SECRET(optional: Google sign-in)CONTENT_DATABASE_URL(required by Prisma tooling for content schema generation/migrations; runtime uses user-provided DB URL)