Overview
The tag analysis system in IntelliQ automatically processes quiz content to generate relevant tags and categories, maintaining user statistics for both user-provided and AI-generated tags. This system works asynchronously using QStash to ensure smooth quiz submission experience.Flow Diagram
Data Structure
The system maintains two levels of tag data:- Quiz Level (in
quizzes
table):
- User Level (in
userAnalysis
table):
-
Quiz Submission
When a user completes a quiz (singleplayer or multiplayer), the system:
The submission triggers a QStash job for tag analysis.
-
Tag Analysis (Async)
The analysis job:
- Generates tags and categories using AI
- Updates the quiz record
- Updates user statistics
- Invalidates relevant caches
-
Retrieve User Analysis
Returns the user’s tag statistics and preferences.
-
Get Top Categories
Returns the user’s most frequent quiz categories.
Response Examples
Technical Implementation
-
QStash Integration
- Uses
@upstash/qstash
for reliable async processing - Configurable delay to batch process tags
- Automatic retries on failure
- Uses
-
Cache Management
- User cache version incremented after analysis
- Ensures frontend receives updated statistics
-
Database Schema
Error Handling
The system handles various error cases:- Failed AI tag generation
- Database transaction failures
- Invalid quiz references
- Rate limiting
- Cache invalidation issues
Security Considerations
- Tag analysis endpoint protected by admin token
- User analysis data access restricted to owner
- Rate limiting on analysis requests
- Sanitization of AI-generated tags
- Validation of user-provided tags
Benefits
-
Asynchronous Processing
- No delay in quiz submission
- Better user experience
- Reduced server load
-
Rich Metadata
- Improved quiz discovery
- Better content organization
- Personalized recommendations
-
User Insights
- Track user interests
- Identify popular categories
- Guide content creation