Skip to content

Repository files navigation

πŸ›‘οΈ SENTINEL

AI-Powered Network Threat Detection System

Python FastAPI scikit-learn MLflow MongoDB Docker Render

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


✨ Preview

Sentinel Dashboard β€” Dark Mode



Analyze Page

🎨 Design Features

  • Glassmorphism cards with blur effects
  • Interactive dot-grid animated background
  • Gradient animations (cyan ↔ violet)
  • Dark / Light theme with smooth toggle
  • Scroll-reveal entrance animations
  • Drag-and-drop CSV uploads
  • Live pipeline step visualization
  • Responsive β€” works on any screen

🧠 What It Does

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

πŸ—οΈ Architecture

                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚         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  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧰 Tech Stack

Layer Technology
Language Python 3.10+
ML Scikit-learn
API FastAPI + Uvicorn
Frontend Jinja2, Vanilla CSS/JS
Database MongoDB Atlas
Layer Technology
Tracking MLflow + DagsHub
Data Pandas, NumPy
Fonts Inter, JetBrains Mono
Container Docker
Deploy Render (Free)

πŸš€ Quick Start

Prerequisites

1️⃣ Clone & Setup

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.txt

2️⃣ Configure Environment

Create 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>

3️⃣ Load Data & Run

# 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

🌐 API Reference

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

Example: Predict via cURL

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.


πŸ€– ML Pipeline Deep Dive

Stage 1 β€” Data Ingestion

Connects to MongoDB Atlas, exports the NetworkData collection, and splits into 80/20 train/test sets.

Stage 2 β€” Data Validation

Validates against data_schema/schema.yaml. Generates a drift report to detect distribution shifts between training runs.

Stage 3 β€” Data Transformation

Applies KNN Imputer (k=3, uniform weights) to handle missing values. Saves the fitted preprocessor as a pickle artifact.

Stage 4 β€” Model Training

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


☁️ Deploy to Render (Free)

Render offers a free tier with Docker support β€” zero cost, auto-deploy on push.

Step-by-Step

  1. Push your code to GitHub

  2. Sign up at render.com (free)

  3. Click New β†’ Web Service β†’ connect your GitHub repo

  4. Configure:

    • Build Command: pip install -r requirements.txt
    • Start Command: uvicorn app:app --host 0.0.0.0 --port 10000
    • Plan: Free
  5. Add Environment Variables:

    Key Value
    MONGODB_URL_KEY Your MongoDB connection string
    MONGO_DB_URL Your MongoDB connection string
    MLFLOW_TRACKING_URI DagsHub MLflow URL
    MLFLOW_TRACKING_USERNAME DagsHub username
    MLFLOW_TRACKING_PASSWORD DagsHub token
  6. Click Create Web Service β†’ Done! πŸŽ‰

πŸ“ Your app will be live at https://<app-name>.onrender.com
πŸ”„ Auto-deploys on every push to main
πŸ’‘ Tip: Free tier sleeps after ~15min idle. Use cron-job.org to ping every 14min to keep it awake.


🐳 Docker

# Build
docker build -t sentinel .

# Run
docker run -p 8080:8080 --env-file .env sentinel

# β†’ http://localhost:8080

πŸ“Š Experiment Tracking

All 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

πŸ“ Project Structure

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)

πŸ” Environment Variables

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.


🀝 Contributing

# 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-feature

πŸ“„ License

This 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!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages