An end-to-end ML pipeline that detects phishing attacks in network traffic β from raw data ingestion to real-time predictions β wrapped in a stunning, modern web interface.
Live Demo Β· Get Started Β· API Docs Β· MLflow Dashboard
Sentinel analyzes network traffic features and classifies each data point as legitimate or phishing using machine learning. The system automates the entire journey:
π₯ Data Ingestion β β
Validation β π Transformation β π€ Training β π― Prediction
| Feature | Description |
|---|---|
| 5 ML Models | Random Forest, Gradient Boosting, Decision Tree, Logistic Regression, AdaBoost |
| Auto-Tuning | Hyperparameter tuning via GridSearchCV across all models |
| Best Model Selection | Automatically picks the highest-scoring classifier |
| Drift Detection | Schema validation + feature drift reports per training run |
| Experiment Tracking | Every run logged to MLflow with F1, Precision, Recall metrics |
| Web Interface | Upload CSV β get predictions, or trigger training from the browser |
| REST API | Programmatic /train and /predict endpoints |
βββββββββββββββββββββββββββββββββββββββββββ
β SENTINEL WEB APPLICATION β
β FastAPI + Jinja2 + Sentinel UI β
ββββββββββββββββ¬βββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ML TRAINING PIPELINE β
β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β 01 Data ββββΆβ 02 Data ββββΆβ 03 Data ββββΆβ 04 Model β β
β β Ingestion β βValidationβ βTransform β β Training β β
β β β β β β β β β β
β β MongoDB β β Schema + β β KNN β β5 Models +β β
β β β CSV β β Drift β β Imputer β β MLflow β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββ΄βββββββββββββββ
β β
ββββββ΄βββββ βββββββ΄ββββββ
β MongoDB β β MLflow β
β Atlas β β DagsHub β
βββββββββββ βββββββββββββ
|
|
- Python 3.10+ Β· Git Β· MongoDB (Atlas Free Tier)
git clone https://github.com/its-me-meax/networksecurity.git
cd networksecurity
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
pip install -r requirements.txtCreate a .env file in the project root:
# MongoDB (required)
MONGODB_URL_KEY=mongodb+srv://<user>:<pass>@<cluster>.mongodb.net/?retryWrites=true&w=majority
MONGO_DB_URL=mongodb+srv://<user>:<pass>@<cluster>.mongodb.net/?retryWrites=true&w=majority
# MLflow / DagsHub (optional β for experiment tracking)
MLFLOW_TRACKING_URI=https://dagshub.com/<username>/networksecurity.mlflow
MLFLOW_TRACKING_USERNAME=<dagshub-username>
MLFLOW_TRACKING_PASSWORD=<dagshub-token># Seed MongoDB with the phishing dataset
python push_data.py
# Option A: Run training pipeline (CLI)
python main.py
# Option B: Launch the web app
python app.py
# β Open http://localhost:8080| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
π Dashboard β Sentinel landing page |
GET |
/analyze |
π Upload page β CSV file upload for predictions |
GET |
/train-model |
ποΈ Training page β trigger pipeline from the UI |
GET |
/train |
β‘ API β Runs the full training pipeline |
POST |
/predict |
π― API β Upload CSV β get phishing predictions |
curl -X POST "http://localhost:8080/predict" -F "file=@network_data.csv"Returns an HTML table: each row annotated with predicted_column β 0 = safe, 1 = phishing.
Connects to MongoDB Atlas, exports the
NetworkDatacollection, and splits into 80/20 train/test sets.
Validates against
data_schema/schema.yaml. Generates a drift report to detect distribution shifts between training runs.
Applies KNN Imputer (k=3, uniform weights) to handle missing values. Saves the fitted preprocessor as a pickle artifact.
Trains 5 classifiers with hyperparameter tuning, selects the best, and logs everything to MLflow:
| Model | Tuned Parameters |
|---|---|
| Random Forest | n_estimators: [8, 16, 32, 128, 256] |
| Decision Tree | criterion: [gini, entropy, log_loss] |
| Gradient Boosting | learning_rate, subsample, n_estimators |
| Logistic Regression | Defaults |
| AdaBoost | learning_rate, n_estimators |
Selection criteria: Best score Β· Min threshold: 0.6 Β· Overfit tolerance: 0.05
Render offers a free tier with Docker support β zero cost, auto-deploy on push.
-
Push your code to GitHub
-
Sign up at render.com (free)
-
Click New β Web Service β connect your GitHub repo
-
Configure:
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn app:app --host 0.0.0.0 --port 10000 - Plan: Free
- Build Command:
-
Add Environment Variables:
Key Value MONGODB_URL_KEYYour MongoDB connection string MONGO_DB_URLYour MongoDB connection string MLFLOW_TRACKING_URIDagsHub MLflow URL MLFLOW_TRACKING_USERNAMEDagsHub username MLFLOW_TRACKING_PASSWORDDagsHub token -
Click Create Web Service β Done! π
π Your app will be live at
https://<app-name>.onrender.com
π Auto-deploys on every push tomain
π‘ Tip: Free tier sleeps after ~15min idle. Use cron-job.org to ping every 14min to keep it awake.
# Build
docker build -t sentinel .
# Run
docker run -p 8080:8080 --env-file .env sentinel
# β http://localhost:8080All runs are traced with MLflow via DagsHub:
- Metrics: F1 Score, Precision, Recall (train & test)
- Model Registry: Best model registered as
NetworkSecurityModel - Dashboard: β Open MLflow UI
sentinel/
βββ app.py # FastAPI web application
βββ main.py # CLI pipeline runner
βββ push_data.py # Seed MongoDB with CSV data
βββ setup.py # Package config
βββ requirements.txt # Dependencies
βββ dockerfile # Docker config
βββ render.yaml # Render deployment blueprint
β
βββ networksecurity/ # Core ML package
β βββ components/ # Pipeline stages
β β βββ data_ingestion.py
β β βββ data_validation.py
β β βββ data_transformation.py
β β βββ model_trainer.py
β βββ pipeline/ # Orchestration
β β βββ training_pipeline.py
β βββ entity/ # Config & artifact dataclasses
β βββ constant/ # Hyperparameters & constants
β βββ utils/ # Helpers (save/load, metrics)
β βββ exception/ # Custom exception handling
β βββ logging/ # Logger configuration
β
βββ static/ # Frontend assets
β βββ css/style.css # Sentinel design system (1300+ lines)
β βββ js/dotgrid.js # Animated dot-grid background
β
βββ templates/ # Jinja2 HTML templates
β βββ base.html # Layout + navbar + theme toggle
β βββ index.html # Dashboard
β βββ analyze.html # CSV upload & prediction
β βββ train.html # Training trigger with live steps
β βββ table.html # Prediction results
β
βββ Network_Data/ # Raw phishing dataset (CSV)
βββ data_schema/ # YAML schema definitions
βββ assets/ # README screenshots
βββ final_model/ # Saved model + preprocessor (.pkl)
| Variable | Required | Description |
|---|---|---|
MONGODB_URL_KEY |
β | MongoDB connection string |
MONGO_DB_URL |
β | MongoDB connection string |
MLFLOW_TRACKING_URI |
β | DagsHub MLflow tracking URL |
MLFLOW_TRACKING_USERNAME |
β | DagsHub username |
MLFLOW_TRACKING_PASSWORD |
β | DagsHub access token |
β οΈ Never commit.envβ it's already in.gitignore.
# 1. Fork the repo
# 2. Create a feature branch
git checkout -b feature/amazing-feature
# 3. Commit your changes
git commit -m "Add amazing feature"
# 4. Push & open a PR
git push origin feature/amazing-featureThis project is licensed under the MIT License β see the LICENSE file for details.
Built with β€οΈ by Pradyuman Sharma
β Star this repo if you found it useful!
