How dhanush342/url-phishing-detection works
1. What this repo is
- A phishing URL detection system with two main parts: a browser-based UI for manual testing and a backend inference pipeline that classifies URLs and explains why.
2. Top-level repository shape
- The visible root files are:
- index.html, script.js, style.css for the frontend
- dataset_phishing (1).csv for training data
- run_all.ps1 for one-command setup/run
- The README also describes a backend/ directory containing the FastAPI app, feature extraction, model training, and saved models.
3. Frontend subsystem
- index.html is the app shell.
- style.css defines the presentation layer.
- script.js is the client logic that likely captures a URL, sends it to the backend, and renders prediction/explanation results.
- This is a static browser UI, not a heavy frontend framework.
4. Backend API boundary
- The backend is described as a FastAPI service exposing POST /predict.
- That endpoint is the main integration boundary: the UI submits a raw URL string, and the backend returns the label plus diagnostic data.
5. Core inference pipeline
- The backend architecture starts with feature extraction from a raw URL.
- The README says there are 29 features derived from URL structure, lexical patterns, entropy/NLP-like signals, and heuristic indicators.
6. Hybrid reasoning stack
- Inference is not just a single classifier. It combines:
- an ensemble ML model
- a Bayesian reasoning layer
- a rule engine
- CSP-style consistency checks / graph-style reasoning
- The response is therefore both a prediction and an explanation trace.
7. Model subsystem
- The model zoo includes:
- Random Forest
- Gaussian Naive Bayes
- Gradient Boosting
- Decision Tree
- Soft-voting ensemble as the production model
- Saved model artifacts live under backend/model/ and are loaded during prediction.
8. Explainability outputs
- The API response includes not just label and probability, but also:
- extracted feature values
- fired rules and rule score
- CSP violations and satisfaction score
- Bayesian score
- human-readable explanations
- This makes explainability a first-class subsystem rather than an afterthought.
9. Training and data flow
- dataset_phishing (1).csv is the training/evaluation source.
- train_model.py uses that dataset to build the individual models and the ensemble, then stores the artifacts for inference.
- Training is separate from runtime prediction, which is a clean ML lifecycle boundary.
10. Orchestration and startup
- run_all.ps1 is the operational entry point.
- It coordinates environment setup, model training if needed, backend startup, and opening the browser UI.
- That script is the main “glue” between the data/model pipeline and the interactive demo.
11. Primary runtime/data path
- User enters a URL in the browser UI.
- The frontend sends the URL to the FastAPI backend.
- The backend extracts features, runs ML + reasoning checks, aggregates the result, and returns a structured JSON response.
- The frontend displays the verdict and explanation details.
12. Important architectural boundaries
- Presentation boundary: static browser files vs. server-side inference.
- Model boundary: trained artifacts vs. runtime scoring.
- Reasoning boundary: numeric classification vs. human-readable explanation generation.
- Data boundary: raw URL input vs. engineered features vs. prediction output.
13. What an architecture diagram should emphasize
- A left-to-right flow from URL input → feature extraction → hybrid inference stack → JSON response → UI rendering.
- Show the backend as multiple cooperating modules, not a single black box.
- Show the dataset and training pipeline as a separate offline path feeding the saved model artifacts used by online inference.
Main entry points: script.js Client logic · run_all.ps1 Run all · index.html App shell · dataset_phishing (1).csv Training data
Components 16
Frontend
Static browser UI for manual URL testing and result display.
- App shell · Browser page structure for the phishing checker UI.
index.html - Styles · Visual styling for the static UI.
style.css - Client logic · Captures URL input, calls the backend, and renders verdicts and explanations.
script.js - URL input · Manual URL entered by the user for inspection.
- Result view · Displays prediction, confidence, feature details, and explanation traces.
Backend
Online inference service and explainability stack.
- Predict API · Server boundary exposing POST /predict for URL classification.
- Feature extractor · Derives lexical, structural, entropy, and heuristic signals from a raw URL.
- Ensemble model · Primary classifier used at runtime to score phishing likelihood.
- Bayesian layer · Adds probabilistic reasoning on top of the classifier output.
- Rule engine · Applies phishing rules and produces fired rules plus rule score.
- CSP checks · Validates consistency constraints and records violations or satisfaction.
- Explanations · Combines model output, rules, Bayesian score, and checks into human-readable diagnostics.
Offline ML
Training pipeline and persisted model artifacts.
- Training data · Labeled phishing dataset used for model training and evaluation.
dataset_phishing (1).csv - Train pipeline · Builds the individual classifiers and the production ensemble from the dataset.
- Saved models · Persisted model artifacts loaded by the backend during inference.
Orchestration
One-command setup and runtime entry point.
- Run all · Sets up the environment, trains if needed, starts the backend, and opens the UI.
run_all.ps1
Connections 21
- URL input → Client logic: submit URL · User enters a URL in the browser UI.
- Client logic → Predict API: POST /predict · Client sends the raw URL to the backend inference API.
- Predict API → Feature extractor: extract features · Backend converts the URL into engineered feature values.
- Feature extractor → Ensemble model: score features · Feature vector is passed to the production classifier.
- Feature extractor → Rule engine: evaluate rules · Heuristics inspect extracted URL signals.
- Feature extractor → CSP checks: check constraints · Consistency checks validate URL-derived conditions.
- Ensemble model → Bayesian layer: probability input · Model score informs Bayesian reasoning.
- Ensemble model → Explanations: prediction · Classifier output contributes to the final response.
- Rule engine → Explanations: rule trace · Fired rules and rule score are included in the explanation payload.
- CSP checks → Explanations: violations · Constraint results are summarized for the response.
- Bayesian layer → Explanations: bayes score · Bayesian reasoning is folded into the output.
- Explanations → Client logic: JSON response · Backend returns label, confidence, feature values, and explanations.
- Client logic → Result view: render result · Frontend displays the verdict and diagnostic details.
- Training data → Train pipeline: train on · Offline training consumes the labeled phishing dataset.
- Train pipeline → Saved models: persist artifacts · Trained models are saved for runtime scoring.
- Saved models → Ensemble model: load at runtime · Backend loads saved artifacts during prediction.
- Run all → Train pipeline: orchestrate training · Script triggers model training when required.
- Run all → Predict API: start backend · Script launches the FastAPI inference service.
- Run all → App shell: open UI · Script brings up the browser demo.
- App shell → Styles: uses styles · The app shell is styled by the CSS layer.
- App shell → Client logic: loads logic · The page loads the browser client code.