Skip to main content

Overview

The Learning Roadmap endpoints use Groq AI to generate comprehensive, structured learning paths. There are two types:
  1. Personal Roadmap: Analyzes a student’s enrolled courses and progress to create a personalized learning journey
  2. Custom Roadmap: Generates a learning path for any topic on demand
Both endpoints leverage the same AI service with structured JSON output for consistent, actionable guidance.

POST /api/user/generate-personal-roadmap

Generate a personalized learning roadmap based on the authenticated user’s enrolled courses and progress.

Authentication

Requires JWT authentication token in the Authorization header.

Request Body

No request body required. The endpoint automatically analyzes the authenticated user’s data.

Response

boolean
Indicates whether the roadmap was successfully generated.
object
The personalized learning roadmap.
array
Detailed statistics for each enrolled course.

Response Example

Error Responses


POST /api/user/generate-custom-roadmap

Generate a learning roadmap for any topic specified by the user.

Authentication

Requires JWT authentication token in the Authorization header.

Request Body

string
required
The learning topic to generate a roadmap for. Must be 2-120 characters. Special characters and extra whitespace are sanitized.

Request Example

Response

boolean
Indicates whether the roadmap was successfully generated.
object
The custom learning roadmap.

Response Example

Error Responses


How It Works

Groq AI Integration

Both endpoints use the same AI service with the following configuration:
  • Model: openai/gpt-oss-120b - A 120B parameter open-source model
  • Temperature: 0.7 - Balanced between creativity and consistency
  • Max Tokens: 5000 - Supports comprehensive roadmaps
  • Top P: 1.0 - Full probability mass for response generation
  • Streaming: Disabled - Returns complete JSON responses

JSON Parsing

The system uses a multi-strategy JSON parser to handle various AI response formats:
  1. Direct JSON: Attempts standard JSON parsing
  2. Markdown Code Blocks: Extracts JSON from ```json fences
  3. Pattern Matching: Finds JSON objects using regex
This ensures robust parsing even if the AI response includes extra formatting.

Response Validation

All AI-generated roadmaps are validated using Zod schemas:
Invalid responses trigger an error, prompting the user to try again.

Personal Roadmap Data Sources

The personal roadmap endpoint aggregates data from:
  • User model: Enrolled courses with populated course details
  • CourseProgress model: Lecture completion tracking
  • Course model: Course structure (chapters, lectures, descriptions)
HTML tags are stripped from course descriptions and truncated to 250 characters.

Input Sanitization (Custom Roadmap)

The topic input is sanitized by:
  1. Trimming whitespace
  2. Removing newlines, backticks, quotes, and backslashes
  3. Collapsing multiple spaces into single spaces
  4. Validating length (2-120 characters)
This prevents prompt injection and ensures clean AI input.

Best Practices

Personal Roadmap

  1. Enroll in Courses: Students must have at least one enrolled course
  2. Complete Quizzes: Quiz data enhances personalization (though not directly used in roadmaps)
  3. Regular Progress: Update course progress to keep roadmaps relevant

Custom Roadmap

  1. Specific Topics: Use clear, specific topics like “React Hooks” rather than vague terms like “coding”
  2. Technology Focus: Works best for technical skills, frameworks, and tools
  3. Length: Keep topics concise (under 50 characters is ideal)

Error Handling

  • Always check the success field before using roadmap data
  • Implement retry logic for failed AI generations
  • Provide fallback UI when roadmaps can’t be generated

Performance Considerations

  • Personal roadmap generation requires multiple database queries (courses, progress)
  • AI generation typically takes 2-5 seconds depending on Groq API response time
  • Consider implementing caching for personal roadmaps with a TTL based on user activity
  • Custom roadmaps can be cached more aggressively by topic