← Solutions

Fraud Detection

Score every card payment for fraud inside your Spring Boot service, with a Deep Netts neural network trained on labelled transactions.

payment-service · fraud scoring (in-process)
payment€86.40Berlin · card$4,980.00Lagos · new cardDeep Nettsfraud modelscore 0.04score 0.93APPROVEpayBLOCKreview
€86.40Berlin · card$4,980.00Lagos · new cardDeep Nettsfraud modelscore 0.04score 0.93BLOCKreviewAPPROVEpay
0.939
ROC AUC on synthetic test data (extended version)
27 → 32 → 16 → 1
neural network in the extended version
8 endpoints
plus Spring Boot Actuator (extended)
JDK 25
Spring Boot 4 · Deep Netts core 4.0.5

Fixed rules miss new fraud and stop good customers

Card fraud costs lost goods or money, chargeback fees, analyst time and customers who leave. Fixed rules such as “block payments above €1,000 abroad” miss new patterns and stop many good customers.

A model trained on labelled transactions returns a fraud score for every payment. You can use it to rank payments for review, ask for extra authentication, and compare alerts with confirmed outcomes. Where to draw the line between approve, review and decline stays a business decision.

How it works

  1. Describe the transaction

    Amount, the customer’s average amount, hour of day, distance from home, recent attempts, online or in store, new device, foreign merchant.

  2. Turn it into features

    Amounts and distances on a log scale, flags as 0 or 1, then standardized with the scaling learned from the training data and saved with the model.

  3. Score it in-process

    A Deep Netts feedforward network returns a fraud score between 0 and 1 – a method call inside the same JVM.

  4. Compare with a threshold

    The score is compared with a configurable threshold. The extended version adds rule-based risk indicators to help an analyst review the case.

Inside the model

The network from the minimal version, neuron by neuron, in its real size.

Inputs · 9Hidden · 16 · ReLUOutput · 2 · softmaxlogAmountlogCustomerAvgAmounthourOfDaylogDistanceFromHomeKmtransactionsLast24hfailedAttemptsLast24honlinenewDeviceforeignlegitimatefraud
The minimal network9 → 16 → 2

Point at an input or an output to see what it is and how it is computed.

Decision
  • fraudScore = the “fraud” output
  • fraud = fraudScore ≥ 0.5
Standardizer saved in the modelCross-entropyAdamlearning rate 0.00130 epochsseed 42
Extended version27 → 32 → 16 (ReLU) → 1 (sigmoid)

Source: minimal/…/FraudModel.java, TransactionEncoder.java

Walk through the code

Real files from the minimal version. Pick a step to see the lines that do it.

@RestController@RequestMapping("/api/fraud")public class FraudController {     private final FraudModel model;     public FraudController(FraudModel model) {        this.model = model;    }     /** Scores one transaction. An invalid request gets a {@code 400} response and no score. */    @PostMapping("/predict")    public FraudPrediction predict(@Valid @RequestBody Transaction transaction) {        return model.predict(transaction);    }}

Two versions in one repository

Start with the minimal version to see the whole integration in a few files; move to the extended one for the full lifecycle.

The smallest complete integration of a Deep Netts fraud model in Spring Boot.

  • 9 inputs, one endpoint
  • Trains on first start, saves and reloads the model
  • Precision, recall and accuracy on test data
  • 16 tests

REST API

POST/api/fraud/predictScore one transactionminimal
POST/api/transactions/assessScore one transactionextended
POST/api/transactions/assess/batchScore up to 1,000 transactionsextended
GET/api/modelModel info and metricsextended
POST/api/model/trainTrain a modelextended
POST/api/monitoring/outcomesReport a confirmed outcomeextended
GET/api/monitoringAlert rate, precision / recall, last retrainingextended
Request · minimal
POST /api/fraud/predictContent-Type: application/json {  "amount": 950,  "customerAvgAmount": 45,  "hourOfDay": 3,  "distanceFromHomeKm": 850,  "transactionsLast24h": 11,  "failedAttemptsLast24h": 3,  "online": true,  "newDevice": true,  "foreign": true}
Response
{  "fraudScore": 0.9999899864196777,  "fraud": true}

Run it locally

  • JDK 25 (required by Deep Netts 4.x)
  • Maven 3.9 or later
  • No external services – trains on synthetic data
  • Both versions use port 8080, run one at a time
Terminal
git clone https://github.com/deepnetts/spring-boot-fraud-detection.gitcd spring-boot-fraud-detection/minimalmvn spring-boot:run # in a second terminalcurl -X POST localhost:8080/api/fraud/predict   -H "Content-Type: application/json"   -d '{"amount": 950, "customerAvgAmount": 45, "hourOfDay": 3,       "distanceFromHomeKm": 850, "transactionsLast24h": 11,       "failedAttemptsLast24h": 3, "online": true,       "newDevice": true, "foreign": true}'

Ready for AI coding assistants

The repository ships a SKILL.md with rules and procedures for developers and AI coding assistants, and ready-made prompts for the most common changes.

  • explain-the-example.mdWalk a Java developer new to ML through the workflow and evaluation, without changing files
  • replace-transaction-fields.mdMap your own payment fields to model inputs, then change the code after approval
  • adapt-preprocessing.mdProfile a new dataset, propose preprocessing and a split, compare evaluations
  • modify-the-prediction-api.mdChange the request and response, keeping the score separate from the decision
  • integrate-into-an-existing-app.mdAdd fraud scoring to an existing Spring Boot app in small, tested steps
  • review-a-change.mdReview uncommitted changes against the SKILL.md rules

Good to know

  • Proofs of concept for local use, not production services. All results come from synthetic data.
  • Fraud scores are not calibrated probabilities. There is no authentication.
  • Model files use Java serialization – only load files you trust.

More solutions

See Deep Netts in researchCase studies from Jefferson Lab and the University of Minnesota.Read the case studies