# mabdullah005/networksecurit architecture

> Architecture diagram of the GitHub repository mabdullah005/networksecurit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mabdullah005/networksecurit
- Repository: https://github.com/mabdullah005/networksecurit

## Overview

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: [`NetworkSecurity/pipeline/traning_pipeline.py`](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/pipeline/traning_pipeline.py) (Training pipeline), [`app.py`](https://github.com/mabdullah005/networksecurit/blob/main/app.py) (App entry), [`NetworkSecurity/components/data_validation.py`](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_validation.py) (Data validation), [`NetworkSecurity/components/model_trainer.py`](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/model_trainer.py) (Model trainer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_training["Offline training"]
  node_node_training_orchestrator["Training pipeline<br/>orchestrator"]
  node_node_data_ingestion["Data ingestion<br/>pipeline stage<br/>[data_ingestion.py]"]
  node_node_data_validation["Data validation<br/>pipeline stage<br/>[data_validation.py]"]
  node_node_data_transformation["Data transform<br/>pipeline stage"]
  node_node_model_trainer["Model trainer<br/>pipeline stage<br/>[model_trainer.py]"]
end

subgraph group_group_serving["Online serving"]
  node_node_batch_prediction["Batch predict<br/>orchestrator"]
  node_node_feature_extraction["Feature extraction<br/>feature builder"]
  node_node_app_entry["App entry<br/>web entrypoint<br/>[app.py]"]
  node_node_main_entry["Main entry<br/>app entrypoint<br/>[main.py]"]
  node_node_templates["UI templates<br/>presentation<br/>[index.html]"]
end

subgraph group_group_shared["Shared platform"]
  node_node_artifact_entity["Artifacts<br/>data contract<br/>[artifact_entity.py]"]
  node_node_config_entity["Config entities<br/>data contract<br/>[config_entity.py]"]
  node_node_constants["Pipeline constants<br/>config"]
  node_node_utils["Utils<br/>[utils.py]"]
  node_node_metrics["Metrics<br/>evaluation"]
  node_node_estimator["Estimator<br/>model wrapper<br/>[estimator.py]"]
  node_node_logging["Logging<br/>observability<br/>[logger.py]"]
  node_node_exceptions["Exceptions<br/>error handling<br/>[expection.py]"]
end

subgraph group_group_ops["Ops and packaging"]
  node_node_schema["Schema<br/>data contract<br/>[schema.yaml]"]
  node_node_source_data[("Source data<br/>dataset<br/>[phisingData.csv]")]
  node_node_validated_data[("Validated data<br/>dataset<br/>[test.csv]")]
  node_node_model_artifact["Model artifact<br/>[model.pkl]"]
  node_node_preprocessor_artifact["Preprocessor<br/>artifact<br/>[preprocessor.pkl]"]
  node_node_prediction_output["Prediction output<br/>result<br/>[output.csv]"]
  node_node_logs["Logs"]
  node_node_ci["CI workflow<br/>automation<br/>[main.yaml]"]
  node_node_dockerfile["Docker image<br/>deployment"]
end

node_node_training_orchestrator -->|"runs"| node_node_data_ingestion
node_node_data_ingestion -->|"reads"| node_node_source_data
node_node_data_ingestion -->|"passes"| node_node_data_validation
node_node_data_validation -->|"checks"| node_node_schema
node_node_data_validation -->|"writes"| node_node_validated_data
node_node_data_validation -->|"feeds"| node_node_data_transformation
node_node_data_transformation -.->|"depends on"| node_node_data_validation
node_node_data_transformation -->|"produces"| node_node_model_trainer
node_node_model_trainer -->|"persists"| node_node_model_artifact
node_node_model_trainer -->|"persists"| node_node_preprocessor_artifact
node_node_model_trainer -->|"evaluates"| node_node_metrics
node_node_training_orchestrator -->|"loads"| node_node_config_entity
node_node_training_orchestrator -->|"emits"| node_node_artifact_entity
node_node_training_orchestrator -->|"uses"| node_node_constants
node_node_training_orchestrator -->|"relies on"| node_node_utils
node_node_training_orchestrator -->|"logs to"| node_node_logging
node_node_training_orchestrator -->|"handles"| node_node_exceptions
node_node_batch_prediction -->|"calls"| node_node_feature_extraction
node_node_feature_extraction -->|"prepares for"| node_node_estimator
node_node_estimator -->|"loads"| node_node_model_artifact
node_node_estimator -->|"loads"| node_node_preprocessor_artifact
node_node_app_entry -->|"invokes"| node_node_feature_extraction
node_node_app_entry -->|"predicts"| node_node_estimator
node_node_app_entry -->|"renders"| node_node_templates
node_node_main_entry -->|"boots"| node_node_app_entry
node_node_app_entry -->|"records"| node_node_logs
node_node_ci -->|"packages"| node_node_dockerfile
node_node_ci -.->|"validates"| node_node_model_artifact
node_node_dockerfile -->|"runs"| node_node_app_entry
node_node_logging -->|"writes"| node_node_logs

click node_node_training_orchestrator "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/pipeline/traning_pipeline.py"
click node_node_data_ingestion "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_ingestion.py"
click node_node_data_validation "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_validation.py"
click node_node_data_transformation "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_transformation.py"
click node_node_model_trainer "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/model_trainer.py"
click node_node_batch_prediction "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/pipeline/batch_predication.py"
click node_node_feature_extraction "https://github.com/mabdullah005/networksecurit/blob/main/predication_output/feature_extraction.py"
click node_node_app_entry "https://github.com/mabdullah005/networksecurit/blob/main/app.py"
click node_node_main_entry "https://github.com/mabdullah005/networksecurit/blob/main/main.py"
click node_node_templates "https://github.com/mabdullah005/networksecurit/blob/main/template/index.html"
click node_node_artifact_entity "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/entity/artifact_entity.py"
click node_node_config_entity "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/entity/config_entity.py"
click node_node_constants "https://github.com/mabdullah005/networksecurit/tree/main/NetworkSecurity/constant/traning_pipeline"
click node_node_utils "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/utils/main_utils/utils.py"
click node_node_metrics "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/utils/ml_utils/metric/classification_metrics.py"
click node_node_estimator "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/utils/ml_utils/model/estimator.py"
click node_node_logging "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/logging/logger.py"
click node_node_exceptions "https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/expection/expection.py"
click node_node_schema "https://github.com/mabdullah005/networksecurit/blob/main/data_schema/schema.yaml"
click node_node_source_data "https://github.com/mabdullah005/networksecurit/blob/main/network_data/phisingData.csv"
click node_node_validated_data "https://github.com/mabdullah005/networksecurit/blob/main/vaild_data/test.csv"
click node_node_model_artifact "https://github.com/mabdullah005/networksecurit/blob/main/final_model/model.pkl"
click node_node_preprocessor_artifact "https://github.com/mabdullah005/networksecurit/blob/main/final_model/preprocessor.pkl"
click node_node_prediction_output "https://github.com/mabdullah005/networksecurit/blob/main/predication_output/output.csv"
click node_node_logs "https://github.com/mabdullah005/networksecurit/blob/main/logs/08_02_2025_14_21_06.log"
click node_node_ci "https://github.com/mabdullah005/networksecurit/blob/main/.github/workflows/main.yaml"
click node_node_dockerfile "https://github.com/mabdullah005/networksecurit/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_training_orchestrator,node_node_data_ingestion,node_node_data_validation,node_node_data_transformation,node_node_model_trainer toneBlue
class node_node_batch_prediction,node_node_feature_extraction,node_node_app_entry,node_node_main_entry,node_node_templates toneAmber
class node_node_artifact_entity,node_node_config_entity,node_node_constants,node_node_utils,node_node_metrics,node_node_estimator,node_node_logging,node_node_exceptions toneMint
class node_node_schema,node_node_source_data,node_node_validated_data,node_node_model_artifact,node_node_preprocessor_artifact,node_node_prediction_output,node_node_logs,node_node_ci,node_node_dockerfile toneRose
```

## Components

### Offline training

End-to-end ML pipeline that ingests data, validates schema, transforms features, and trains the phishing model.

- [Training pipeline](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/pipeline/traning_pipeline.py): orchestrator · Coordinates the offline training stages and model artifact creation. · `NetworkSecurity/pipeline/traning_pipeline.py`
- [Data ingestion](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_ingestion.py): pipeline stage · Loads source data into the training pipeline. · `NetworkSecurity/components/data_ingestion.py`
- [Data validation](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_validation.py): pipeline stage · Checks incoming data against the schema before downstream use. · `NetworkSecurity/components/data_validation.py`
- [Data transform](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/data_transformation.py): pipeline stage · Cleans and engineers features for model training. · `NetworkSecurity/components/data_transformation.py`
- [Model trainer](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/components/model_trainer.py): pipeline stage · 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](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/pipeline/batch_predication.py): orchestrator · Runs offline scoring for multiple inputs using saved artifacts. · `NetworkSecurity/pipeline/batch_predication.py`
- [Feature extraction](https://github.com/mabdullah005/networksecurit/blob/main/predication_output/feature_extraction.py): feature builder · Derives prediction-time features from raw URL or HTML input. · `predication_output/feature_extraction.py`
- [App entry](https://github.com/mabdullah005/networksecurit/blob/main/app.py): web entrypoint · Connects the user interface or API layer to prediction logic. · `app.py`
- [Main entry](https://github.com/mabdullah005/networksecurit/blob/main/main.py): app entrypoint · Secondary application startup path and integration point. · `main.py`
- [UI templates](https://github.com/mabdullah005/networksecurit/blob/main/template/index.html): presentation · 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](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/entity/artifact_entity.py): data contract · Models the outputs and handoffs between pipeline stages. · `NetworkSecurity/entity/artifact_entity.py`
- [Config entities](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/entity/config_entity.py): data contract · Defines runtime configuration for pipeline execution. · `NetworkSecurity/entity/config_entity.py`
- [Pipeline constants](https://github.com/mabdullah005/networksecurit/tree/main/NetworkSecurity/constant/traning_pipeline): config · Centralized constants that parameterize the training pipeline. · `NetworkSecurity/constant/traning_pipeline`
- [Utils](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/utils/main_utils/utils.py): platform utils · Shared file, logging, and helper utilities used by the pipeline. · `NetworkSecurity/utils/main_utils/utils.py`
- [Metrics](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/utils/ml_utils/metric/classification_metrics.py): evaluation · Classification metric helpers used during model assessment. · `NetworkSecurity/utils/ml_utils/metric/classification_metrics.py`
- [Estimator](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/utils/ml_utils/model/estimator.py): model wrapper · Reusable model abstraction for loading and inference. · `NetworkSecurity/utils/ml_utils/model/estimator.py`
- [Logging](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/logging/logger.py): observability · Application logging used across stages and runtime paths. · `NetworkSecurity/logging/logger.py`
- [Exceptions](https://github.com/mabdullah005/networksecurit/blob/main/NetworkSecurity/expection/expection.py): error handling · 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](https://github.com/mabdullah005/networksecurit/blob/main/data_schema/schema.yaml): data contract · Validation schema for the incoming phishing dataset. · `data_schema/schema.yaml`
- [Source data](https://github.com/mabdullah005/networksecurit/blob/main/network_data/phisingData.csv): dataset · Raw training dataset used by ingestion. · `network_data/phisingData.csv`
- [Validated data](https://github.com/mabdullah005/networksecurit/blob/main/vaild_data/test.csv): dataset · Schema-checked dataset emitted by validation. · `vaild_data/test.csv`
- [Model artifact](https://github.com/mabdullah005/networksecurit/blob/main/final_model/model.pkl): artifact · Serialized trained model used for inference. · `final_model/model.pkl`
- [Preprocessor](https://github.com/mabdullah005/networksecurit/blob/main/final_model/preprocessor.pkl): artifact · Serialized preprocessing pipeline used at prediction time. · `final_model/preprocessor.pkl`
- [Prediction output](https://github.com/mabdullah005/networksecurit/blob/main/predication_output/output.csv): result · Local inference output artifact for batch or test runs. · `predication_output/output.csv`
- [Logs](https://github.com/mabdullah005/networksecurit/blob/main/logs/08_02_2025_14_21_06.log): runtime logs · Persisted execution logs from training and serving runs. · `logs/08_02_2025_14_21_06.log`
- [CI workflow](https://github.com/mabdullah005/networksecurit/blob/main/.github/workflows/main.yaml): automation · GitHub Actions workflow for build and validation automation. · `.github/workflows/main.yaml`
- [Docker image](https://github.com/mabdullah005/networksecurit/tree/main/Dockerfile): deployment · Container definition for packaging the application. · `Dockerfile`

## Connections

- 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.
