A production-grade Next.js application that connects to Meta Graph API to fetch social media comments, perform sentiment analysis, and provide comprehensive data exploration with CSV export functionality.
- Multi-Platform Integration: Connect Facebook Pages and Instagram Business accounts
- Real-time Sentiment Analysis: AI-powered sentiment detection (positive, negative, neutral)
- Toxicity Detection: Identify harmful or toxic content in comments
- Keyword Extraction: Automatically extract key topics and themes
- Multi-language Support: Analyze comments in multiple languages
- Interactive Dashboards: Beautiful charts and graphs using Recharts
- Sentiment Trends: Track sentiment changes over time
- Engagement Analytics: Analyze likes, comments, and engagement patterns
- Page Comparison: Compare performance across different pages
- Toxicity Monitoring: Track and visualize toxicity levels
- Advanced Filtering: Filter by platform, sentiment, date range, and more
- Export Capabilities: Export data in CSV, JSON, and Excel formats
- Customizable Fields: Choose which data fields to include in exports
- Historical Data: Maintain complete history of all analyzed content
- Background Job Processing: Efficient queue system for data fetching and analysis
- Rate Limit Handling: Automatic handling of API rate limits
- Token Management: Secure encryption and refresh of access tokens
- Scalable Architecture: Built for high-volume data processing
- Frontend: Next.js 14, React, TypeScript, Tailwind CSS
- UI Components: shadcn/ui, Lucide Icons, Recharts
- Backend: Next.js API Routes, Prisma ORM
- Database: PostgreSQL
- Authentication: NextAuth.js with Facebook OAuth
- Job Queue: Database-backed job processing system
- AI/ML: Local sentiment analysis with optional OpenAI integration
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β API Routes β β Database β
β Dashboard βββββΊβ Job Queue βββββΊβ PostgreSQL β
β Components β β Auth System β β Prisma ORM β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Meta Graph β β Sentiment β β Background β
β API Client β β Analysis β β Workers β
β Token Mgmt β β Engine β β Job Processor β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Node.js 18+ and npm
- PostgreSQL database
- Facebook Developer Account
-
Clone the repository:
git clone <repository-url> cd social-sentiment-app
-
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Set up the database:
npx prisma migrate dev npx prisma generate
-
Start the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:3000
Create a .env file with the following variables:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/social_sentiment"
# NextAuth.js
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here"
# Facebook App
FACEBOOK_APP_ID="your-facebook-app-id"
FACEBOOK_APP_SECRET="your-facebook-app-secret"
# Encryption (32 characters)
ENCRYPTION_KEY="your-32-character-encryption-key"
# Optional: OpenAI for enhanced analysis
OPENAI_API_KEY="your-openai-api-key"- Create a Facebook App at developers.facebook.com
- Add Facebook Login product
- Configure OAuth redirect URIs:
- Development:
http://localhost:3000/api/auth/callback/facebook - Production:
https://yourdomain.com/api/auth/callback/facebook
- Development:
- Request the following permissions:
pages_show_listpages_read_engagementpages_read_user_contentinstagram_basicinstagram_manage_comments
- Sign in with your Facebook account
- Navigate to the Pages section
- Click "Connect Pages" to authorize access
- Select which pages to analyze
- Automatic Fetching: Comments are fetched automatically from connected pages
- Manual Trigger: Use the "Fetch Recent Data" button for immediate updates
- Background Processing: Analysis runs in the background via job queue
- Dashboard: Overview of all your data and recent activity
- Explorer: Search and filter individual comments
- Insights: Detailed analytics with charts and visualizations
- Export: Download data in various formats
- Navigate to the Export section
- Configure export settings (format, date range, fields)
- Apply filters to narrow down data
- Download your customized export
All API endpoints require authentication via NextAuth.js session.
GET /api/dashboard/statsReturns overview statistics for the authenticated user.
GET /api/pages
POST /api/pages
PATCH /api/pages/[id]
DELETE /api/pages/[id]GET /api/comments?page=1&limit=20&sentiment=POSITIVE
GET /api/insights?timeRange=30d&pageId=123GET /api/export?format=csv&dataType=comments&dateFrom=2024-01-01POST /api/fetch
GET /api/jobs/status# Unit tests
npm test
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2enpm run test:coverageSee DEPLOYMENT.md for comprehensive deployment instructions.
npm run build
npx verceldocker-compose up -d- Encryption: All access tokens are encrypted at rest
- HTTPS: All production traffic uses HTTPS
- Authentication: Secure OAuth flow with Facebook
- Rate Limiting: API rate limiting to prevent abuse
- GDPR Ready: Built with privacy regulations in mind
- Data Retention: Configurable data retention policies
- User Control: Users can delete their data at any time
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Use Prettier for code formatting
- Write tests for new features
- Update documentation as needed
- Database Indexing: Optimized queries with proper indexes
- Caching: Redis caching for frequently accessed data
- Background Processing: Non-blocking job queue system
- Pagination: Efficient data loading with pagination
- Code Splitting: Optimized bundle sizes with Next.js
- Health Checks: Built-in health monitoring endpoints
- Error Tracking: Comprehensive error logging
- Performance Metrics: Database and API performance tracking
# Check database status
sudo systemctl status postgresql
# Test connection
psql -h localhost -U username -d social_sentiment- Verify app permissions in Facebook Developer Console
- Check token expiration dates
- Validate redirect URIs match exactly
# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install
# Regenerate Prisma client
npx prisma generateThis project is licensed under the MIT License - see the LICENSE file for details.
- Meta Graph API for social media data access
- OpenAI for advanced sentiment analysis capabilities
- Vercel for hosting and deployment platform
- shadcn/ui for beautiful UI components
- Prisma for database management
- NextAuth.js for authentication
- Documentation: Check the docs folder for detailed guides
- Issues: Report bugs via GitHub Issues
- Discussions: Join community discussions
- Email: Contact support at support@socialment.com
Built with β€οΈ by the Social Sentiment Team