An end-to-end Machine Learning platform for detecting phishing websites and network intrusions, powered by XGBoost and a modular MLOps pipeline.
Features β’ Tech Stack β’ Project Structure β’ Getting Started β’ API Reference β’ Deployment β’ Contributing β’ License
| Feature | Description |
|---|---|
| π Real-Time URL Scanning | Paste any URL and get an instant Phishing / Legitimate verdict using a trained ML model + PhishTank API cross-check. |
| π Batch CSV Analysis | Upload a CSV of network traffic features to get bulk predictions with downloadable results. |
| π€ RAG Chatbot | An AI assistant powered by Google Gemini 1.5 Flash that answers questions about the platform, grounded in project context. |
| π MLflow Experiment Tracking | Every training run logs F1, Precision, and Recall metrics to DagsHub/MLflow for experiment comparison. |
| βοΈ AWS S3 Artifact Storage | Training artifacts and final models are automatically synced to an S3 bucket after each pipeline run. |
| π User Authentication | Session-based login/register system backed by MongoDB. |
| ποΈ CI/CD Pipeline | GitHub Actions workflow for linting, Docker build, ECR push, and self-hosted deployment. |
| β‘ Optimised Inference | Model is loaded once at startup (~27 MB) and reused across all requests; URL scan results are cached in-memory. |
| Layer | Technologies |
|---|---|
| ML / Data Science | Scikit-Learn, XGBoost, KNN Imputer, Pandas, NumPy |
| Experiment Tracking | MLflow, DagsHub |
| Backend / API | FastAPI, Uvicorn, Mangum (AWS Lambda adapter) |
| Frontend | Jinja2 Templates, Bootstrap 5, Animate.css, Google Fonts (Outfit) |
| Database | MongoDB Atlas (PyMongo) |
| Cloud & Infra | AWS S3, AWS ECR, Docker, GitHub Actions |
| AI / Chatbot | Google Gemini 1.5 Flash (google-generativeai SDK) |
| Deployment | Netlify (serverless), Vercel, Self-hosted Docker |
.
βββ .github/
β βββ workflows/
β βββ main.yml # CI/CD β Build β ECR β Deploy
β
βββ data_schema/
β βββ schema.yaml # 30-feature schema (int64 columns)
β
βββ final_model/
β βββ model.pkl # Trained XGBoost/best model (~27 MB)
β βββ preprocessor.pkl # KNN Imputer pipeline (~2.3 MB)
β
βββ Network_Data/
β βββ phisingData.csv # Raw phishing dataset (11,055 rows)
β
βββ networksecurity/ # Core Python package
β βββ chatbot/
β β βββ rag_factory.py # Gemini-powered RAG chatbot
β βββ cloud/
β β βββ s3_syncer.py # AWS S3 sync utility
β βββ components/
β β βββ data_ingestion.py # MongoDB β DataFrame β Train/Test
β β βββ data_validation.py # Schema validation & KS drift test
β β βββ data_transformation.py # KNN Imputation pipeline
β β βββ model_trainer.py # Multi-model training + MLflow
β βββ constant/
β β βββ training_pipeline/
β β βββ __init__.py # All pipeline constants
β βββ entity/
β β βββ config_entity.py # Config dataclasses for each stage
β β βββ artifact_entity.py # Artifact dataclasses for each stage
β βββ exception/
β β βββ exception.py # Custom exception with file/line info
β βββ logging/
β β βββ logger.py # Timestamped file-based logging
β βββ pipeline/
β β βββ training_pipeline.py # Orchestrates the full training run
β βββ utils/
β βββ main_utils/
β β βββ utils.py # save/load object, YAML, numpy I/O
β βββ ml_utils/
β βββ feature_extractor.py # URL β 30-feature vector extraction
β βββ metric/ # Classification metric helper
β βββ model/
β βββ estimator.py # NetworkModel (preprocessor + model)
β
βββ static/
β βββ css/ # style.css, premium.css
β βββ js/ # dashboard.js
β βββ images/ # hero_banner.png, login_bg.png, etc.
β
βββ templates/
β βββ landing.html # Public marketing landing page
β βββ login.html # Auth page (login + register)
β βββ index.html # Main dashboard (URL scan, CSV upload, chatbot)
β βββ table.html # Prediction results table
β
βββ app.py # FastAPI application entry point
βββ main.py # CLI entry for training pipeline
βββ push_data.py # Script to seed MongoDB from CSV
βββ check_preprocessor.py # Debug utility for preprocessor inspection
βββ setup.py # Package metadata & dependency installer
βββ requirements.txt # Python dependencies
βββ Dockerfile # Production container (Python 3.10-slim)
βββ run.sh # Local deployment helper script
βββ netlify.toml # Netlify serverless configuration
βββ vercel.json # Vercel deployment configuration
βββ AGENTS.md # AI agent rules & project conventions
βββ CODE_OF_CONDUCT.md # Contributor Code of Conduct
βββ CONTRIBUTING.md # Contribution guidelines
βββ SECURITY.md # Security policy & vulnerability reporting
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Training Pipeline β
β β
MongoDB Atlas βββΆ β Ingestion β Validation β Transformation β
(or local CSV) β β β β β
β βΌ βΌ βΌ β
β Train/Test Drift KNN Imputer β
β Split Report Pipeline β
β β
β Model Training β
β ββββββββββββββββββββββββββββββββββββββ β
β β Random Forest β XGBoost β AdaBoost β β
β β Decision Tree β GBM β Logistic β β
β ββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β Best Model βββΆ MLflow βββΆ DagsHub β
β β β
β βΌ β
β final_model/ βββΆ AWS S3 β
ββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Inference (FastAPI) β
β β
β /predict_url βββΆ Feature Extractor β
β β β β
β β PhishTank API β
β β β β
β βΌ βΌ β
β NetworkModel.predict() β
β β β
β βΌ β
β { prediction: "Phishing" | "Legitimate" } β
β β
β /predict βββΆ CSV β NumPy β predict() β
β /api/chat βββΆ Gemini RAG chatbot β
ββββββββββββββββββββββββββββββββββββββββββββββββ
- Python 3.10+
- MongoDB Atlas account (or local MongoDB instance)
- AWS CLI configured (for S3 artifact storage)
- Google API Key (for the RAG chatbot β Gemini 1.5 Flash)
git clone https://github.com/prashantshukla01/Network_Security.git
cd Network_Security# Using conda
conda create -n networkml python=3.10 -y
conda activate networkml
# Or using venv
python3 -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windowspip install -r requirements.txt
pip install python-multipart # Required for file uploadsCreate a .env file in the project root:
MONGO_DB_URL=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/?appName=<appName>
GOOGLE_API_KEY=<your-google-gemini-api-key>
AWS_ACCESS_KEY_ID=<your-aws-access-key>
AWS_SECRET_ACCESS_KEY=<your-aws-secret-key>
SECRET_KEY=<random-session-secret-key>
β οΈ Important: Never commit your.envfile. It is already listed in.gitignore.
If starting fresh, push the phishing dataset to MongoDB:
python push_data.pypython app.py
# Server starts at http://0.0.0.0:8000Or use the helper script:
chmod +x run.sh
./run.shRun the full ML training pipeline (Ingestion β Validation β Transformation β Training β S3 Sync):
python main.pyOr trigger via the API:
GET http://127.0.0.1:8000/train
| Model | Hyperparameter Grid |
|---|---|
| Random Forest | n_estimators: [8, 16, 32, 128, 256] |
| Decision Tree | criterion: [gini, entropy, log_loss] |
| Gradient Boosting | learning_rate, subsample, n_estimators |
| XGBoost | learning_rate, n_estimators, max_depth |
| AdaBoost | learning_rate, n_estimators |
| Logistic Regression | Default |
The best model is automatically selected based on test score and pushed to final_model/.
Metrics are logged to DagsHub:
# Set tracking (already configured in model_trainer.py via dagshub.init)
export MLFLOW_TRACKING_URI=https://dagshub.com/prashantshukla01/Network_Security.mlflow
export MLFLOW_TRACKING_USERNAME=<your-username>
export MLFLOW_TRACKING_PASSWORD=<your-token>
# View locally
mlflow ui| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Landing page |
GET |
/login |
Login / Register page |
POST |
/login |
Submit login credentials |
POST |
/register |
Register a new user |
GET |
/logout |
Clear session and redirect |
GET |
/dashboard |
Main dashboard (auth required) |
GET |
/train |
Trigger full training pipeline |
POST |
/predict |
Upload CSV for batch prediction |
POST |
/predict_url |
Scan a single URL (JSON body: {"url": "..."}) |
GET |
/api/history |
Get last 10 prediction history records |
POST |
/api/chat |
Chat with the RAG assistant (JSON body: {"message": "..."}) |
curl -X POST http://127.0.0.1:8000/predict_url \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'Response:
{
"url": "https://example.com",
"prediction": "Legitimate",
"raw_result": 1
}# Build
docker build -t netguard-ai .
# Run
docker run -d -p 8000:8000 \
-e MONGO_DB_URL="<your-mongo-url>" \
-e GOOGLE_API_KEY="<your-key>" \
--name netguard \
netguard-aiThe GitHub Actions workflow (.github/workflows/main.yml) handles:
- Continuous Integration β Lint + unit test stubs
- Continuous Delivery β Docker build β push to AWS ECR
- Continuous Deployment β Pull from ECR β run on self-hosted runner (port
8080:8000)
Required GitHub Secrets:
| Secret | Description |
|---|---|
AWS_ACCESS_KEY_ID |
AWS IAM access key |
AWS_SECRET_ACCESS_KEY |
AWS IAM secret key |
AWS_REGION |
e.g. ap-south-1 |
AWS_ECR_LOGIN_URI |
ECR registry URI |
ECR_REPOSITORY_NAME |
ECR repository name |
MONGO_DB_URL |
MongoDB Atlas connection string |
Configured via netlify.toml β uses Mangum adapter to wrap FastAPI as a serverless function.
Configured via vercel.json β routes all traffic to app.py.
The model uses 30 features extracted from URLs and web page attributes:
Click to expand full feature list
| # | Feature | Type |
|---|---|---|
| 1 | having_IP_Address |
int64 |
| 2 | URL_Length |
int64 |
| 3 | Shortining_Service |
int64 |
| 4 | having_At_Symbol |
int64 |
| 5 | double_slash_redirecting |
int64 |
| 6 | Prefix_Suffix |
int64 |
| 7 | having_Sub_Domain |
int64 |
| 8 | SSLfinal_State |
int64 |
| 9 | Domain_registeration_length |
int64 |
| 10 | Favicon |
int64 |
| 11 | port |
int64 |
| 12 | HTTPS_token |
int64 |
| 13 | Request_URL |
int64 |
| 14 | URL_of_Anchor |
int64 |
| 15 | Links_in_tags |
int64 |
| 16 | SFH |
int64 |
| 17 | Submitting_to_email |
int64 |
| 18 | Abnormal_URL |
int64 |
| 19 | Redirect |
int64 |
| 20 | on_mouseover |
int64 |
| 21 | RightClick |
int64 |
| 22 | popUpWidnow |
int64 |
| 23 | Iframe |
int64 |
| 24 | age_of_domain |
int64 |
| 25 | DNSRecord |
int64 |
| 26 | web_traffic |
int64 |
| 27 | Page_Rank |
int64 |
| 28 | Google_Index |
int64 |
| 29 | Links_pointing_to_page |
int64 |
| 30 | Statistical_report |
int64 |
Values: 1 (Legitimate), 0 (Suspicious), -1 (Phishing)
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
For reporting vulnerabilities, see SECURITY.md.
Prashant Shukla
- Email: prashantshukla9812@gmail.com
- GitHub: @prashantshukla01
This project is open source and available under the MIT License.
Made with β€οΈ for a safer internet.
