Documentation

AI Course Generator Platform

A comprehensive guide to the architecture, features, and innovations of our AI-powered educational platform.

Platform Overview

AI-Powered Course Generation

Create comprehensive courses tailored to specific topics using advanced AI models.

Secure Authentication

Role-based access control with NextAuth v5 integration for secure user management.

Modern UI/UX

Clean, responsive interface built with React 19, Next.js 15, and Tailwind CSS 4.

Content Management

Organize and structure educational materials with intuitive interfaces.

File Uploads

Support for various document formats (PDF, DOCX) with automatic content extraction.

API Integration

Seamless connections with AI services like Groq and LangChain for content generation.

Technical Architecture

Backend Technology

Next.js API Routes

Server-side API endpoints for handling data operations and business logic.

Prisma ORM

Type-safe database access with automated migrations and schema management.

PostgreSQL

Relational database with vector extension for AI embeddings and similarity search.

Redis

In-memory data store for caching and real-time operations.

AWS S3 Compatible Storage

Object storage for course materials and user uploads.

Frontend Framework

React 19

Latest React version with modern features and improved performance.

Next.js 15

React framework with server components, app router, and optimized rendering.

Tailwind CSS 4

Utility-first CSS framework for rapid UI development.

Framer Motion

Animation library for creating smooth, interactive UI elements.

React Three Fiber

React renderer for Three.js, enabling 3D visuals like the interactive globe.

AI Integration

Key AI Features

The platform leverages multiple AI technologies to deliver intelligent content generation and learning experiences.

Qwen-QWQ-32B

Course Generation

AI-powered creation of comprehensive course structures based on topic, level, and desired outcomes.

Llama3-70B

Module Content Generation

Automated creation of detailed educational content in multiple formats (text, quizzes, MD).

Llama3-70B

Quiz Generation

Intelligent creation of assessment questions and answers based on course content.

Custom Embeddings

Document Processing

Extraction and embedding of knowledge from uploaded documents for course integration.

Groq API

Content Summarization

Automatic summarization of educational materials for quick review.

PostgreSQL Vector

Vector Search

Semantic similarity search for finding relevant course materials and knowledge.

Innovative Features

Event Orchestration System

A sophisticated event orchestration system for managing complex workflows, like course creation, with parallel processing and dependency management.

Document Knowledge Extraction

Intelligent parsing and semantic understanding of uploaded documents, extracting structured knowledge and embedding it for retrieval.

Interactive 3D Globe Visualization

A beautiful Three.js-powered interactive globe component for visualizing global course distribution and user engagement.

Adaptive Quiz Generation

AI-generated quizzes that adapt to course content and learning objectives, with intelligent question and distractor creation.

Real-time Collaborative Learning

Tools for real-time collaboration, discussions, and peer learning within course modules.

Database Schema

User

User accounts with authentication, profile details, and role-based access.

id, name, email, emailVerified
firstName, lastName, profilePic
password, role (ADMIN, USER)

Course

Educational courses with metadata, settings, and relationship to modules.

id, name, description, outcome
currentLevel, targetAudience
createdAt, updatedAt, published

Module

Course modules of various types (VIDEO, TEXT, QUIZ, MD, CHART).

id, name, description, content
moduleType, order, videoUrl, thumbnailUrl
courseId, createdAt, updatedAt

Quiz & Questions

Assessment components with questions, options, and correct answers.

Quiz: id, title, description, moduleId
Question: id, question, quizId
Option: id, option, correct, questionId

UserCourse

Relationship between users and courses, tracking progress and permissions.

id, userId, courseId
role, progress, completedAt
createdAt, updatedAt

Security Features

Authentication

  • NextAuth v5 integration

  • Password hashing with bcrypt

  • JWT-based session management

  • OAuth providers support

  • Email verification workflow

Authorization

  • Role-based access control

  • Course-level permissions

  • Protected API routes

  • Middleware security checks

  • Session validation

RAG Pipeline & Document Processing

Intelligent Document Processing

