# kratospidey/phisdomjs architecture

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

- Interactive diagram: https://gitdiagram.com/kratospidey/phisdomjs
- Repository: https://github.com/kratospidey/phisdomjs

## Overview

1. **Project purpose and top-level shape**
   - `phisdom` is a phishing-page detection system centered on three signal families: **URL**, **DOM/markup**, and **JavaScript**.
   - The repo is organized as a research-to-production pipeline: data collection and normalization, feature extraction, model training, calibration/fusion, evaluation, and export/validation.

2. **Core Python package boundary**
   - The main runtime code lives under `src/phisdom`.
   - This package is the stable API boundary for feature extraction, dataset handling, model definitions, calibration, metrics, and a small CLI demo.
   - The rest of the repo is mostly orchestration: scripts, configs, tooling, and validation harnesses.

3. **Data and ingestion layer**
   - `src/phisdom/data` handles dataset schema, normalization, loaders, multimodal joins, and modality-specific helpers.
   - The repository keeps durable state in `data/`, including split definitions, seed data, and caches for **DNS**, **RDAP**, and **TLS** lookups.
   - This implies the pipeline enriches URLs/domains with network and registration metadata before modeling.

4. **Feature extraction layer**
   - `src/phisdom/features` contains URL feature extraction and related extractors.
   - The README confirms URL features include **character n-grams, entropy, and length**.
   - Separate alphabet/token resources under `alphabets/` suggest frozen vocabularies or token sets used by text/URL/JS pipelines.

5. **Modeling layer: per-modality heads**
   - `src/phisdom/models/heads.py` and the training scripts indicate independent modality-specific classifiers:
     - `train_url_head.py`
     - `train_text_head.py`
     - `train_markup.py`
     - `train_js_head.py`
     - plus specialized variants like `train_dom_gcn.py`
   - This is a “many experts” architecture: each modality can be trained, evaluated, and calibrated separately.

6. **Fusion and ensemble layer**
   - `src/phisdom/models/fusion.py`, `fusion_new.py`, and `fusion_old.py` show multiple generations of ensemble logic.
   - Scripts such as `fuse_heads.py`, `meta_fuse_heads.py`, `train_fusion_xattn.py`, and `compare_stacking.py` suggest the system combines modality outputs using stacking, cross-attention, or other learned fusion strategies.
   - This fusion layer is the main decision boundary for final phishing scores.

7. **Calibration and thresholding**
   - Calibration is a first-class subsystem in both `src/phisdom/calibration.py` and `src/phisdom/models/calibration.py`.
   - The repo includes scripts for refitting and exporting calibrated models and operating thresholds.
   - This indicates the architecture separates raw model scores from deployment-ready probabilities and decision thresholds.

8. **Pipeline orchestration and batch jobs**
   - The `scripts/` directory is the operational backbone.
   - It covers crawling, ingestion, dataset merging, split creation, augmentation, head training, fusion fitting, evaluation, plotting, reporting, and CI checks.
   - Notable stages include `crawl_*`, `fetch_feeds.py`, `ingest_phish_only.py`, `make_splits.py`, `augment_*`, `evaluate_enhanced.py`, `report_eval.py`, and `export_predictions.py`.

9. **Crawler and external-data boundary**
   - `configs/feeds.yaml` and the `crawl_*` scripts indicate external feed ingestion and browser-based page collection.
   - `Makefile` knobs like `CRAWL_CONCURRENCY`, `TLS_TIMEOUT`, `DNS_TIMEOUT`, `MOBILE_PROFILE`, and `GPU` show the crawler is an explicit subsystem with tunable runtime behavior.
   - The system also supports mobile-profile reloading to detect cloaking deltas, so crawl-time behavior is part of the signal.

10. **Data quality, augmentation, and repair**
   - Several scripts focus on dataset integrity: `verify_splits.py`, `repair_ids.py`, `backfill_*`, `auto_backfill.py`, and `audit_*`.
   - Augmentation and hard-negative generation are also built in (`augment_js.py`, `augment_with_hard_negatives.py`, `prepare_hard_negatives.py`).
   - This suggests the repo treats label quality, missing fields, and modality gaps as core architectural concerns rather than afterthoughts.

11. **Evaluation, diagnostics, and CI gates**
   - `tests/` contains unit and integration coverage for calibration, fusion, normalization, token assembly, metrics, and pipeline correctness.
   - Validation scripts like `validate_pipeline.py`, `validate_all_fixes.py`, and `scripts/ci_gate.py` indicate a formal quality gate around dataset and model changes.
   - The repository also includes anomaly detection and coverage-audit scripts to find blind spots in modality availability and JS coverage.

