I'll design a lean, on-premise system architecture for your fraud detection system. Here's a comprehensive yet simple design:
System Architecture Overview
The system follows a modular architecture with clear separation of concerns:
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Web Frontend │────▶│ API Gateway │────▶│ Core Services │
│ (Dashboard) │ │ (FastAPI) │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
┌──────────────────────────┴───────────────────────┐
│ │
┌───────▼────────┐ ┌──────────────┐ ┌─────────────────┐
│ Crawler Service│ │ ML Service │ │ Labeling Service│
└────────────────┘ └──────────────┘ └─────────────────┘
│ │ │
└───────────────────┴────────────────────┘
│
┌─────────▼──────────┐
│ PostgreSQL DB │
└────────────────────┘
┌────────────────────┐
│ File Storage │
│ (Local Disk) │
└────────────────────┘
Component Details
1. Database Schema (PostgreSQL)
-- Videos table
videos (
id SERIAL PRIMARY KEY,
url VARCHAR(500) UNIQUE NOT NULL,
platform VARCHAR(50),
created_at TIMESTAMP DEFAULT NOW()
)
-- Commenters table
commenters (
id SERIAL PRIMARY KEY,
platform_id VARCHAR(255) UNIQUE NOT NULL,
username VARCHAR(255),
profile_data JSONB,
profile_image_path VARCHAR(500),
created_at TIMESTAMP DEFAULT NOW()
)
-- Comments table
comments (
id SERIAL PRIMARY KEY,
video_id INTEGER REFERENCES videos(id),
commenter_id INTEGER REFERENCES commenters(id),
comment_text TEXT,
comment_data JSONB,
created_at TIMESTAMP DEFAULT NOW()
)
-- Labels table
labels (
id SERIAL PRIMARY KEY,
commenter_id INTEGER REFERENCES commenters(id),
fraud_type VARCHAR(50), -- 'financial', 'dating', 'misc', 'none'
labeled_by VARCHAR(100),
labeled_at TIMESTAMP DEFAULT NOW(),
UNIQUE(commenter_id)
)
-- Predictions table
predictions (
id SERIAL PRIMARY KEY,
commenter_id INTEGER REFERENCES commenters(id),
fraud_probability FLOAT,
fraud_type VARCHAR(50),
model_version VARCHAR(50),
predicted_at TIMESTAMP DEFAULT NOW()
)
2. Crawler Service
A Python service using:
- Scrapy or requests for API crawling
- Celery for async task processing
- Redis as message broker
Key functions:
# crawler/tasks.py
@celery.task
def crawl_video_comments(video_url):
# Extract platform and video ID
# Call appropriate API
# Store comments and queue commenter crawls
@celery.task
def crawl_commenter_profile(commenter_id):
# Fetch profile data
# Download profile image
# Store in DB and disk
3. ML Service
A Python service using:
- scikit-learn or PyTorch for the model
- Pillow for image processing
- NLTK/spaCy for text processing
Key components:
# ml/model.py
class FraudDetector:
def extract_features(self, image_path, comments):
# Image features (face detection, quality metrics)
# Text features (sentiment, keywords, patterns)
def train(self, labeled_data):
# Train ensemble model
def predict(self, commenter_id):
# Return fraud probability and type
4. API Gateway (FastAPI)
# api/main.py
@app.post("/videos")
async def add_video(url: str):
# Queue crawling task
@app.post("/labels")
async def label_commenter(commenter_id: int, fraud_type: str):
# Store manual label
@app.get("/dashboard/stats")
async def get_dashboard_stats():
# Return fraud statistics
5. Web Frontend
Simple React or Vue.js dashboard with:
- Video URL input form
- Commenter list with labeling interface
- Fraud statistics visualization
- Fraudster profiles viewer
6. File Storage Structure
/data/
├── images/
│ ├── profiles/
│ │ ├── {year}/{month}/{day}/{commenter_id}.jpg
├── models/
│ ├── fraud_detector_v1.pkl
│ ├── fraud_detector_v2.pkl
├── logs/
Deployment Architecture
Docker Compose Setup
version: '3.8'
services:
postgres:
image: postgres:15
volumes:
- ./postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: fraud_detection
redis:
image: redis:7
api:
build: ./api
ports:
- "8000:8000"
depends_on:
- postgres
- redis
crawler:
build: ./crawler
depends_on:
- postgres
- redis
volumes:
- ./data:/data
ml_service:
build: ./ml
depends_on:
- postgres
volumes:
- ./data:/data
frontend:
build: ./frontend
ports:
- "3000:3000"
Key Design Decisions
- PostgreSQL with JSONB: Flexible schema for varying API responses while maintaining relational integrity
- Celery + Redis: Reliable async processing for crawling tasks
- Local file storage: Simple and sufficient for profile images
- FastAPI: Modern, fast API framework with automatic documentation
- Modular services: Easy to scale individual components if needed
Workflow
- User submits video URLs via dashboard
- Crawler service fetches comments asynchronously
- For each unique commenter, profile and image are crawled
- Users manually label fraudsters through the dashboard
- ML service trains periodically on labeled data
- New comments/commenters are automatically scored
- Dashboard displays fraud statistics and high-risk profiles
This architecture is lean, uses only open-source components, and can run entirely on a single server or be distributed across multiple machines as needed.