The platform features a sophisticated Retrieval-Augmented Generation (RAG) pipeline that processes uploaded documents, extracts knowledge, and uses it to enhance AI-generated content.

Document Processing

Multi-Format Support

PDF Documents

Extracts text content from PDF files using PDFLoader from LangChain.

Word Documents

Processes DOCX/DOC files using Mammoth for content extraction.

Presentations

Extracts content from PowerPoint (PPTX/PPT) files.

Spreadsheets

Parses CSV files with PapaParse for structured data extraction.

Plain Text & Markdown

Direct processing of TXT and MD files for content integration.

Embedding Pipeline

Knowledge Extraction & Embedding

AI Summarization

Documents are summarized using AI to extract key concepts and knowledge.

Vector Embeddings

Summaries are embedded into high-dimensional vectors for semantic retrieval.

PostgreSQL Vector Storage

Embeddings stored in Postgres with vector extension for efficient similarity search.

Parallel Processing

Multiple documents processed simultaneously for efficient course creation.

Error Handling & Retries

Robust retry mechanisms ensure reliable processing of all documents.

RAG Pipeline Workflow

  1. 1
    Document Upload

    Course creators upload documents (PDF, DOCX, etc.) that contain relevant educational content.

  2. 2
    Text Extraction

    The system extracts raw text from documents using format-specific loaders.

  3. 3
    AI Summarization

    AI generates comprehensive summaries capturing key concepts and knowledge from each document.

  4. 4
    Vector Embedding

    Summaries are transformed into vector embeddings using AI embedding models.

  5. 5
    Database Storage

    Embeddings and summaries are stored in PostgreSQL with vector extension for retrieval.

  6. 6
    Content Enrichment

    AI-generated course content is enhanced with knowledge from these documents via similarity search.

  7. 7
    Context Integration

    Module generation, quiz creation, and content suggestions leverage document knowledge.

Similarity Search Applications

  • Course modules pull relevant context from document embeddings

  • Quiz questions are generated based on most similar document sections

  • Video recommendations match most relevant document content

  • AI completions for students are contextually enhanced

Technical Implementation

  • Parallel processing with Promise.all for multiple documents

  • PostgreSQL vector similarity using cosine distance (<=> operator)

  • AI-optimized summary generation with retry mechanisms

  • Automatic cleanup of temporary files after processing

Technical Implementation Details

Event Orchestration System

A custom-built asynchronous workflow engine that manages complex operations with dependencies. The system orchestrates parallel and sequential tasks during course creation and other workflows.

Implementation Highlights

Topological Sorting Algorithm

Uses in-degree tracking to process events in dependency order. Tasks with no dependencies execute first, followed by tasks whose dependencies have completed.

Parallel Task Execution

Tasks at the same dependency level are executed concurrently using Promise.all(), optimizing performance during resource-intensive operations.

Error Resilience

Error handling ensures the system continues execution even when individual tasks fail, tracking error states for later inspection and recovery.

State Preservation

Each event maintains its own result state, allowing downstream tasks to access outputs from previously executed dependencies.

Sample Event Orchestration Graph

// Define the event graph for course creation workflow
adjList.set(authEvent, [validateDataEvent]);
adjList.set(validateDataEvent, [createDbCourseEvent]);
adjList.set(createDbCourseEvent, [
  createUserCourseEvent,  // Executes in parallel
  uploadNotesEvent,       // Executes in parallel
  createAiModulesEvent    // Executes in parallel
]);
adjList.set(createAiModulesEvent, [uploadModulesToDBEvent]);
adjList.set(uploadModulesToDBEvent, [sendNotificationEvent]);

Vector Database Integration

The platform leverages the PostgreSQL vector extension to store and query high-dimensional embeddings for semantic search capabilities without requiring a dedicated vector database.

Technical Details

Embedding Dimensions

Uses 768-dimensional vectors from Google's text-embedding-004 model, optimized for semantic similarity search in educational content.

Vector Storage

Stored as a custom PostgreSQL vector type in the CourseAttachment model, enabling direct database-level vector operations.

Similarity Search

Implements cosine similarity using the PostgreSQL <=> operator for efficient semantic matching between queries and stored embeddings.