12. **Utilities, exports, and packaging**
   - `src/phisdom/utils` holds alignment, split handling, and prediction standardization helpers.
   - `tools/` contains operational utilities such as URL normalization and DOM-graph backfilling.
   - Packaging is standard Python tooling (`pyproject.toml`, `requirements.txt`), with a lightweight CLI entrypoint in `src/phisdom/cli.py` for demo/inference use.

13. **Mental model for an architecture diagram**
   - The cleanest diagram is a left-to-right flow:
     - **External feeds / crawled pages / cached metadata**
     - → **normalization and enrichment**
     - → **modality-specific feature extraction**
     - → **per-head training/inference**
     - → **fusion + calibration**
     - → **evaluation, export, and CI validation**
   - The key boundary is between the **offline data/training pipeline** and the **model-serving-facing scoring path**, with calibration and threshold export bridging them.

Main entry points: [`src/phisdom/models/fusion.py`](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/models/fusion.py) (Fusion), [`src/phisdom/models/heads.py`](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/models/heads.py) (Heads), [`src/phisdom/data/multimodal.py`](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/multimodal.py) (Multimodal), [`src/phisdom/calibration.py`](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/calibration.py) (Calibration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_ingest["Data & ingest"]
  node_n_feeds["Feeds<br/>external sources<br/>[feeds.yaml]"]
  node_n_caches[("Caches<br/>lookup state<br/>[dns_cache.json]")]
  node_n_dataset[("Dataset<br/>corpus<br/>[seed.csv]")]
end

subgraph group_grp_runtime["Core runtime"]
  node_n_normalize["Normalize<br/>data prep<br/>[normalize.py]"]
  node_n_schema["Schema<br/>[schema.py]"]
  node_n_loader["Loader<br/>[loader.py]"]
  node_n_multimodal["Multimodal<br/>joins<br/>[multimodal.py]"]
  node_n_urlfeat["URL features<br/>feature extractor<br/>[url.py]"]
  node_n_extractors["Extractors<br/>feature API<br/>[extractors.py]"]
  node_n_heads["Heads<br/>modality classifiers<br/>[heads.py]"]
  node_n_domgcn["DOM GCN<br/>graph head<br/>[train_dom_gcn.py]"]
  node_n_fusion["Fusion<br/>ensemble layer<br/>[fusion.py]"]
  node_n_calib["Calibration<br/>[calibration.py]"]
  node_n_metrics["Metrics<br/>evaluation<br/>[metrics.py]"]
  node_n_cli["CLI<br/>demo/inference<br/>[cli.py]"]
end

subgraph group_grp_pipeline["Training pipeline"]
  node_n_crawl["Crawl<br/>page collection"]
  node_n_ingest["Ingest<br/>dataset build"]
  node_n_train["Train heads<br/>model training<br/>[train_url_head.py]"]
  node_n_fuse["Fuse<br/>model selection"]
  node_n_eval["Evaluate<br/>reporting"]
  node_n_export["Export<br/>deployment artifacts"]
end

subgraph group_grp_quality["Validation"]
  node_n_tests["Tests<br/>integration suite"]
  node_n_validate["CI gate<br/>quality gate"]
end

node_n_feeds -->|"seed crawl"| node_n_crawl
node_n_crawl -->|"raw pages"| node_n_ingest
node_n_caches -->|"enrich"| node_n_normalize
node_n_dataset -->|"inputs"| node_n_normalize
node_n_normalize -->|"shape"| node_n_schema
node_n_schema -->|"load"| node_n_loader
node_n_loader -->|"join"| node_n_multimodal
node_n_multimodal -->|"URL path"| node_n_urlfeat
node_n_multimodal -->|"shared view"| node_n_extractors
node_n_urlfeat -->|"features"| node_n_heads
node_n_extractors -->|"features"| node_n_heads
node_n_heads -->|"specialize"| node_n_domgcn
node_n_heads -->|"logits"| node_n_fusion
node_n_domgcn -->|"graph logits"| node_n_fusion
node_n_fusion -->|"calibrate"| node_n_calib
node_n_calib -->|"score"| node_n_metrics
node_n_metrics -->|"report"| node_n_eval
node_n_calib -->|"thresholds"| node_n_export
node_n_fusion -->|"predictions"| node_n_export
node_n_train -->|"fit"| node_n_heads
node_n_fuse -->|"fit"| node_n_fusion
node_n_eval -->|"gate"| node_n_validate
node_n_tests -->|"assert"| node_n_validate
node_n_cli -.->|"infer"| node_n_fusion

click node_n_feeds "https://github.com/kratospidey/phisdomjs/blob/main/configs/feeds.yaml"
click node_n_caches "https://github.com/kratospidey/phisdomjs/blob/main/data/dns_cache.json"
click node_n_dataset "https://github.com/kratospidey/phisdomjs/blob/main/data/seed.csv"
click node_n_normalize "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/normalize.py"
click node_n_schema "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/schema.py"
click node_n_loader "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/loader.py"
click node_n_multimodal "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/multimodal.py"
click node_n_urlfeat "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/features/url.py"
click node_n_extractors "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/features/extractors.py"
click node_n_heads "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/models/heads.py"
click node_n_domgcn "https://github.com/kratospidey/phisdomjs/blob/main/scripts/train_dom_gcn.py"
click node_n_fusion "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/models/fusion.py"
click node_n_calib "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/calibration.py"
click node_n_metrics "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/metrics.py"
click node_n_cli "https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/cli.py"
click node_n_crawl "https://github.com/kratospidey/phisdomjs/blob/main/scripts/crawl_playwright.py"
click node_n_ingest "https://github.com/kratospidey/phisdomjs/blob/main/scripts/ingest_phish_only.py"
click node_n_train "https://github.com/kratospidey/phisdomjs/blob/main/scripts/train_url_head.py"
click node_n_fuse "https://github.com/kratospidey/phisdomjs/blob/main/scripts/train_fusion_xattn.py"
click node_n_eval "https://github.com/kratospidey/phisdomjs/blob/main/scripts/evaluate_enhanced.py"
click node_n_export "https://github.com/kratospidey/phisdomjs/blob/main/scripts/export_predictions.py"
click node_n_tests "https://github.com/kratospidey/phisdomjs/blob/main/tests/test_pipeline_integration.py"
click node_n_validate "https://github.com/kratospidey/phisdomjs/blob/main/validate_pipeline.py"

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_n_feeds,node_n_caches,node_n_dataset toneBlue
class node_n_normalize,node_n_schema,node_n_loader,node_n_multimodal,node_n_urlfeat,node_n_extractors,node_n_heads,node_n_domgcn,node_n_fusion,node_n_calib,node_n_metrics,node_n_cli toneAmber
class node_n_crawl,node_n_ingest,node_n_train,node_n_fuse,node_n_eval,node_n_export toneMint
class node_n_tests,node_n_validate toneRose
```

## Components

### Data & ingest

External feeds, crawls, caches, and dataset assembly.

- [Feeds](https://github.com/kratospidey/phisdomjs/blob/main/configs/feeds.yaml): external sources · Feed configs and seed inputs for ingestion and crawl scheduling. · `configs/feeds.yaml`
- [Caches](https://github.com/kratospidey/phisdomjs/blob/main/data/dns_cache.json): lookup state · Durable DNS, RDAP, TLS, and split caches used during enrichment. · `data/dns_cache.json`
- [Dataset](https://github.com/kratospidey/phisdomjs/blob/main/data/seed.csv): corpus · Seed data and split definitions that anchor training and evaluation. · `data/seed.csv`

### Core runtime

Stable Python package for data, features, models, metrics, and CLI.

- [Normalize](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/normalize.py): data prep · Schema normalization, alignment, and multimodal joins. · `src/phisdom/data/normalize.py`
- [Schema](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/schema.py): dataset schema · Canonical record layout for samples and labels. · `src/phisdom/data/schema.py`
- [Loader](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/loader.py): dataset loader · Dataset loading and batching entrypoint for training and inference. · `src/phisdom/data/loader.py`
- [Multimodal](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/data/multimodal.py): joins · Combines URL, DOM/markup, text, and JS views into one sample. · `src/phisdom/data/multimodal.py`
- [URL features](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/features/url.py): feature extractor · Character n-grams, entropy, length, and related URL signals. · `src/phisdom/features/url.py`
- [Extractors](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/features/extractors.py): feature API · Shared feature extraction interfaces and helpers. · `src/phisdom/features/extractors.py`
- [Heads](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/models/heads.py): modality classifiers · Independent per-modality classifiers and head definitions. · `src/phisdom/models/heads.py`
- [DOM GCN](https://github.com/kratospidey/phisdomjs/blob/main/scripts/train_dom_gcn.py): graph head · Specialized DOM/markup graph-based head variant. · `scripts/train_dom_gcn.py`
- [Fusion](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/models/fusion.py): ensemble layer · Learned combination of modality outputs across fusion generations. · `src/phisdom/models/fusion.py`
- [Calibration](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/calibration.py): score calibration · Probability calibration and thresholding for deployment-ready scores. · `src/phisdom/calibration.py`
- [Metrics](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/metrics.py): evaluation · Shared metrics and scoring utilities. · `src/phisdom/metrics.py`
- [CLI](https://github.com/kratospidey/phisdomjs/blob/main/src/phisdom/cli.py): demo/inference · Lightweight command-line entrypoint for runtime usage. · `src/phisdom/cli.py`

### Training pipeline

Operational scripts for crawl, train, fuse, calibrate, and export.

- [Crawl](https://github.com/kratospidey/phisdomjs/blob/main/scripts/crawl_playwright.py): page collection · Browser-based crawling and external-page acquisition. · `scripts/crawl_playwright.py`
- [Ingest](https://github.com/kratospidey/phisdomjs/blob/main/scripts/ingest_phish_only.py): dataset build · Feed fetching, phish-only ingestion, and dataset merging. · `scripts/ingest_phish_only.py`
- [Train heads](https://github.com/kratospidey/phisdomjs/blob/main/scripts/train_url_head.py): model training · Per-modality training scripts for URL, text, markup, and JS heads. · `scripts/train_url_head.py`
- [Fuse](https://github.com/kratospidey/phisdomjs/blob/main/scripts/train_fusion_xattn.py): model selection · Stacking, cross-attention, and meta-fusion training scripts. · `scripts/train_fusion_xattn.py`
- [Evaluate](https://github.com/kratospidey/phisdomjs/blob/main/scripts/evaluate_enhanced.py): reporting · Evaluation, plotting, anomaly review, and KPI reporting. · `scripts/evaluate_enhanced.py`
- [Export](https://github.com/kratospidey/phisdomjs/blob/main/scripts/export_predictions.py): deployment artifacts · Prediction export and operating-threshold export for downstream use. · `scripts/export_predictions.py`

### Validation

Tests, audits, and CI gates for pipeline and model correctness.

- [Tests](https://github.com/kratospidey/phisdomjs/blob/main/tests/test_pipeline_integration.py): integration suite · Unit and integration tests covering calibration, fusion, normalization, metrics, and pipeline behavior. · `tests/test_pipeline_integration.py`
- [CI gate](https://github.com/kratospidey/phisdomjs/blob/main/validate_pipeline.py): quality gate · Validation scripts that enforce pipeline and fix correctness. · `validate_pipeline.py`

## Connections

- Feeds → Crawl: seed crawl · Feed definitions drive collection jobs.
- Crawl → Ingest: raw pages · Crawled pages are normalized into datasets.
- Caches → Normalize: enrich · Lookup caches supply DNS/RDAP/TLS metadata.
- Dataset → Normalize: inputs · Seed records and split definitions enter normalization.
- Normalize → Schema: shape · Normalization enforces the canonical record schema.
- Schema → Loader: load · Schema-backed records are loaded for runtime use.
- Loader → Multimodal: join · Loader assembles multimodal examples.
- Multimodal → URL features: URL path · URL view feeds URL feature extraction.
- Multimodal → Extractors: shared view · Common extractor interfaces operate on multimodal samples.
- URL features → Heads: features · URL features train or score the URL head.
- Extractors → Heads: features · Extractor outputs feed modality-specific heads.
- Heads → DOM GCN: specialize · DOM/markup head variants are trained separately when needed.
- Heads → Fusion: logits · Per-modality predictions are fused into a final score.
- DOM GCN → Fusion: graph logits · DOM graph outputs can participate in fusion.
- Fusion → Calibration: calibrate · Fusion scores are calibrated before export or thresholding.
- Calibration → Metrics: score · Calibrated outputs feed evaluation metrics.
- Metrics → Evaluate: report · Metrics power evaluation scripts and plots.
- Calibration → Export: thresholds · Calibration produces operating thresholds for deployment.
- Fusion → Export: predictions · Final scores are exported for downstream consumers.
- Train heads → Heads: fit · Training scripts produce the per-modality heads.
- Fuse → Fusion: fit · Fusion scripts train ensemble logic.
- Evaluate → CI gate: gate · Evaluation results are checked by validation gates.
- Tests → CI gate: assert · Tests backstop the validation pipeline.
- CLI → Fusion: infer · CLI can run scoring through the fused model path.
