Skip to main content

Adversarial machine learning framework for bank fraud detection and model simulation

Project description

Fraudstruct

Fraudstruct is a high-performance Python framework for real-time streaming feature stores and graph-adversarial machine learning in banking fraud detection. It is designed to help Data Scientists and Risk Engineers simulate, detect, and harden models against structuring (smurfing), multi-hop money laundering, and threshold evasion in transaction streams.

The library supports a production-ready Three-Tier Architecture that bridges deep offline Graph Neural Networks (GNNs) with sub-10ms real-time transaction authorization endpoints.


Why Fraudstruct Exists

Traditional fraud models degrade rapidly because fraudsters actively adapt to rule-based thresholds (e.g., splitting a transaction into smaller amounts across proxy accounts/mules).

Fraudstruct addresses these operational realities:

  • Coordinated Multi-Hop Fraud: Fraudsters use network topologies to evade single-account checks.
  • Strict Latency Budgets: Banks must authorize transactions in <50ms, making traditional graph neural network (GNN) convolution passes on the transaction hot-path infeasible.
  • Continuous Adaptive Evasion: Evasion techniques evolve faster than weekly or monthly model retraining loops.

System Architecture Overview

Fraudstruct resolves the latency-complexity trade-off using a Three-Tier Lambda-style ML System:

           [Core Banking / NIBSS / Switch]
                          │
         (1) Synchronous API Request (e.g. NIP/ISO 8583)
                          ▼
             ┌─────────────────────────┐
             │    HOT PATH (<10ms)     │
             │   REST API (FastAPI)    │◄─── [Loaded Model Weights]
             └────────────┬────────────┘
                          │ (Retrieves pre-computed GNN + temporal features)
                          ▼
                  ┌──────────────┐
                  │ Feature Cache│
                  └──────▲───────┘
                         │ (Updates features in real-time)
             ┌───────────┴─────────────┐
             │    WARM PATH (<1s)      │
             │  Streaming Event Loop   │◄─── [Transaction Log Stream]
             └───────────┬─────────────┘
                         │ (Aggregates historical subgraph structures)
                         ▼
             ┌─────────────────────────┐
             │    COLD PATH (Offline)  │
             │ NumPy SGC GNN Classifier│◄─── [Graph Attack Simulator]
             └─────────────────────────┘
  1. Hot Path (Synchronous Inference): A lightweight REST API that retrieves pre-computed graph features and rolling temporal stats, evaluates fast rules + GNN score thresholds, and responds in <5ms (satisfying strict banking SLAs).
  2. Warm Path (Near Real-Time Feature Store): A streaming engine that consumes transaction streams, updates the transaction graph structure (using GraphEngine), and updates rolling temporal windows in memory.
  3. Cold Path (Offline Training & Simulation): Generates synthetic multi-hop structuring attacks on the graph, trains a Simplifying Graph Convolution (SGC) GNN model, and hot-deploys updated model weights to the Hot Path.

Key Capabilities

1. Graph representation & Feature Store

  • NetworkX-powered transaction graph engine (GraphEngine) that models accounts as nodes and transactions as edges.
  • Real-time calculation of topological features (in-degree, out-degree, PageRank, running sums, and velocities).

2. Graph-Based Evasion Simulation

  • Multi-hop transaction-splitting simulator (simulate_graph_splitting). Splits a target amount $S$ from $A \rightarrow B$ across $K$ dynamic mule pathways, adding temporal spacing and amount jittering to mimic realistic money laundering.

3. Portability & Performance (Pure NumPy GNN)

  • Implementation of Simplifying Graph Convolution (SGC) (Wu et al., 2019) in pure NumPy, removing heavy compile dependencies (e.g. PyTorch Geometric or C++ bindings) and allowing seamless execution under Python 3.13.

4. Real-time REST API

  • FastAPI endpoint exposing /v1/evaluate for real-time transaction scoring and /v1/train to hot-deploy trained graph embeddings to the feature store.

