The bot detection system is a comprehensive multi-layered approach to identify automated user behavior and suspicious activity patterns on the confession platform. It uses advanced algorithms to analyze user behavior and maintain platform integrity.
-
BotDetectionService (
src/lib/bot-detection.ts)- Main service class with singleton pattern
- Comprehensive bot detection algorithms
- Risk level classification
- Statistical analysis
-
Database Integration (
src/lib/db-utils.ts)- Enhanced reputation calculation with bot penalties
- Real-time activity monitoring
- Bot probability updates
- Historical tracking
-
Admin Dashboard (
src/components/BotDetectionPanel.tsx)- Real-time bot detection statistics
- Risk level visualization
- Detection method explanations
- User management interface
- Excessive Activity Detection: Monitors daily action counts (>50 actions = high risk)
- Activity Burst Analysis: Identifies unnatural activity spikes
- Consistent Pattern Recognition: Detects unnaturally regular behavior patterns
- Repetitive Content Detection: Analyzes content similarity (>70% similarity = high risk)
- Generic/Bot-like Content: Identifies templated or automated content
- Content Length Analysis: Detects suspicious length patterns
- Regular Interval Detection: Identifies automated posting schedules
- 24/7 Activity Monitoring: Detects continuous activity patterns
- Timezone Inconsistency Checks: Identifies multi-timezone bot networks
- Low Engagement Despite High Activity: Detects bots that post but don't interact
- One-sided Interaction Detection: Identifies bots that only post or only vote
- Social Graph Analysis: Analyzes user interaction patterns
- Multiple Account Detection: Identifies accounts from same source
- Device Fingerprinting: Tracks device patterns (future implementation)
- IP Address Analysis: Monitors IP-based patterns
- Isolation Score: Measures social connection patterns
- Artificial Social Patterns: Detects fake social interactions
- Network Analysis: Identifies bot networks
| Level | Probability | Action Required | Description |
|---|---|---|---|
| CRITICAL | 80%+ | Immediate suspension | High confidence bot detection |
| HIGH | 60-79% | Enhanced monitoring | Strong bot indicators |
| MEDIUM | 30-59% | Regular monitoring | Moderate suspicion |
| LOW | 0-29% | Normal monitoring | Normal activity patterns |
Total Score = Activity Score + Content Score + Timing Score +
Engagement Score + Device Score + Social Score
Bot Probability = (Total Score / Max Score) * 100
model User {
// Bot detection fields
botProbability Int @default(0) // 0-100, higher = more likely bot
isFlagged Boolean @default(false)
verificationLevel String @default("NEW_USER")
// Activity tracking
dailyConfessions Int @default(0)
dailyVotes Int @default(0)
dailyComments Int @default(0)
confessionsCreated Int @default(0)
votesCast Int @default(0)
commentsCreated Int @default(0)
}
model ReputationHistory {
// Enhanced tracking
botProbability Int?
botIndicators String[] // Array of bot detection indicators
riskLevel String? // LOW, MEDIUM, HIGH, CRITICAL
}-
GET /api/admin/bot-detection/stats
- Returns bot detection statistics
- Total users, suspicious users, critical users, average probability
-
GET /api/admin/bot-detection/[userId]
- Returns detailed bot detection info for specific user
- Probability, indicators, risk level, recommendations
-
User Activity Monitoring
// Called on every user action await monitorUserActivity(userId, 'confession' | 'vote' | 'comment');
-
Reputation Calculation
// Bot penalty applied to reputation const botPenalty = botProbability > 50 ? (botProbability - 50) * 0.5 : 0; const reputationScore = activityScore + qualityScore + trustScore - botPenalty;
-
Real-time Flagging
// Automatic flagging for critical risk if (botDetectionResult.riskLevel === 'CRITICAL') { await flagUser(userId); }
- Bot Detection Rate: Percentage of users flagged as suspicious
- Critical Risk Users: Number of users with 80%+ bot probability
- Average Bot Probability: Mean bot probability across all users
- Detection Accuracy: False positive/negative rates
- Real-time Statistics: Live updates of bot detection metrics
- Risk Level Visualization: Color-coded risk indicators
- Detection Method Breakdown: Explanation of detection algorithms
- User Management: Flag/unflag users with detailed reasoning
const DETECTION_THRESHOLDS = {
EXCESSIVE_ACTIVITY: 50, // Daily actions
HIGH_ACTIVITY: 30, // Daily actions
REPETITIVE_CONTENT: 0.7, // Similarity threshold
GENERIC_CONTENT: 0.6, // Generic content threshold
REGULAR_INTERVALS: 0.8, // Timing regularity
CONTINUOUS_ACTIVITY: true, // 24/7 activity flag
LOW_ENGAGEMENT_RATIO: 0.1, // Engagement threshold
ONE_SIDED_INTERACTIONS: 0.8, // Interaction pattern threshold
};const RISK_THRESHOLDS = {
CRITICAL: 80, // 80%+ bot probability
HIGH: 60, // 60-79% bot probability
MEDIUM: 30, // 30-59% bot probability
LOW: 0, // 0-29% bot probability
};import { botDetectionService } from '@/lib/bot-detection';
// Detect bot for a user
const result = await botDetectionService.detectBot(userId);
console.log(`Bot probability: ${result.probability}%`);
console.log(`Risk level: ${result.riskLevel}`);
console.log(`Indicators: ${result.indicators.join(', ')}`);import { BotDetectionPanel } from '@/components/BotDetectionPanel';
// Add to admin page
<BotDetectionPanel />// Monitor user activity
await monitorUserActivity(userId, 'confession');
// Get bot detection stats
const stats = await getBotDetectionStats();
console.log(`Critical users: ${stats.criticalUsers}`);- Bot detection data is stored securely
- Personal information is not exposed in bot analysis
- Detection algorithms focus on behavior patterns, not personal data
- Multiple detection methods reduce false positives
- Manual review process for flagged users
- Appeal system for incorrectly flagged accounts
- Efficient database queries for large user bases
- Caching of detection results
- Asynchronous processing for real-time monitoring
- Machine Learning Integration: Advanced ML models for pattern recognition
- Behavioral Biometrics: Mouse movement and typing pattern analysis
- Network Analysis: Detection of coordinated bot networks
- Real-time Alerts: Instant notifications for critical detections
- Automated Actions: Automatic suspension for confirmed bots
- Natural Language Processing: Content sentiment and style analysis
- Image Analysis: Profile picture and content image analysis
- Geographic Analysis: Location-based pattern detection
- Temporal Analysis: Time-based behavior pattern recognition
- Reduced Spam: Automated detection prevents spam content
- Quality Control: Maintains high-quality user interactions
- Trust Building: Creates a safer environment for users
- Resource Protection: Prevents abuse of platform resources
- Cleaner Feed: Less spam and automated content
- Better Engagement: Higher quality interactions
- Fair Competition: Prevents bot-driven unfair advantages
- Community Health: Maintains authentic community interactions
- Automated Monitoring: Reduces manual review workload
- Detailed Analytics: Comprehensive bot detection statistics
- Proactive Management: Early detection of suspicious activity
- Scalable Solution: Handles large user bases efficiently
- Monitor detection accuracy rates
- Adjust thresholds based on false positive/negative rates
- Update detection algorithms based on new bot patterns
- Review and refine risk classification system
- Track detection processing times
- Monitor database query performance
- Optimize algorithms for large-scale deployment
- Scale infrastructure as user base grows
This bot detection system provides comprehensive protection against automated abuse while maintaining user privacy and platform performance.