Skip to content

prathiusharun/studymode

Repository files navigation

StudyMode AI Learning Extraction System

Live Demo

https://studymode-ai.vercel.app/


Overview

StudyMode is an AI-powered learning extraction system designed to improve reasoning, clarity, and depth of understanding.

Instead of behaving like a traditional chatbot that gives direct answers, StudyMode acts as a cognitive refinement system that helps users:

  • structure raw thoughts
  • strengthen mental models
  • refine reasoning
  • transform vague understanding into clear knowledge

The goal is not passive consumption. The goal is deeper thinking.


Core Philosophy

Most AI tools optimize for answer generation.

StudyMode optimizes for:

  • reasoning
  • reflection
  • structured understanding
  • knowledge extraction

The system is intentionally designed to:

  • slow down shallow thinking
  • force causal reasoning
  • encourage active recall
  • build connected mental models

It acts as a thinking amplifier rather than an answer machine.


Current System Architecture

graph TD

A[User Input] --> B[Next.js Frontend]

B --> C[API Route /api/chat]

C --> D[Authentication Layer]

D --> E[Rate Limiting Layer]

E --> F[Conversation Builder]

F --> G[System Prompt Engine]

G --> H[Gemini AI API]

H --> I[Response Processor]

I --> J[Structured Learning Output]

J --> B

B --> K[Generate Post API /api/generate]

K --> L[Prompt Transformation Layer]

L --> H

H --> M[LinkedIn Style Post Output]

M --> B
Loading

Current Features

Learning Extraction System

  • AI-powered reasoning refinement
  • Structured learning outputs
  • Mental model focused responses
  • Active recall oriented conversation flow
  • System guided reasoning instead of direct answers

UI System (Claude-style Interface)

  • Centered chat layout inspired by Claude
  • Persistent sidebar (UI-level only, no database persistence yet)
  • Dark / Light theme toggle system
  • Chat-first minimal interface design
  • Responsive input dock with action buttons

Content Transformation Pipeline

  • Converts learning sessions into structured posts

Extracts:

  • insights

  • pain points

  • analogies

  • realizations

  • Generates LinkedIn-style educational content


Backend & Auth Protection Layer

  • Backend-only AI execution
  • Environment variable protection
  • Global AI kill switch
  • API route protection
  • Google OAuth authentication via NextAuth.js (session-based authentication)
  • Session-based user identity system
  • Request rate limiting
  • Structured backend logging (console-based; no external observability pipeline yet)
  • Production-aware request handling
  • Redis-based request rate limiting (Upstash / Redis-compatible store)
  • Redis-based global cost budgeting system (atomic reservation)
  • Daily AI cost budgeting per user
  • Prevents uncontrolled API billing
  • Token usage estimation before AI execution
  • Blocks requests when estimated cost exceeds budget

OAuth Configuration

Google OAuth supports both environments:

Local

http://localhost:3000/api/auth/callback/google

Production

https://studymode-ai.vercel.app/api/auth/callback/google

Both must be configured in Google Cloud Console.


Deployment Infrastructure

  • Vercel deployment pipeline
  • CI/CD through GitHub integration
  • Environment-separated configuration
  • Serverless backend architecture

Vercel Environment Variables

The following must be configured in Vercel:

  • GOOGLE_CLIENT_ID
  • GOOGLE_CLIENT_SECRET
  • NEXTAUTH_SECRET
  • NEXTAUTH_URL (production URL)
  • GEMINI_API_KEY
  • REDIS_URL

Tech Stack

Frontend

  • Next.js App Router
  • React
  • TypeScript
  • Tailwind CSS

Backend

  • Next.js API Routes
  • Rate Limiting Layer
  • Structured Logging System

AI Infrastructure

  • Google Generative AI (Gemini)

Deployment

  • Vercel
  • GitHub CI/CD

System Flow

