Skip to content
DukeazetaPublic

About

Upload notes and get summaries, mind maps, flashcards and quizzes, generated with Gemini.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

Note2Mind

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.

Features

  • 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

Tech Stack

Frontend

  • Next.js 16 App Router
  • React 19
  • TypeScript
  • TanStack Query
  • Zustand
  • React Flow
  • Framer Motion

Backend

  • 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

Repository Structure

note2mind/
  backend/      Express API, Prisma schema, document processing
  frontend/     Next.js web application
  package.json  Root workspace scripts

Prerequisites

  • 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.

Getting Started

Install dependencies from the repository root:

pnpm install

Create environment files:

cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env

Fill in backend/.env with your Neon connection strings, R2 credentials, and Gemini API key. See Environment Variables.

Check that everything is reachable:

pnpm check:setup

This verifies each service independently and tells you exactly which values are still missing.

Apply the database schema:

pnpm prisma:deploy

Use prisma:deploy (prisma migrate deploy) rather than prisma: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:backend

Start the frontend in another terminal:

pnpm dev:frontend

Open http://localhost:3000.

Environment Variables

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_URL is the pooled connection the application uses for its queries.
  • DIRECT_URL is 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.

Scripts

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 development

API Overview

All 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

How Background Processing Works

Jobs are stored in PostgreSQL and processed on demand. Nothing polls in a loop.

  1. 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.
  2. The HTTP response returns straight away; the drain keeps working in the background.
  3. A safety sweep runs every JOB_SWEEP_INTERVAL_MINUTES to pick up retries and jobs orphaned by a crash, and to fail any document that can never finish.

Why not Redis

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.

Development Notes

  • 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.

Troubleshooting

  • sslmode warning from pg on startup. Harmless. pg currently treats sslmode=require as verify-full; a future major version will change that. Pick either behaviour explicitly if the warning is unwelcome.
  • PutObject fails against R2 with a checksum error. Some AWS SDK versions send checksum headers R2 rejects. Set requestChecksumCalculation: "WHEN_REQUIRED" on the S3Client in backend/src/services/storage/s3.service.ts.
  • Uploads stay in UPLOADED and never complete. The queue can't reach the database. Check that DIRECT_URL is the direct (non-pooler) connection string.

Current Limitations

  • 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.

Contributing

Contributions are welcome. Before opening a pull request:

  1. Keep changes focused.
  2. Run the relevant validation commands.
  3. Include migrations for schema changes.
  4. Do not commit .env files or secrets.

License

MIT

About

Upload notes and get summaries, mind maps, flashcards and quizzes, generated with Gemini.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages