An intelligent movie review moderation system built with Motia framework that analyzes sentiment, moderates content, and generates personalized movie recommendations.
- π€ AI-Powered Moderation - Automatically analyzes review sentiment and filters inappropriate content
- π― Genre-Aware Recommendations - Intelligently recommends movies based on the same genre as the reviewed movie
- π Real-time Analytics - Tracks review sentiment scores and approval rates with detailed genre information
- π Event-Driven Architecture - Uses Motia's event system for seamless data flow
- π Advanced TMDB Integration - Fetches rich movie data, genre information, and targeted recommendations
- π Multi-Strategy Recommendations - 4-tier fallback system ensuring quality recommendations
- π§ͺ Comprehensive Testing - Includes automated test suite for genre-based recommendations
This system implements a genre-aware movie-moderation flow with four intelligent components:
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ
β ModerateReview βββββΆβ AnalyzeSentiment βββββΆβ Genre-Aware Recom- βββββΆβNotifyRecommendationsβ
β (API) β β (Event) β β mendations (Event) β β (Event) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
Receives POST Analyzes text π¬ Identifies movie Prepares notifications
requests with sentiment and genre and finds with genre-matched
movie reviews moderates content same-genre movies recommendationsπ₯ Horror Movie β Recommends other horror films
π Action Movie β Recommends other action films
π Comedy Movie β Recommends other comedies
π Sci-Fi Movie β Recommends other sci-fi films
- Node.js 18+
- npm or yarn
- TMDB API Key (free from themoviedb.org)
-
Clone the repository
git clone <your-repo-url> cd motioa-demo
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envand add your TMDB API key:TMDB_API_KEY=your_tmdb_api_key_here PORT=3000 NODE_ENV=development
-
Start the development server
npm run dev
-
Start testing the API The system is now ready! You can test it using:
- The automated test script (recommended)
- Direct API calls
- Motia Workbench at http://localhost:3000
Endpoint: POST /api/moderate-review
Request Body:
{
"movieId": "1038392",
"reviewText": "This movie was absolutely amazing! Great acting and plot.",
"userId": "user123"
}Response:
{
"status": "success",
"data": {
"isApproved": true,
"moderationReason": "Your review is being processed"
}
}# Development
npm run dev # Start development server with hot reload
npm run generate-types # Generate TypeScript types from Motia config
# Production
npm run build # Build the project for production
npm start # Start production server
# Utilities
npm run clean # Clean build artifacts and dependenciesβββ steps/ # Motia step definitions
β βββ moderate-review.step.ts # API endpoint for review submission
β βββ analyze-sentiment.step.ts # Sentiment analysis and moderation
β βββ generate-recommendations.step.ts # Genre-aware TMDB recommendations
β βββ notify-recommendations.step.ts # Enhanced notification handler
βββ services/ # External service integrations
β βββ tmdb.service.ts # Enhanced TMDB API client with genre support
β βββ types.ts # Shared type definitions
βββ test-genre-recommendations.js # Automated test suite for genre-based recommendations
βββ .env # Environment variables (create from .env.example)
βββ motia-workbench.json # Motia workbench configuration
βββ types.d.ts # Generated TypeScript types- Type: API Route Handler
- Method: POST
- Path:
/api/moderate-review - Purpose: Receives movie review submissions and validates input
- Emits:
review-moderatedevent
- Type: Event Handler
- Subscribes to:
review-moderated - Purpose: Analyzes review sentiment and filters inappropriate content
- Features:
- Simple keyword-based sentiment analysis
- Inappropriate content filtering
- Caching for performance optimization
- Emits:
review-analyzedevent
- Subscribes to:
review-analyzed - Purpose: Intelligently generates genre-based movie recommendations
- Features:
- π Genre Detection: Identifies movie genres from TMDB
- π₯ Smart Matching: Recommends movies from the same genre
- π 4-Tier Fallback System:
- Primary genre movies (same main genre)
- Multi-genre movies (multiple matching genres)
- TMDB recommendations (original algorithm)
- Popular movies (high-rated fallback)
- π Quality Scoring: Sorts by vote average and popularity
- Emits:
recommendations-generatedevent with genre information
- Type: Event Handler
- Subscribes to:
recommendations-generated - Purpose: Prepares notification data for users
- Features:
- Structured notification data
- Ready for email/push notification services
- Comprehensive logging
The system uses a simple but effective sentiment analysis algorithm:
Inappropriate Content Filters:
hate,terrible,awful,boring,worst- Reviews containing these words are automatically rejected
Positive Keywords:
great,amazing,love,excellent,best(+0.1 each)
Negative Keywords:
bad,poor,disappointing,waste(-0.1 each)
Approval Threshold: Score > 0.3
The system uses an intelligent 4-tier recommendation strategy:
- Identifies the main genre of the reviewed movie
- Fetches highest-rated movies from the same genre
- Filters out the original movie
- Prioritizes movies with 100+ votes for quality
- For movies with multiple genres (e.g., Action-Comedy)
- Finds movies that share multiple genres
- Broader selection while maintaining relevance
- Falls back to TMDB's native recommendation engine
- Uses collaborative filtering and user behavior data
- Provides diversity when genre-specific movies are limited
- Final fallback to ensure recommendations are always provided
- High-rated, popular movies across all genres
- Filtered to exclude the reviewed movie
- All recommendations sorted by vote average
- Limited to top 5 recommendations
- Includes recommendation strategy metadata
The system integrates with The Movie Database (TMDB) API to:
- Fetch detailed movie information
- Get movie-specific recommendations
- Retrieve popular movies as fallback
- Search for movies by query
Rate Limits: TMDB API allows 40 requests every 10 seconds
# Build the image
docker build -t movie-moderation .
# Run the container
docker run -p 3000:3000 -e TMDB_API_KEY=your_key movie-moderation-
Build the project:
npm run build
-
Set production environment variables
-
Start the production server:
npm start
- Open http://localhost:3000
- Select the "movie-moderation" flow
- Use the visual interface to:
- Test individual steps
- Monitor event flow
- View execution logs
- Debug issues in real-time
- INFO: General flow information
- DEBUG: Detailed execution data
- WARN: Non-critical issues
- ERROR: Critical failures
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- β Genre-based recommendations - Completed! Now recommends movies by genre
- β Comprehensive test suite - Completed! Automated testing script available
- β Enhanced TMDB integration - Completed! Advanced genre detection and discovery
- Add machine learning-based sentiment analysis
- Implement user preference learning
- Add email notification service integration
- Create admin dashboard for moderation oversight
- Add Redis for distributed caching
- Implement rate limiting
- Docker containerization
- CI/CD pipeline setup
- Fix Motia Workbench UI issues
- Add genre-specific sentiment analysis (e.g., horror-specific keywords)
Issue: ERR_HTTP_INVALID_STATUS_CODE
Solution: Ensure all handlers return proper response objects with status and body properties.
Issue: [INVALID EMIT] errors
Solution: Make sure emit calls use the format: emit({ topic: 'event-name', data: {...} })
Issue: TMDB API failures
Solution: Check your API key in .env and verify network connectivity.
Issue: No genre-based recommendations
Solution: Ensure the movie ID exists in TMDB and has genre information. Check the logs for genre detection messages.
- Motia Framework - For the excellent workflow framework
- The Movie Database (TMDB) - For movie data and recommendations
- Axios - For HTTP client functionality
- Zod - For schema validation