Learning Mode Flow

  • User enters raw thought or confusion
  • Request passes Google OAuth (NextAuth session layer)
  • Request passes rate limiting layer (Redis)
  • Token usage is estimated before AI execution
  • AI cost budget is validated (Redis stored quota)
  • Prompt engine constructs structured reasoning prompt
  • Gemini processes request
  • Response is returned with usage metadata
  • Usage is stored for daily tracking

Post Generation Flow

  • User completes learning session
  • Conversation history is transformed into structured context

AI Extracts:

  • insight

  • struggle

  • analogy

  • realization

  • System generates LinkedIn-ready educational content


Prompt Design Philosophy

The system is built around strict reasoning constraints.

Core Constraints

  • No shallow direct answers
  • Force reasoning before explanation
  • Encourage active recall
  • Use real-world analogies
  • Preserve user-generated insight
  • Avoid replacing user thinking
  • Build connected mental models
  • One deep concept at a time

The AI is intentionally constrained to improve cognitive depth rather than maximize convenience.


Cost Safety Architecture

graph TD

A[User Request] --> B[Auth Layer]
B --> C[Rate Limit Layer<br/>Redis - requests]
C --> D[Token Estimation Layer]
D --> E[Cost Budget Check<br/>Redis - tokens]
E --> F[AI Execution<br/>Gemini]
F --> G[Usage Logging<br/>Redis]
G --> H[Response]
Loading

API Structure

/api/chat

Handles:

  • learning extraction pipeline
  • conversation orchestration
  • reasoning enforcement
  • prompt construction
  • AI interaction
  • backend protection layers
  • request rate limiting

/api/generate

Handles:

  • post generation pipeline
  • structured transformation of learning sessions
  • insight extraction
  • content refinement
  • LinkedIn-style formatting

No new ideas are introduced during generation.
The pipeline only transforms user-generated understanding.


Current Production Architecture

Security & Protection

  • Backend-only AI calls
  • Protected API routes
  • Environment variable isolation
  • Global AI kill switch
  • Request rate limiting

Operational Infrastructure

  • Structured logging
  • Request-level observability
  • CI/CD deployment pipeline
  • Serverless infrastructure awareness

Architectural Principles

  • Separation of concerns
  • Modular AI pipeline design
  • Stateless serverless architecture
  • Protection before execution
  • Observability over assumptions
  • UI and backend are decoupled; UI state is currently ephemeral and will later support persistent storage

Current Limitations

The system is a production-capable MVP with core safety and cost-control architecture implemented.

Current limitations include:

  • Observability is limited to structured logging only (no tracing or monitoring dashboards)
  • No distributed quota coordination (single Redis instance)
  • Cost enforcement is based on token estimation, not real-time billing reconciliation
  • No automated anomaly detection or abuse detection system
  • Chat persistence layer is not implemented (no database storage)
  • Sidebar chat history is UI-only and resets on refresh

System Maturity

🟡 Production-Ready MVP Stage

The system includes:

  • Authentication
  • Rate limiting
  • Cost control
  • AI pipeline architecture
  • Deployment pipeline

Missing:

  • Persistent storage layer
  • Observability stack
  • Analytics dashboard
  • Multi-session memory system

Future Improvements

Infrastructure

  • Persistent database layer
  • Distributed quota coordination
  • Request tracing system
  • Metrics and monitoring dashboards

Product Features

  • Persistent learning history
  • Personal knowledge graph
  • Spaced repetition system
  • Session memory
  • AI-generated revision cards

AI Expansion

  • Multi-model support
  • Claude integration
  • GPT integration
  • Model routing system
  • Personalized prompting systems

SaaS Features

  • Usage analytics dashboard
  • Subscription system
  • Token usage tracking
  • User-level quotas
  • Exportable learning archives

Engineering Philosophy

StudyMode is built around one core belief:

Better learning comes from better thinking.

The system is designed to help users:

  • observe their reasoning
  • strengthen understanding
  • identify gaps
  • connect concepts
  • think from first principles

The objective is not answer generation.
The objective is cognitive amplification.

The system prioritizes user cognitive quality over response speed, but UI is optimized to feel real-time through streaming simulation techniques.


About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors