A production-ready writing growth engine for students that analyzes essays, teaches skills, tracks growth over time, and helps understand grading patternsβall while maintaining strict academic integrity.
RefineLab NEVER generates content you can paste into your essay. The system provides:
β
Feedback, insights, metrics, and strategic guidance
β
Analysis of structure and identification of weaknesses
β
Explanations of WHY something needs improvement
β
Conceptual teaching of writing principles
β Does NOT write thesis statements or paragraphs
β Does NOT rewrite or paraphrase your text
β Does NOT generate replacement content
This is enforced at both the UX level and through LLM system prompts.
-
Context-Aware Structure Mapper - Paragraph-level visualization showing thesis clarity, argument depth, transitions, and analysis quality
-
Insight-Based Writing Lessons - Adaptive lessons linked to detected weaknesses (generic principles, not essay-specific text)
-
Multi-Essay Growth Dashboard - Track metrics over time with line charts, radar charts, and tables
-
Real-Time Writing Skill Delta Analyzer - Compare drafts showing metric improvements (not text diffs)
-
Grading Pattern Analyzer - Identify patterns in past grades and rubric dimensions
-
Pattern-Adaptive Essay Coach - Strategic prompts linked to specific paragraphs with conceptual guidance
-
Semester Writing Fingerprint - Aggregated view of tone, structure, pacing, and evidence habits
-
Assignment Goal Setting + Progress Tracking - Define goals and track progress per assignment
-
Grade Prediction Simulator - Probabilistic grade band estimates based on metrics and patterns
-
Document Upload with OCR - Upload PDFs, DOCX files, or images to extract text and teacher comments
- Framework: Next.js 15 (App Router) with TypeScript
- Styling: Tailwind CSS + shadcn/ui components
- Database: PostgreSQL via Prisma ORM
- Authentication: NextAuth.js (Google OAuth + Email/Password)
- AI: Google Gemini 2.0 Flash (with academic integrity system prompts)
- OCR: Tesseract.js + pdf-parse + mammoth
- Charts: Recharts
- Deployment: Vercel-ready
- Node.js 18+ and npm
- PostgreSQL database
- Google OAuth credentials
- Gemini API key
- Clone the repository
git clone <your-repo-url>
cd refinelab- Install dependencies
npm install- Set up environment variables
Create a .env file in the root directory:
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/refinelab?schema=public"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here-generate-with-openssl-rand-base64-32"
# Google OAuth
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# Gemini API
GEMINI_API_KEY="your-gemini-api-key"To generate NEXTAUTH_SECRET:
openssl rand -base64 32To get Google OAuth credentials:
- Go to Google Cloud Console
- Create a project
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google
To get Gemini API key:
-
Go to Google AI Studio
-
Create an API key
-
Set up the database
npx prisma generate
npx prisma migrate dev --name init- Run the development server
npm run devOpen http://localhost:3000 in your browser.
-
Push your code to GitHub
-
Import project to Vercel
- Go to vercel.com
- Click "New Project"
- Import your GitHub repository
-
Set up Postgres database
- In Vercel dashboard, go to Storage
- Create Postgres database
- Copy DATABASE_URL to environment variables
-
Configure environment variables
- Add all environment variables from
.env - Make sure to use production URLs for NEXTAUTH_URL and Google OAuth redirect URIs
- Add all environment variables from
-
Deploy
- Vercel will automatically deploy on push to main branch
refinelab/
βββ app/
β βββ api/ # API routes
β β βββ auth/ # Authentication endpoints
β β βββ essays/ # Essay CRUD operations
β β βββ upload/ # File upload & OCR processing
β β βββ compare/ # Essay comparison
β β βββ goals/ # Goal tracking
β β βββ grading-patterns/
β βββ auth/ # Auth pages (signin, signup)
β βββ dashboard/ # Main dashboard
β βββ essays/ # Essay list and detail views
β βββ upload/ # Upload essay page
β βββ compare/ # Compare drafts page
β βββ page.tsx # Landing page
βββ components/
β βββ ui/ # shadcn/ui components
βββ lib/
β βββ auth.ts # NextAuth configuration
β βββ prisma.ts # Prisma client
β βββ ai.ts # Gemini AI integration
β βββ document-processor.ts # OCR & file processing
βββ prisma/
β βββ schema.prisma # Database schema
βββ types/
βββ next-auth.d.ts # TypeScript declarations
The application uses the following main models:
- User - User accounts with authentication
- Essay - Uploaded essays with metrics and analysis
- EssayComparison - Comparison data between essay versions
- Goal - User-defined improvement goals
- GradingPattern - Historical grading data for analysis
GET /api/essays- List all essays for authenticated userPOST /api/essays- Create and analyze new essayGET /api/essays/[id]- Get essay by IDDELETE /api/essays/[id]- Delete essay
POST /api/upload- Upload and process document (PDF/DOCX/Image)
POST /api/compare- Compare two essay versions
GET /api/goals- List goalsPOST /api/goals- Create goal
GET /api/grading-patterns- List patternsPOST /api/grading-patterns- Add pattern
# Run development server
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run linter
npm run lint
# Generate Prisma client
npx prisma generate
# Create database migration
npx prisma migrate dev --name your_migration_name
# Open Prisma Studio (database GUI)
npx prisma studioThe system enforces academic integrity through multiple layers:
- LLM System Prompts - Hard-coded prompts that instruct the AI to never generate essay content
- API Validation - Backend checks to ensure responses don't violate integrity rules
- UI Guardrails - Frontend warnings and disabled features for prohibited actions
- Response Format - AI outputs are structured as metrics, tags, and bullet pointsβnever continuous prose
This is a production-ready template. Feel free to customize for your specific needs while maintaining the academic integrity protections.
MIT License - See LICENSE file for details
For issues or questions, please open a GitHub issue.
Built with academic integrity at its core. π‘οΈ