Note2Mind is a full-stack study tool that turns uploaded notes into structured learning assets. A user can upload a TXT, PDF, or DOCX file, then the backend extracts the text, sends it through Gemini, and stores generated summaries, mind maps, flashcards, and quizzes for review in the web app.
The project is built as a pnpm workspace with a Next.js frontend and a TypeScript Express backend.
- Email/password authentication with JWT access and refresh tokens
- Document upload for TXT, PDF, and DOCX files
- Private document storage in Cloudflare R2 (S3-compatible)
- On-demand background processing with pg-boss, no separate queue service
- Text extraction and cleanup before AI processing
- Gemini-powered generation of:
- Mind maps
- Short and long summaries
- Key points
- Flashcards
- Quizzes with answers and explanations
- PostgreSQL persistence through Prisma
- Authenticated dashboard for uploaded documents
- Study views for mind maps, summaries, flashcards, and quizzes
- Next.js 16 App Router
- React 19
- TypeScript
- TanStack Query
- Zustand
- React Flow
- Framer Motion
- Node.js
- Express
- TypeScript
- Prisma
- PostgreSQL
- pg-boss
- AWS S3 SDK, used as a generic S3 client against Cloudflare R2
- Gemini via
@google/genai - Zod
note2mind/
backend/ Express API, Prisma schema, document processing
frontend/ Next.js web application
package.json Root workspace scripts
- Node.js 22.12 or later (pg-boss requires it)
- pnpm
- A PostgreSQL database (this project uses Neon)
- A Cloudflare R2 bucket
- Gemini API key
No Docker and no Redis are required. There is nothing to run locally beyond the two dev servers.
Install dependencies from the repository root:
pnpm installCreate environment files:
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.envFill in backend/.env with your Neon connection strings, R2 credentials, and Gemini API key. See Environment Variables.
Check that everything is reachable:
pnpm check:setupThis verifies each service independently and tells you exactly which values are still missing.
Apply the database schema:
pnpm prisma:deployUse
prisma:deploy(prisma migrate deploy) rather thanprisma:migrate(prisma migrate dev) when pointing at a database that holds real data. The dev command can offer to reset it.
Start the backend API:
pnpm dev:backendStart the frontend in another terminal:
pnpm dev:frontendOpen http://localhost:3000.
Backend variables are documented in backend/.env.example. The important ones:
PORT
FRONTEND_ORIGIN
DATABASE_URL # Neon pooled connection
DIRECT_URL # Neon direct connection (migrations + pg-boss)
JOB_SWEEP_INTERVAL_MINUTES
JWT_ACCESS_SECRET
JWT_REFRESH_SECRET
S3_ENDPOINT # https://<account-id>.r2.cloudflarestorage.com
S3_REGION # "auto" for R2
S3_BUCKET
S3_ACCESS_KEY_ID
S3_SECRET_ACCESS_KEY
GEMINI_API_KEY
GEMINI_DEFAULT_MODEL
GEMINI_STRONG_MODEL
The storage variables are named S3_* because R2 speaks the S3 protocol. No AWS account is involved — those values all come from Cloudflare.
Two connection strings are required on purpose:
DATABASE_URLis the pooled connection the application uses for its queries.DIRECT_URLis the direct connection used by Prisma migrations and by pg-boss. pg-boss needs session-level locking, which PgBouncer's transaction pooling mode does not support.
Frontend variables are documented in frontend/.env.example. The only one is NEXT_PUBLIC_API_URL.
Run these from the repository root:
pnpm dev:frontend # Start the Next.js app
pnpm dev:backend # Start the Express API (and its job queue)
pnpm check:setup # Verify the database, queue, and R2 are reachable
pnpm build # Build all workspace packages
pnpm typecheck # Type-check the backend
pnpm lint # Lint the frontend
pnpm prisma:validate # Validate the Prisma schema
pnpm prisma:deploy # Apply migrations to an existing database
pnpm prisma:migrate # Create/apply migrations during developmentAll backend routes are mounted under /api/v1.
Auth:
POST /auth/register
POST /auth/login
POST /auth/refresh
POST /auth/logout
GET /auth/me
Documents:
POST /documents/upload
GET /documents
GET /documents/:id
GET /documents/:id/status
POST /documents/:id/reprocess
DELETE /documents/:id
Generated study assets:
GET /documents/:id/mindmap
GET /documents/:id/summary
GET /documents/:id/flashcards
GET /documents/:id/quizzes
Jobs are stored in PostgreSQL and processed on demand. Nothing polls in a loop.
- An upload writes the file to R2, creates a document and a processing job, stores a job row through pg-boss, and immediately starts a drain.
- The HTTP response returns straight away; the drain keeps working in the background.
- A safety sweep runs every
JOB_SWEEP_INTERVAL_MINUTESto pick up retries and jobs orphaned by a crash, and to fail any document that can never finish.
Redis was removed along with BullMQ. It existed only to hold the queue, and a queue worker's natural behaviour is to poll the database continuously.
That matters because Neon's free plan suspends a compute after five minutes without queries, and the monthly allowance is 100 CU-hours (about 400 hours awake). A worker polling every couple of seconds would never let the database sleep and would exhaust that allowance in roughly sixteen days. The sweep interval is therefore kept above the five minute suspend window, and JOB_SWEEP_INTERVAL_MINUTES is validated at a minimum of 6.
If you change this design, keep that constraint in mind: anything that queries the database on a timer shorter than five minutes prevents the database from suspending.
- The frontend sends uploaded files with the multipart field name
file. - The backend stores uploaded files privately, then processes them asynchronously.
- The frontend polls document status while processing is still running, capped at five minutes per document. The cap is a safety net: a document stuck in a non-terminal state would otherwise keep the database awake indefinitely.
- Generated AI output is validated before being persisted.
- Keep future database changes in Prisma migrations.
sslmodewarning frompgon startup. Harmless.pgcurrently treatssslmode=requireasverify-full; a future major version will change that. Pick either behaviour explicitly if the warning is unwelcome.PutObjectfails against R2 with a checksum error. Some AWS SDK versions send checksum headers R2 rejects. SetrequestChecksumCalculation: "WHEN_REQUIRED"on theS3Clientinbackend/src/services/storage/s3.service.ts.- Uploads stay in
UPLOADEDand never complete. The queue can't reach the database. Check thatDIRECT_URLis the direct (non-pooler) connection string.
- Automated test coverage is still limited.
- PDF extraction should be tested against more real-world PDF files.
- Refresh tokens are currently handled by the JSON API flow; HTTP-only cookie support would be a stronger production option.
- Rate limiting should be added before exposing AI-heavy routes publicly.
- Local development shares the production database. Dev uploads and deletions therefore affect real rows; a Neon branch is the cheap way to separate them.
Contributions are welcome. Before opening a pull request:
- Keep changes focused.
- Run the relevant validation commands.
- Include migrations for schema changes.
- Do not commit
.envfiles or secrets.
MIT