How techtyphoon/cyber-threat-detection-machine-learning-project works
Project Type and Purpose
• This is a full-stack web application for cyber threat detection.
• Frontend: React.js/Vite single-page app for user input and displaying predictions.
• Backend: Python/Flask API serving a pre-trained machine learning model (scikit-learn) to classify network traffic as Normal or malicious.
File Structure
• Top-level:
• Pipfile/Pipfile.lock: root environment for running scripts or orchestration
• README.md: project overview and setup instructions
• backend/: contains model code, data, API definitions, Dockerfile
• frontend/: contains React app, config files (package.json, vite.config.js, tailwind.config.js)
• backend/:
• data/: raw dataset (cyberfeddefender_dataset.csv)
• model artifacts: model.pkl, scaler.pkl, label_encoder.pkl
• notebook.py: training and EDA pipeline
• model.py: model-building logic
• predict.py: Flask server exposing /predict endpoint
• Dockerfile: containerizes Flask app
• frontend/:
• src/: React entrypoint (main.jsx), components (InputForm.jsx, ResultCard.jsx, ResultsTable.jsx), styling (App.css, index.css)
• public/index.html
• package.json & lock: npm dependencies (React, Axios, Tailwind)
• vite.config.js, postcss.config.js, tailwind.config.js, eslint.config.js
README for Insights
• Workflow: data preprocessing → model training → export .pkl files → containerize Flask API → React UI calls API
• Deployment: Docker build and run for backend; npm run dev for frontend
• External interactions: user’s browser communicates with backend via REST over HTTP (JSON payloads)
Main Components and Their Relationships
a. Frontend Client (React/Vite)
• Renders forms for single/batch inputs
• Sends HTTP POST requests with feature vectors or CSV file to /predict
• Displays prediction labels & probabilities
b. Backend API (Flask)
• Receives requests, loads model artifacts (scaler.pkl, label_encoder.pkl, model.pkl)
• Applies preprocessing steps, runs inference
• Returns JSON response with label and probabilities
c. Data & Model Artifacts
• Stored on backend filesystem under backend/data and root of backend
d. Containerization & Deployment
• Dockerfile builds a “flask-predict-app” image exposing port 5002
• Frontend and backend can be deployed independently (microservices-style)
e. Development Tooling
• Pipenv for Python virtual environments
• npm/Yarn and Vite for frontend bundling
• ESLint, Tailwind for code quality and styling
Architectural Patterns and Design Principles
• Layered architecture:
• Presentation layer (React UI)
• Service layer (Flask REST API)
• Data layer (model files + dataset)
• Separation of concerns: UI vs. inference logic vs. data preprocessing/training
• Containerization for portability and scaling
• Stateless API design: each request reloads model or reuses in-memory global