Installation

Install the library locally:

pip install -e .

Required Dependencies

  • pandas
  • numpy
  • networkx
  • fastapi
  • httpx

Quick Start

1. Running the End-to-End Pipeline & Benchmark

Fraudstruct comes with a comprehensive verification script that runs the entire warm, hot, and cold path loop and profiles API latency:

python test_pipeline.py

Expected output log:

==================================================
FRAUDSTRUCT PIPELINE VERIFICATION AND BENCHMARK
==================================================
[Step 1] Generating organic transaction traffic...
Generated 150 organic transactions.

[Step 2] Simulating adversarial smurfing path (A -> Mules -> B)...
Generated 12 attack path transactions.

[Step 3] Feeding organic stream to API evaluate endpoint...
Inference Latency Metric (ZENITH SLA check):
  - Average Latency: 2.447 ms
  - 95th Percentile: 3.407 ms

[Step 4] Feeding attack stream and checking for alerts...
ALERT TRIGGERED on TXN-ADV-46940! Decision: FLAG, Reasons: ['Debit velocity structuring threshold breached: Sum=600000.0, Count=6']

[Step 5] Triggering Cold Path GNN Training & Hot-Deployment...
Training response: {'status': 'Success', 'message': 'GNN model successfully trained and hot-deployed.', 'trained_nodes_count': 52}

[Step 6] Verifying active GNN blocking post-deployment...
Post-GNN deployment evaluation result for attacker:
  - Decision: BLOCK
  - Reasons: ['High GNN network anomaly score: 0.9650']
  - GNN Anomaly Score: 0.965

API Reference

Evaluate Transaction

Exposes a NIBSS Instant Payment (NIP) compliant payload structure:

  • Endpoint: POST /v1/evaluate
  • Request Body:
    {
      "transaction_id": "TXN-90283",
      "source_account": "1029384756",
      "destination_account": "2093847561",
      "amount": 250000.0,
      "timestamp": "2026-06-26T17:00:00Z",
      "channel": "NIP"
    }
    
  • Response Body:
    {
      "transaction_id": "TXN-90283",
      "decision": "APPROVE",
      "reasons": [],
      "latency_ms": 2.447,
      "features": {
        "rolling_sum": 250000.0,
        "rolling_count": 1,
        "in_degree": 0,
        "out_degree": 1,
        "gnn_anomaly_score": 0.0
      }
    }
    

Academic Thesis Contributions

This repository serves as the empirical codebase for an MSc thesis in Computer Science:

  1. Graph-Based Tabular Evasion Modeling: Bridges graph topology with tabular business constraints by formalizing smurfing as a dynamic flow-splitting optimization problem.
  2. Decoupled Real-Time Streaming Graph Inference: Proves that GNN node features can be successfully cached and served in transaction authorization switches under a <10ms SLA.
  3. Online Graph Adversarial Hardening: Details a continuous learning framework that updates graph embeddings in response to dynamic topology shifts.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fraudstruct-1.0.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fraudstruct-1.0.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file fraudstruct-1.0.0.tar.gz.

File metadata

  • Download URL: fraudstruct-1.0.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for fraudstruct-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cb4e5bd93eb9a6a0c99bb54524a099d1bca3e07b2a9cc8f9e365975ca9f954f8
MD5 4eef16b211bb8b22a2563c22b4b58f62
BLAKE2b-256 a2541a219d96a2d06fb90b8dd1c52637f0f0008968df0c91109817e2e3279cc6

See more details on using hashes here.

File details

Details for the file fraudstruct-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: fraudstruct-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for fraudstruct-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ecb17b32dd975d65a3979cb26afb0c08bcc1a27644a18e39200a32ea5966ed8
MD5 97ab51140d3934e70d098c7f8b35fcc5
BLAKE2b-256 e79fc9a249c2076f9028c4145a081c02ef8ae849b4af89e9102da84e46a6ea19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page