An end-to-end Machine Learning system for detecting phishing URLs β built with a production-grade MLOps pipeline.
Network Security is a full-stack MLOps project that detects phishing websites using machine learning. It goes beyond a simple notebook β implementing a complete, production-ready pipeline covering data ingestion from MongoDB, data validation with drift detection, feature transformation, model training with hyperparameter tuning, experiment tracking via MLflow & DagsHub, and deployment as a REST API using FastAPI inside a Docker container with CI/CD via GitHub Actions.
π The model analyzes network-level features of URLs to classify them as phishing or legitimate β a real-world cybersecurity problem with direct industry relevance.
| Feature | Description |
|---|---|
| ποΈ Data Source | Phishing dataset stored and fetched from MongoDB Atlas |
| β Data Validation | Schema checks + KS-test based data drift detection |
| βοΈ Feature Engineering | KNN Imputer for missing values, preprocessing pipeline serialized as .pkl |
| π€ Model Selection | Automated comparison of 5 classifiers with GridSearchCV |
| π Experiment Tracking | All runs tracked via MLflow integrated with DagsHub |
| π REST API | Full prediction & training endpoints via FastAPI |
| π³ Containerized | Fully Dockerized application |
| π CI/CD | Automated pipeline via GitHub Actions |
Raw Data (CSV)
β
βΌ
βββββββββββββββββββ
β MongoDB Atlas β β Data Storage
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Data Ingestion β β Pulls data, splits into Train/Test
ββββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββββ
β Data Validation β β Schema validation + Drift Detection (KS-Test)
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Data Transformationβ β KNN Imputer, Preprocessing β saved as .pkl
ββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββ
β Model Trainer β β Trains 5 models, selects best, logs to MLflow
ββββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββββ
β FastAPI Server β β /train and /predict endpoints
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β Docker + CI/CD β β Containerized & deployed via GitHub Actions
ββββββββββββββββββββ
- Connects to MongoDB Atlas and exports the
NetworkDatacollection as a Pandas DataFrame - Handles missing values (
naβNaN) and drops internal MongoDB_idfield - Splits data into train (80%) / test (20%) and saves to the artifact store
- Validates that train and test datasets conform to the expected schema (column count, column names)
- Detects data drift using the Kolmogorov-Smirnov (KS) test on each feature column
- Generates a drift report (
report.yaml) flagging drifted columns with p-values
- Applies KNN Imputer (
k=3, weights=uniform) to handle missing values - Serializes the complete preprocessing pipeline as
preprocessing.pklfor inference consistency
Trains and evaluates 5 classification models using cross-validated GridSearchCV:
| Model | Hyperparameters Tuned |
|---|---|
| Random Forest | n_estimators |
| Decision Tree | criterion |
| Gradient Boosting | learning_rate, subsample, n_estimators |
| Logistic Regression | β |
| AdaBoost | learning_rate, n_estimators |
- Selects the best model by test score
- Evaluates with F1-Score, Precision, and Recall
- Logs all metrics and models to MLflow / DagsHub
- Every training run is logged with metrics:
f1_score,precision,recall - Models are registered in the MLflow Model Registry
- Experiments are tracked remotely on DagsHub
Once the server is running, navigate to http://localhost:8000/docs for the interactive Swagger UI.
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Redirects to Swagger UI |
GET |
/train |
Triggers the full training pipeline |
POST |
/predict |
Upload a CSV file and get phishing predictions |
The /predict endpoint accepts a CSV file, runs inference using the saved model + preprocessor, and returns an HTML table with a predicted_column appended (1 = Phishing, -1 = Legitimate).
NetworkSecurity/
βββ networksecurity/
β βββ components/ # Core ML pipeline stages
β β βββ data_ingestion.py
β β βββ data_validation.py
β β βββ data_transformation.py
β β βββ model_trainer.py
β βββ pipeline/
β β βββ training_pipeline.py # Orchestrates full pipeline
β βββ entity/
β β βββ config_entity.py # Configuration dataclasses
β β βββ artifact_entity.py # Artifact dataclasses
β βββ constants/
β β βββ training_pipeline/ # All constants & hyperparams
β βββ utils/ # Utility functions
β βββ exception/ & logging/ # Custom exception & logger
βββ templates/
β βββ table.html # Prediction results UI
βββ app.py # FastAPI application
βββ main.py # Run pipeline manually
βββ push_data.py # Load CSV data into MongoDB
βββ Dockerfile
βββ requirements.txt
βββ setup.py
βββ .github/workflows/main.yml # CI/CD pipeline
- Python 3.10+
- MongoDB Atlas account
- DagsHub account (for MLflow tracking)
- Docker (optional, for containerized run)
git clone https://github.com/RudrakshJani/NetworkSecurity.git
cd NetworkSecuritypython -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windowspip install -r requirements.txtCreate a .env file in the project root:
MONGODB_URL_KEY=your_mongodb_atlas_connection_string
MLFLOW_TRACKING_URI=your_dagshub_mlflow_uri
MLFLOW_TRACKING_USERNAME=your_dagshub_username
MLFLOW_TRACKING_PASSWORD=your_dagshub_tokenpython push_data.pypython app.pyVisit http://localhost:8000/docs to access the API.
docker build -t networksecurity:latest .docker run -p 8000:8000 --env-file .env networksecurity:latestThis project uses GitHub Actions for continuous integration. On every push to main:
- Checkout β Pulls the latest code
- Lint β Code quality check
- Unit Tests β Automated test execution
The workflow is defined in .github/workflows/main.yml.
| Category | Technology |
|---|---|
| Language | Python 3.10+ |
| ML Framework | Scikit-learn |
| API Framework | FastAPI + Uvicorn |
| Database | MongoDB Atlas |
| Experiment Tracking | MLflow + DagsHub |
| Containerization | Docker |
| CI/CD | GitHub Actions |
| Data Processing | Pandas, NumPy |
| Config Management | PyYAML, python-dotenv |
- β Not just a notebook β fully modular, production-grade codebase
- β MLOps best practices β artifact management, experiment tracking, model registry
- β Real-world problem β phishing detection is a top cybersecurity challenge
- β Scalable design β pipeline components are loosely coupled and independently testable
- β End-to-end β from raw data in MongoDB to a live REST API in Docker
Rudraksh Jani π§ rudrakshjani05@gmail.com
This project is licensed under the MIT License β see the LICENSE file for details.