How mabdullah005/networksecurit works
1. This repository is organized around two clear boundaries: an offline ML training pipeline and an online inference/serving layer. The training side builds and versions the phishing-detection model; the serving side loads the saved artifacts and classifies user-supplied URLs in real time.
2. The core package is NetworkSecurity/, which contains the reusable pipeline logic. The main training stages are split into components/data_ingestion.py, data_validation.py, data_transformation.py, and model_trainer.py. That is the primary end-to-end ETL/ML flow in the project.
3. NetworkSecurity/entity/ defines the pipeline’s data contracts. config_entity.py and artifact_entity.py are where run-time configuration and intermediate outputs are modeled, so each stage passes structured artifact metadata to the next stage rather than raw ad hoc values.
4. NetworkSecurity/constant/ holds pipeline constants, especially under traning_pipeline/ (note the typo in the folder name). This suggests the pipeline behavior is centralized through configuration rather than hardcoded in each component.
5. NetworkSecurity/utils/ contains shared infrastructure used by every stage: logging, exception handling, generic file/utils helpers, metric calculation, and a model wrapper/estimator abstraction. These utilities form the “platform layer” for the ML workflow and keep the pipeline stages thin.
6. The training data path starts with network_data/phisingData.csv, goes through validation against data_schema/schema.yaml, and produces validated artifacts such as vaild_data/test.csv. This schema-first design is important for diagramming the data contract between ingestion and validation.
7. The trained model and preprocessing pipeline are persisted in final_model/model.pkl and final_model/preprocessor.pkl. Those files are the handoff point between offline training and online prediction; the serving layer depends on them directly.
8. Prediction-time feature extraction is separated from training-time preprocessing. predication_output/feature_extraction.py appears to compute URL/HTML features from raw user input, while predication_output/output.csv is likely a local inference artifact for batch or test runs. This is a distinct boundary worth showing in the architecture.
9. The application entrypoints at the repo root (app.py and main.py) likely connect the web/API layer to the prediction pipeline and templates under template/. The README says the project uses FastAPI and Streamlit, so the diagram should include a user-facing interface that calls the model-serving code rather than the training pipeline.
10. NetworkSecurity/pipeline/traning_pipeline.py and batch_predication.py are the orchestrators. The training pipeline coordinates the stage sequence, while batch prediction handles offline scoring of multiple inputs. These are the control planes above the lower-level components.
11. External state and operational logging are part of the architecture. logs/ stores runtime logs, push_data.py and test_mongo.py indicate MongoDB Atlas integration for storing structured data/logging, and NetworkSecurity/cloud/ suggests cloud-specific integration points.
12. The project is packaged and deployable: Dockerfile, requirements.txt, setup.py, and .github/workflows/main.yaml indicate containerized deployment and CI/CD automation. The README also mentions AWS EC2, S3, DVC, and MLflow, so the intended production architecture includes artifact tracking and cloud deployment around the core Python pipeline.
13. For an architecture diagram, the most important flow is: raw URL/data input → ingestion → validation against schema → transformation/feature engineering → model training → saved artifacts → API/UI inference → prediction output. Separate side channels should show logs, MongoDB storage, and CI/CD/container packaging supporting the main flow.
Main entry points: traning_pipeline.py Training pipeline · app.py App entry · data_validation.py Data validation · model_trainer.py Model trainer
Components 27
Offline training
End-to-end ML pipeline that ingests data, validates schema, transforms features, and trains the phishing model.
- Training pipeline · Coordinates the offline training stages and model artifact creation.
NetworkSecurity/pipeline/traning_pipeline.py - Data ingestion · Loads source data into the training pipeline.
NetworkSecurity/components/data_ingestion.py - Data validation · Checks incoming data against the schema before downstream use.
NetworkSecurity/components/data_validation.py - Data transform · Cleans and engineers features for model training.
NetworkSecurity/components/data_transformation.py - Model trainer · Trains the phishing detection model and persists learned artifacts.
NetworkSecurity/components/model_trainer.py
Online serving
User-facing inference path that extracts URL features and returns predictions through the app entrypoints.
- Batch predict · Runs offline scoring for multiple inputs using saved artifacts.
NetworkSecurity/pipeline/batch_predication.py - Feature extraction · Derives prediction-time features from raw URL or HTML input.
predication_output/feature_extraction.py - App entry · Connects the user interface or API layer to prediction logic.
app.py - Main entry · Secondary application startup path and integration point.
main.py - UI templates · HTML templates used by the user-facing interface.
template/index.html
Shared platform
Common entities, constants, utilities, logging, and exception handling used across pipeline stages.
- Artifacts · Models the outputs and handoffs between pipeline stages.
NetworkSecurity/entity/artifact_entity.py - Config entities · Defines runtime configuration for pipeline execution.
NetworkSecurity/entity/config_entity.py - Pipeline constants · Centralized constants that parameterize the training pipeline.
NetworkSecurity/constant/traning_pipeline - Utils · Shared file, logging, and helper utilities used by the pipeline.
NetworkSecurity/utils/main_utils/utils.py - Metrics · Classification metric helpers used during model assessment.
NetworkSecurity/utils/ml_utils/metric/classification_metrics.py - Estimator · Reusable model abstraction for loading and inference.
NetworkSecurity/utils/ml_utils/model/estimator.py - Logging · Application logging used across stages and runtime paths.
NetworkSecurity/logging/logger.py - Exceptions · Custom exception handling for pipeline and runtime failures.
NetworkSecurity/expection/expection.py
Ops and packaging
Persistent artifacts and deployment/automation files supporting the application.
- Schema · Validation schema for the incoming phishing dataset.
data_schema/schema.yaml - Source data · Raw training dataset used by ingestion.
network_data/phisingData.csv - Validated data · Schema-checked dataset emitted by validation.
vaild_data/test.csv - Model artifact · Serialized trained model used for inference.
final_model/model.pkl - Preprocessor · Serialized preprocessing pipeline used at prediction time.
final_model/preprocessor.pkl - Prediction output · Local inference output artifact for batch or test runs.
predication_output/output.csv - Logs · Persisted execution logs from training and serving runs.
logs/08_02_2025_14_21_06.log - CI workflow · GitHub Actions workflow for build and validation automation.
.github/workflows/main.yaml - Docker image · Container definition for packaging the application.
Dockerfile
Connections 30
- Training pipeline → Data ingestion: runs · The training pipeline starts with data ingestion.
- Data ingestion → Source data: reads · Raw training data is loaded from the source dataset.
- Data ingestion → Data validation: passes · Ingested data moves into validation.
- Data validation → Schema: checks · Validation compares data against the schema contract.
- Data validation → Validated data: writes · Validated records are persisted for downstream stages.
- Data validation → Data transform: feeds · Only validated data proceeds to transformation.
- Data transform → Data validation: depends on · Transformation expects schema-clean input from validation.
- Data transform → Model trainer: produces · Transformed features are used for training.
- Model trainer → Model artifact: persists · The trained model is serialized for later inference.
- Model trainer → Preprocessor: persists · The preprocessing pipeline is saved alongside the model.
- Model trainer → Metrics: evaluates · Training uses shared metric helpers for assessment.
- Training pipeline → Config entities: loads · Pipeline execution is driven by structured config.
- Training pipeline → Artifacts: emits · Stages exchange typed artifact metadata.
- Training pipeline → Pipeline constants: uses · Pipeline behavior is parameterized by constants.
- Training pipeline → Utils: relies on · Common utilities support file handling and helpers.
- Training pipeline → Logging: logs to · Pipeline execution is recorded through shared logging.
- Training pipeline → Exceptions: handles · Failures are normalized through shared exception handling.
- Batch predict → Feature extraction: calls · Batch scoring extracts features before prediction.
- Feature extraction → Estimator: prepares for · Extracted features are consumed by the inference wrapper.
- Estimator → Model artifact: loads · The estimator reads the trained model artifact.
- Estimator → Preprocessor: loads · The estimator reads the saved preprocessing pipeline.
- App entry → Feature extraction: invokes · The app entrypoint routes user input into feature extraction.
- App entry → Estimator: predicts · The serving layer uses the estimator for live classification.
- App entry → UI templates: renders · The interface returns HTML views from templates.
- Main entry → App entry: boots · Main startup path connects to the app layer.
- App entry → Logs: records · Runtime requests and errors are logged.
- CI workflow → Docker image: packages · CI supports containerized build and deployment.
- CI workflow → Model artifact: validates · Automation can depend on produced artifacts.
- Docker image → App entry: runs · Container image packages the serving application.
- Logging → Logs: writes · Logging infrastructure writes to the log store.