Extension Installation

Automatically installs and configures the vector extension during application setup, simplifying deployment and database management.

Vector Similarity Query Example

// Find documents most similar to a query embedding
const result = await prisma.$queryRaw`
  SELECT "name", "url", "summary",
  1 - ("summaryEmbedding" <=> ${embedding}::vector) AS CosineSimilarity
  FROM "CourseAttachment"
  ORDER BY CosineSimilarity DESC
  LIMIT 10
` as { name: string, url: string, summary: string, CosineSimilarity: number }[];

Advanced AI Model Integration

The platform integrates multiple large language models and AI services through a unified API abstraction, enabling specialized models for different content generation tasks.

Streaming Implementation

Real-time content streaming provides immediate feedback to users during generation of long-form educational content.

// Streaming text generation example
const stream = streamText({
  model: groq("llama3-70b-8192"),
  system: `You are an expert educational content creator.`,
  prompt: `Create notes for: ${module.name}`,
  temperature: 0.7,
  maxTokens: 6000,
});

// Returns a streaming response
return stream.toDataStreamResponse();

Structured Output Generation

Uses JSON schema validation to ensure AI outputs match expected data structures for quizzes, course modules, and other structured content.

// Structured object generation with validation
const { object: quizData } = await generateObject({
  model: groq("llama3-70b-8192"),
  schema: QuizSchema, // Zod schema for validation
  system: `Create a comprehensive quiz`,
  prompt: `Create quiz for: ${module.name}`,
  temperature: 0.2,
  maxTokens: 4000,
});

AI Model Selection Strategy

Task Type
Model
Technical Rationale
Course Structure
Qwen-QWQ-32B
Superior knowledge organization and structured output capabilities with 32B parameters
Content Generation
Llama3-70B
Optimal markdown generation, code examples, and educational explanations with 70B parameters
Quiz Creation
Llama3-70B
Advanced reasoning for distractor generation and precise question formulation
Embeddings
Google-E004
768-dimensional vectors optimized for semantic similarity with high information density
Summarization
Groq API
Low-latency processing of document content with high compression ratio while maintaining key concepts

Resilience & Error Handling

The platform implements robust error handling and recovery mechanisms to ensure reliability during complex operations involving external AI services and file processing.

Exponential Backoff Retry

AI service calls implement exponential backoff with configurable retry limits to handle transient failures and rate limiting from external APIs.

// Retry with exponential backoff
while (attempts < maxAttempts) {
  try {
    return await aiServiceCall();
  } catch (error) {
    attempts++;
    
    if (attempts < maxAttempts) {
      const delayMs = Math.pow(2, attempts) * 1000;
      await new Promise(resolve => 
        setTimeout(resolve, delayMs)
      );
    }
  }
}
Resource Cleanup

Temporary file handling with guaranteed cleanup through finally blocks and delete hooks, preventing resource leaks during document processing.

// Resource cleanup pattern
const deleteFile = async () => {
  try {
    await rm(filePath);
    console.log(`Deleted ${filePath}`);
  } catch (error) {
    console.error(`Error deleting ${filePath}`);
  }
};

try {
  // Process file...
} finally {
  // Always execute cleanup
  await deleteFile();
}

Fault Tolerance Strategies

  • Graceful degradation when AI services are unavailable or return unexpected results

  • Parameter validation using Zod schemas before expensive operations

  • Content length truncation to prevent token limit errors in AI models

  • Transactional database operations to maintain data consistency

Deployment & Performance

Optimization Strategies

The platform employs multiple strategies to ensure optimal performance and user experience.

Server Components

Leverages Next.js server components for improved initial load performance.

Edge Caching

Content delivery network integration for global low-latency access.

API Optimization

Batched and parallel API requests for efficient data fetching.

Image Optimization

Automatic image resizing, format conversion, and lazy loading.

Code Splitting

Dynamic imports and component lazy loading to reduce bundle size.

Streaming Responses

AI content is streamed to improve perceived performance.

Built with using Next.js, React, and Tailwind CSS