Try out the live demo of the project: Network Security Project Demo
(Please note that the application may take a few minutes to start up on first access)
- Live Demo
- Project Overview
- Project Structure
- Features
- Installation
- Usage
- Frontend Interface
- MLOps Pipeline
- API Endpoints
- Deployment on AWS
- CI/CD Pipeline
- Results and Examples
- Contributing
- License
This Network Security Project is designed to detect phishing websites using machine learning techniques. The primary goal is to create a robust MLOps (Machine Learning Operations) solution with a clear and modular structure that can:
- Ingest data from MongoDB
- Validate data against a predefined schema
- Transform and preprocess the data
- Train machine learning models
- Deploy the best model via a FastAPI application
- Make batch predictions on new data
- Provide an easy-to-use interface for predictions
The project follows industry best practices for MLOps, ensuring reproducibility, scalability, and maintainability.
The project follows a modular architecture with separate components for each step in the ML lifecycle:
Network-Security-Project/
βββ app.py # FastAPI application
βββ Dockerfile # Docker configuration for containerization
βββ main.py # Main pipeline execution script
βββ push_data.py # Script to push data to MongoDB
βββ requirements.txt # Project dependencies
βββ setup.py # Package setup configuration
βββ training_status.json # Training process status tracking
βββ test_mongodb.py # MongoDB connection test script
βββ Artifacts/ # Saved data artifacts by timestamp
β βββ 05_18_2025_21_05_00/ # Example artifact directory
β βββ data_ingestion/ # Data fetching artifacts
β βββ data_transformation/ # Preprocessing artifacts
β βββ data_validation/ # Validation reports
β βββ model_trainer/ # Model artifacts
βββ daily_logs/ # Daily operation logs
βββ logs/ # Detailed timestamped log files
βββ data_schema/ # Data validation schemas
β βββ schema.yaml # Schema definition file
βββ final_model/ # Production-ready model
β βββ model.pkl # Trained model
β βββ preprocessor.pkl # Data preprocessor
βββ Network_Data/ # Raw dataset directory
β βββ phisingData.csv # Phishing website dataset
βββ prediction_output/ # Directory for prediction results
β βββ output.csv # Example prediction output
βββ valid_data/ # Validated data for testing
β βββ test.csv # Test dataset
βββ templates/ # HTML templates for the web interface
β βββ index.html # Landing page
β βββ prediction.html # Prediction interface
β βββ train_model.html # Model training interface
β βββ training_complete.html # Training success page
β βββ table.html # Results display page
βββ static/ # Static assets for the frontend
β βββ css/ # CSS stylesheets
β βββ js/ # JavaScript files
β βββ img/ # Images and icons
βββ networksecurity/ # Core package
βββ __init__.py # Package initialization
βββ components/ # Pipeline components
β βββ __init__.py # Component initialization
β βββ data_ingestion.py # Data loading from MongoDB
β βββ data_validation.py # Schema validation
β βββ data_transformation.py # Feature engineering
β βββ model_trainer.py # Model training and evaluation
βββ cloud/ # Cloud integration (AWS S3)
β βββ __init__.py # Cloud module initialization
β βββ s3_syncer.py # AWS S3 synchronization
βββ constant/ # Project constants and configurations
βββ entity/ # Data classes and entities
βββ exception/ # Custom exception handling
βββ logging/ # Logging configuration
βββ pipeline/ # ML pipelines
βββ utils/ # Utility functions
- π End-to-end MLOps pipeline
- π Data validation with schema enforcement
- π§ Machine learning model training with hyperparameter tuning
- π FastAPI-based REST API for real-time predictions
- π¨ Modern, responsive web interface with cybersecurity aesthetics
- π± User-friendly UI for model training and predictions
- π¦ Containerization with Docker
- βοΈ AWS deployment ready
- π CI/CD with GitHub Actions for automated testing and deployment
- π Experiment tracking with MLflow
- π Security-focused for phishing detection
-
Clone the repository:
git clone https://github.com/cmatiass/Network-Security-Project.git -
Install dependencies:
pip install -r requirements.txt -
Set up environment variables:
# Create a .env file with: MONGODB_URL_KEY=your_mongodb_connection_string -
Install the package in development mode:
pip install -e .
-
After installation, start the FastAPI application:
python app.py -
The application will start on
http://localhost:8000 -
Open your web browser and navigate to this address
-
You'll see the main dashboard with options to:
- Learn about the project
- Train a new model
- Make predictions on network data
- Navigate to the "Train Model" page
- Click the "Start Training" button
- The system will display real-time progress of the training pipeline
- Once complete, you'll see performance metrics and can proceed to making predictions
- Navigate to the "Make Prediction" page
- Upload your network data in CSV format, or use the provided sample data
- Click "Analyze Network Data"
- View the detailed results showing:
- Classification results (safe or malicious)
- Confidence scores
- Feature importance
- Summary statistics
The project includes a test.csv file in the valid_data directory that can be used to test the prediction functionality. This sample data contains various network security features like:
- IP address characteristics
- URL properties
- Domain registration information
- SSL certificate status
- HTTP/HTTPS token information
The project implements a comprehensive MLOps pipeline:
- Connects to MongoDB to fetch phishing data
- Splits data into training and testing sets
- Stores the split data as artifacts
- Validates the dataset against a predefined schema (schema.yaml)
- Checks for missing values, data types, and column names
- Generates validation reports
- Preprocesses the data with appropriate scaling and encoding
- Handles categorical features
- Creates preprocessor pipeline artifacts
- Trains multiple classification algorithms
- Performs hyperparameter tuning
- Evaluates models using appropriate metrics
- Selects the best performing model
- Packages the model with a FastAPI application
- Exposes REST API endpoints for predictions
- Containerizes the application with Docker
The application provides several API endpoints for both frontend functionality and direct programmatic access:
GET /: Main landing page with project overviewGET /train-model: Model training interfaceGET /prediction: Prediction interface for data uploadsGET /training-complete: Training completion confirmation page
POST /train-status: Initiates model training processPOST /finalize-training: Finalizes and persists the trained modelGET /check-model: Checks if a trained model exists and its statusPOST /predict: Makes predictions on uploaded dataGET /predict-sample: Makes predictions using the sample test dataset
Check if model exists:
import requests
response = requests.get("http://localhost:8000/check-model")
print(response.json())
# {"trained": true, "status": "completed"}Upload data for prediction:
import requests
files = {"file": open("network_data.csv", "rb")}
response = requests.post("http://localhost:8000/predict", files=files)
# Returns HTML with prediction resultsUse sample data for prediction:
import requests
response = requests.get("http://localhost:8000/predict-sample")
# Returns HTML with prediction results using test.csvThe project is designed to be deployed on AWS following these steps:
-
Build Docker Image:
docker build -t network-security-project . -
Push to Amazon ECR:
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com docker tag network-security-project:latest <account-id>.dkr.ecr.<region>.amazonaws.com/network-security-project:latest docker push <account-id>.dkr.ecr.<region>.amazonaws.com/network-security-project:latest -
Deploy on ECS/Fargate:
- Create an ECS cluster
- Define a task definition using the ECR image
- Create a service with desired configurations
- Set up Application Load Balancer for exposing the API
-
Model Storage:
- Models are stored in S3 using the S3 syncer utility
- This allows for version control of models
This project implements Continuous Integration and Continuous Deployment using GitHub Actions:
-
Automated Testing:
- Every push and pull request to the main branch triggers automated tests
- Unit tests validate individual components
- Integration tests verify the entire pipeline functionality
-
Continuous Deployment:
- Successful builds on the main branch automatically deploy to AWS
- The workflow builds the Docker image, pushes it to ECR, and updates the ECS service
- Environment variables are securely stored as GitHub Secrets
The CI/CD pipeline ensures that the application is always in a deployable state, reducing manual errors and speeding up the development process.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Created with β€οΈ for secure networks
