Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Real-Time Fake Job Detector

A production-grade streaming data pipeline that detects fraudulent job postings in real time.

Python Apache Kafka Apache Spark FastAPI Next.js PostgreSQL Docker License: MIT

Features β€’ Architecture β€’ Quick Start β€’ ML Model β€’ API Docs β€’ Contributing


πŸ“Œ Overview

Job boards are flooded with fraudulent postings designed to steal personal data or money. This system automatically flags fake jobs the moment they are posted β€” no manual review required.

Every job posting flows through a Kafka queue β†’ Spark ML pipeline β†’ PostgreSQL β†’ FastAPI β†’ live Next.js dashboard. Fraud decisions happen in under 5 seconds with 100% precision (zero false alarms).


✨ Features

Feature Description
⚑ Real-time streaming Kafka β†’ Spark micro-batches every 5 seconds
πŸ€– ML inference at scale TF-IDF + Random Forest UDF runs across Spark workers
πŸ“ˆ Anomaly detection EMA-based spike detection flags unusual fraud surges
πŸ”— Fraud clustering Cosine similarity groups related fake jobs (β‰₯ 0.8 threshold)
✏️ Human corrections Manual override system with full correction audit trail
πŸ“‘ Live dashboard WebSocket-powered Next.js frontend with real-time charts
πŸͺ¦ Dead letter queue Failed events captured for manual investigation
🐳 One-command deploy Full Docker Compose stack β€” 7 services, one command

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     DATA FLOW                                    β”‚
β”‚                                                                   β”‚
β”‚  CSV Dataset                                                      β”‚
β”‚      β”‚                                                            β”‚
β”‚      β–Ό                                                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”‚
β”‚  β”‚ Kafka        │────►│  Kafka Topic     β”‚                       β”‚
β”‚  β”‚ Producer     β”‚     β”‚  (jobs)          β”‚                       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β”‚                                β”‚                                  β”‚
β”‚                                β–Ό                                  β”‚
β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚                  β”‚  Spark Structured       β”‚                     β”‚
β”‚                  β”‚  Streaming              β”‚                     β”‚
β”‚                  β”‚  β”œβ”€ TF-IDF + RF model   β”‚                     β”‚
β”‚                  β”‚  β”œβ”€ Anomaly detection   β”‚                     β”‚
β”‚                  β”‚  └─ Fraud clustering    β”‚                     β”‚
β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                               β”‚                                   β”‚
β”‚                               β–Ό                                   β”‚
β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚                  β”‚     PostgreSQL           β”‚                     β”‚
β”‚                  β”‚  β”œβ”€ job_predictions      β”‚                     β”‚
β”‚                  β”‚  β”œβ”€ job_clusters         β”‚                     β”‚
β”‚                  β”‚  β”œβ”€ job_corrections      β”‚                     β”‚
β”‚                  β”‚  └─ pipeline_metrics     β”‚                     β”‚
β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                               β”‚                                   β”‚
β”‚                               β–Ό                                   β”‚
β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚                  β”‚  FastAPI                 β”‚                     β”‚
β”‚                  β”‚  REST + WebSocket        β”‚                     β”‚
β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                               β”‚                                   β”‚
β”‚                               β–Ό                                   β”‚
β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚                  β”‚  Next.js Dashboard       β”‚                     β”‚
β”‚                  β”‚  Live charts & alerts    β”‚                     β”‚
β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Services

Service Image Port Role
fraud-postgres postgres:16-alpine 5432 Predictions database
fraud-kafka apache/kafka:3.8 9092 KRaft message broker
fraud-spark-master custom 7077 / 8080 Spark cluster coordinator
fraud-spark-worker custom 8081 ML inference executor
fraud-spark-stream custom 4040 Streaming driver
fraud-api custom 8000 FastAPI REST + WebSocket
fraud-dashboard custom 3001 Next.js frontend

πŸš€ Quick Start

Prerequisites

  • Docker Desktop 24+
  • 6 GB RAM available
  • 10 GB free disk space
# 1. Clone the repo
git clone https://github.com/Veladicodes/Realtime-Fake-Job-Predictor.git
cd Realtime-Fake-Job-Predictor

# 2. Set up environment
cp .env.example .env
# ⚠️  Edit .env and set a strong POSTGRES_PASSWORD

# 3. Launch everything
docker compose up --build
Service URL
πŸ“Š Live Dashboard http://localhost:3001
πŸ“– API Docs (Swagger) http://localhost:8000/docs
⚑ Spark Master UI http://localhost:8080
πŸ”§ Spark Worker UI http://localhost:8081
# Stop everything
docker compose down

# Also start the Kafka CSV producer (streams dataset into pipeline)
docker compose --profile producer up

Windows Local Dev (no Docker)

