Overview
The Learning Roadmap endpoints use Groq AI to generate comprehensive, structured learning paths. There are two types:- Personal Roadmap: Analyzes a student’s enrolled courses and progress to create a personalized learning journey
- Custom Roadmap: Generates a learning path for any topic on demand
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
Indicates whether the roadmap was successfully generated.
The personalized learning roadmap.
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
The learning topic to generate a roadmap for. Must be 2-120 characters. Special characters and extra whitespace are sanitized.
Request Example
Response
Indicates whether the roadmap was successfully generated.
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:- Direct JSON: Attempts standard JSON parsing
- Markdown Code Blocks: Extracts JSON from ```json fences
- Pattern Matching: Finds JSON objects using regex
Response Validation
All AI-generated roadmaps are validated using Zod schemas:Personal Roadmap Data Sources
The personal roadmap endpoint aggregates data from:Usermodel: Enrolled courses with populated course detailsCourseProgressmodel: Lecture completion trackingCoursemodel: Course structure (chapters, lectures, descriptions)
Input Sanitization (Custom Roadmap)
The topic input is sanitized by:- Trimming whitespace
- Removing newlines, backticks, quotes, and backslashes
- Collapsing multiple spaces into single spaces
- Validating length (2-120 characters)
Best Practices
Personal Roadmap
- Enroll in Courses: Students must have at least one enrolled course
- Complete Quizzes: Quiz data enhances personalization (though not directly used in roadmaps)
- Regular Progress: Update course progress to keep roadmaps relevant
Custom Roadmap
- Specific Topics: Use clear, specific topics like “React Hooks” rather than vague terms like “coding”
- Technology Focus: Works best for technical skills, frameworks, and tools
- Length: Keep topics concise (under 50 characters is ideal)
Error Handling
- Always check the
successfield 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
Related Endpoints
- AI Chatbot - Conversational AI assistant
- Chat Sessions - Manage AI conversations