This project is a FastAPI-based application for network security tasks, such as training models and making predictions on network data (e.g., phishing detection). It includes a CI/CD pipeline, Docker support/AWS ECR, AWS s3 Bucket , and MongoDB integration and deployment using FastAPI/AWs EC2 Instance.
.
├── .env # Environment variables
├── .gitignore # Git ignore file
├── app.py # FastAPI application
├── Dockerfile # Dockerfile for containerization
├── main.py # Main entry point for the application
├── push_data.py # Script to push data to the database
├── README.md # Project documentation (this file)
├── requirements.txt # Python dependencies
├── setup.py # Python package setup
├── test_mongodb.py # MongoDB connection test script
├── .github/
│ └── workflows/
│ └── main.yml # GitHub Actions CI/CD workflow
├── data_schema/
│ └── schema.yaml # Data schema definition
├── final_models/
│ ├── model.pkl # Trained model
│ └── preprocessor.pkl # Preprocessing pipeline
├── network_data/
│ └── phisingData.csv # Sample dataset
├── network_security/
│ ├── __init__.py
│ ├── cloud/ # Cloud-related utilities
│ ├── components/ # Pipeline components
│ ├── constant/ # Constants for the project
│ ├── entity/ # Entity definitions
│ ├── exception/ # Custom exceptions
│ ├── logging/ # Logging utilities
│ ├── pipeline/ # Training and deployment pipelines
│ └── utils/ # Utility functions
├── notebooks/ # Jupyter notebooks for experimentation
├── prediction_output/ # Directory for storing prediction outputs
└── templates/ # HTML templates for FastAPI
git clone https://github.com/your-username/your-repo.git
cd your-repoCreate a virtual environment and install the required Python packages:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate a .env file in the root directory and add the following (adjust values as needed):
MONGO_URI=mongodb://localhost:27017
DATABASE_NAME=network_security_db
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
ECR_REGISTRY=your-ecr-registry
Start the FastAPI application:
python app.pyAccess the API documentation at http://127.0.0.1:8000/docs.
docker build -t network-security-app .docker run -d -p 8000:8000 --env-file .env network-security-appThe project uses GitHub Actions for CI/CD, defined in .github/workflows/main.yml. The workflow includes:
- Checkout code: Pulls the latest code from the repository.
- Lint the repository: Runs linting to ensure code quality.
- Run unit tests: Executes tests to verify functionality.
- Build and push Docker images: Creates a Docker image and pushes it to Amazon ECR.
- Deploy the container: Deploys the container to a self-hosted runner.
app.py: Defines the FastAPI application with endpoints for training and prediction.Dockerfile: Configuration for containerizing the application.main.yml: GitHub Actions workflow for CI/CD.requirements.txt: Lists the Python dependencies.setup.py: Metadata and setup for the Python package.
Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix (
git checkout -b feature-name). - Commit your changes (
git commit -m "Add feature"). - Push to your fork (
git push origin feature-name). - Submit a pull request.
- AWS IAM : Access & Secret Access
- AWS S3 Bucket : Model.pkl and Preprocessor.pkl
- AWS EC2 Instance : Deployment with FastAPI
- AWS ECR : Container