cd fake_job_detector
python -m venv venv && venv\Scripts\activate
pip install -r requirements.txt
python ../start_system.py

πŸ€– ML Model Performance

Trained on the Kaggle Fake Job Postings dataset β€” 17,880 job postings, 866 fraudulent (4.8%).

Metric Score
βœ… Accuracy 98.0%
🎯 Precision 100%
πŸ” Recall 60.2%
βš–οΈ F1-Score 75.2%

Model selected: Random Forest (beat Logistic Regression on F1-score)

100% Precision means zero false alarms β€” every job the model flags as fake is genuinely fraudulent. The trade-off is 60% recall: it misses ~40% of fakes, but never incorrectly flags a real job.

How the model works

  1. Text preprocessing β€” job title + company profile + description + requirements are combined and cleaned
  2. TF-IDF vectorization β€” converts text into 5,000 numerical features (rare, distinctive words score highest)
  3. Feature engineering β€” adds has_company_profile, has_salary_range, text_length
  4. Random Forest β€” 100 decision trees vote on the final prediction

To retrain from scratch:

cd fake_job_detector
python ml/train_model.py

πŸ“‘ API Reference

Base URL: http://localhost:8000

Method Endpoint Description
GET /health System health (Kafka, Spark, DB, ML status)
GET /dashboard Aggregated stats snapshot
GET /jobs/latest Last 50 processed predictions
GET /jobs/fake All flagged fake jobs
GET /alerts Top alerts sorted by risk score
GET /trends Hourly fake/real job trend (24h window)
GET /clusters/top High-pressure fraud clusters
GET /corrections Manual human overrides
POST /jobs/ingest Submit a new job posting for analysis
WS /ws WebSocket β€” live prediction stream

Full interactive docs: http://localhost:8000/docs


πŸ“ Project Structure

Realtime-Fake-Job-Predictor/
β”œβ”€β”€ docker-compose.yml              # Orchestrates all 7 services
β”œβ”€β”€ .env.example                    # Environment variable template
β”œβ”€β”€ start_system.py                 # Windows local dev launcher
β”œβ”€β”€ DOCKER_SETUP.md                 # Detailed Docker guide
β”‚
└── fake_job_detector/
    β”œβ”€β”€ api/                        # FastAPI backend
    β”‚   β”œβ”€β”€ Dockerfile
    β”‚   └── app.py                  # REST endpoints + WebSocket
    β”‚
    β”œβ”€β”€ dashboard/                  # Next.js real-time frontend
    β”‚   β”œβ”€β”€ app/                    # Pages: dashboard, alerts, analytics, trends
    β”‚   β”œβ”€β”€ components/             # UI components
    β”‚   β”œβ”€β”€ context/                # Dashboard state (WebSocket + polling)
    β”‚   └── services/               # API client
    β”‚
    β”œβ”€β”€ kafka/                      # Kafka CSV replay producer
    β”‚   └── producer.py
    β”‚
    β”œβ”€β”€ ml/                         # Model training pipeline
    β”‚   β”œβ”€β”€ preprocess.py
    β”‚   β”œβ”€β”€ train_model.py
    β”‚   └── saved_model/            # fraud_model.pkl + tfidf.pkl
    β”‚
    β”œβ”€β”€ spark/                      # Spark Structured Streaming job
    β”‚   β”œβ”€β”€ spark_stream.py         # Main streaming driver
    β”‚   β”œβ”€β”€ model_loader.py         # ML inference UDF
    β”‚   └── Dockerfile
    β”‚
    β”œβ”€β”€ utils/                      # DB writer, config, helpers
    └── data/raw/                   # fake_job_postings.csv (17,880 rows)

βš™οΈ Environment Variables

Variable Default Description
POSTGRES_PASSWORD (required) Database password
SPARK_TRIGGER_INTERVAL 5 seconds Spark micro-batch cadence
SPARK_MAX_OFFSETS_PER_TRIGGER 700 Records per Spark batch
ANOMALY_EMA_ALPHA 0.2 EMA smoothing factor
ANOMALY_SPIKE_MULTIPLIER 2.2 Spike threshold multiplier
DASHBOARD_PORT 3001 Host port for Next.js dashboard
REPLAY_SPEED 10.0 CSV replay speed (10x = 10Γ— faster)
MAX_KAFKA_LAG 5000 Producer throttle threshold

See .env.example for the full list.


πŸ§ͺ Load Testing

python fake_job_detector/load_test.py \
  --total-events 10000 \
  --concurrency 40 \
  --api-base-url http://127.0.0.1:8000

🀝 Contributing

Contributions are welcome! Please open an issue first to discuss what you'd like to change.

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'Add your feature'
  4. Push and open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.


If you found this useful, please consider giving it a ⭐

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages