How shivammitra/network-security works
Purpose and Entry Points
This is a Python phishing-data ML service: it ingests phishing records, validates and transforms them, trains/persists a classifier, and serves batch prediction through an application layer. Primary operational entry points are app.py, main.py, and the data-load script push_data.py.
Training Pipeline Orchestration
networksecurity/pipeline/training_pipeline.py coordinates the end-to-end training lifecycle. It composes typed configuration and artifact objects from networksecurity/entity/config_entity.py and networksecurity/entity/artifact_entity.py, creating explicit handoffs between pipeline stages rather than coupling stages directly.
Data Sources and Ingestion Boundary
Raw phishing data is present at Network_Data/phisingData.csv; ingestion is implemented in networksecurity/components/data_ingestion.py. MongoDB is an external persistence/source integration, with population-oriented execution in push_data.py and coverage/smoke validation in test_mongodb.py. This separates external data acquisition/storage from local training artifacts.
Schema Validation
networksecurity/components/data_validation.py validates ingested data against the contract in data_schema/schema.yaml. Validated outputs are represented as pipeline artifacts and may be materialized under valid_data/test.csv. The schema boundary protects downstream feature processing and prediction from malformed or drifted input columns.
Transformation and Feature Preparation
networksecurity/components/data_transformation.py converts validated datasets into model-ready features and persists preprocessing state. Shared serialization/data utilities reside in networksecurity/utils/main_utils/utils.py. The resulting fitted preprocessor is distributed with the trained model as final_model/preprocessor.pkl, ensuring inference uses the same feature preparation as training.
Model Training, Evaluation, and Packaging
networksecurity/components/model_trainer.py fits and evaluates the phishing classifier, using classification metrics in networksecurity/utils/ml_utils/metric/classification_metric.py. Estimator wrapping/adaptation is centralized in networksecurity/utils/ml_utils/model/estimator.py. Deployable artifacts are checked into final_model/model.pkl and final_model/preprocessor.pkl.
Batch Inference and Service Surface
networksecurity/pipeline/batch_prediction.py is the inference orchestration boundary: it loads the persisted model/preprocessor and applies them to supplied batch data. app.py provides the runnable web/service surface, while templates/table.html supports HTML rendering of result tables. main.py is an additional application/service launcher or execution layer.
Runtime and Delivery
The system runs on Python, packaged through setup.py with dependencies declared in requirements.txt. It is containerized by Dockerfile and documented to expose port 8000. CI/CD execution is defined in .github/workflows/main.yml. Cloud synchronization capabilities are isolated in networksecurity/cloud/s3_syncer.py, indicating an AWS S3 artifact/data transfer boundary.
Main entry points: training_pipeline.py Training orchestration · data_validation.py Data validation · data_transformation.py Data transformation · model_trainer.py Model trainer
Components 23
Data & Contracts
- Phishing CSV · Raw phishing records.
Network_Data/phisingData.csv - MongoDB · External source and persistence integration.
- Data load script · Populates MongoDB-oriented data storage.
push_data.py - Data schema
data_schema/schema.yaml - Validated data
valid_data/test.csv
Training Pipeline
- Data ingestion
networksecurity/components/data_ingestion.py - Data validation
networksecurity/components/data_validation.py - Data transformation · Builds model-ready features and fitted preprocessing state.
networksecurity/components/data_transformation.py - Data utilities · Serialization and shared data helpers.
networksecurity/utils/main_utils/utils.py - Model trainer · Fits and evaluates the phishing classifier.
networksecurity/components/model_trainer.py - Classification metrics
networksecurity/utils/ml_utils/metric/classification_metric.py - Estimator adapter
networksecurity/utils/ml_utils/model/estimator.py - Training orchestration · Coordinates typed configs and artifacts across training stages.
networksecurity/pipeline/training_pipeline.py - Pipeline entities · Typed stage configuration and handoff objects.
networksecurity/entity/config_entity.py
Serving
- Trained model
final_model/model.pkl - Fitted preprocessor · Keeps inference feature preparation aligned with training.
final_model/preprocessor.pkl - Batch prediction · Loads artifacts and predicts supplied batch data.
networksecurity/pipeline/batch_prediction.py - Service app · Runnable batch-prediction service surface.
app.py - Results table
templates/table.html - Application launcher
main.py
Runtime & Delivery
- S3 sync · AWS S3 artifact and data transfer capability.
networksecurity/cloud/s3_syncer.py - Container runtime · Exposes the service on port 8000.
Dockerfile - CI/CD workflow
.github/workflows/main.yml
Connections 26
- Phishing CSV → Data load script: loads
- Data load script → MongoDB: populates
- MongoDB → Data ingestion: acquires data
- Training orchestration → Pipeline entities: uses
- Training orchestration → Data ingestion: orchestrates
- Data ingestion → Data validation: ingested data
- Training orchestration → Data validation: orchestrates
- Data schema → Data validation: validates against
- Data validation → Validated data: materializes
- Data validation → Data transformation: validated data
- Training orchestration → Data transformation: orchestrates
- Data utilities → Data transformation: supports
- Data transformation → Model trainer: features
- Training orchestration → Model trainer: orchestrates
- Classification metrics → Model trainer: evaluates
- Estimator adapter → Model trainer: wraps estimator
- Model trainer → Trained model: persists
- Data transformation → Fitted preprocessor: persists
- Trained model → Batch prediction: loads
- Fitted preprocessor → Batch prediction: loads
- Service app → Batch prediction: serves
- Service app → Results table: renders
- Application launcher → Service app: launches
- Container runtime → Service app: runs
- CI/CD workflow → Container runtime: builds and deploys
- S3 sync → Trained model: syncs artifacts