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

- 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
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.
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.
Score it in-process
A Deep Netts feedforward network returns a fraud score between 0 and 1 – a method call inside the same JVM.
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.
Point at an input or an output to see what it is and how it is computed.
- fraudScore = the “fraud” output
- fraud = fraudScore ≥ 0.5
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
A fraud scoring service that covers the complete machine learning lifecycle.
- 27 features from 16 fields, synthetic generator or your own CSV
- ROC AUC, PR AUC, F1 and a recommended threshold
- Model and metadata in one file, swapped while requests run
- Health, readiness, metrics and monitoring of confirmed outcomes
- Retraining on request or on a schedule
- 142 tests
REST API
| POST | /api/fraud/predict | Score one transaction | minimal |
| POST | /api/transactions/assess | Score one transaction | extended |
| POST | /api/transactions/assess/batch | Score up to 1,000 transactions | extended |
| GET | /api/model | Model info and metrics | extended |
| POST | /api/model/train | Train a model | extended |
| POST | /api/monitoring/outcomes | Report a confirmed outcome | extended |
| GET | /api/monitoring | Alert rate, precision / recall, last retraining | extended |
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}{ "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
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 filesreplace-transaction-fields.mdMap your own payment fields to model inputs, then change the code after approvaladapt-preprocessing.mdProfile a new dataset, propose preprocessing and a split, compare evaluationsmodify-the-prediction-api.mdChange the request and response, keeping the score separate from the decisionintegrate-into-an-existing-app.mdAdd fraud scoring to an existing Spring Boot app in small, tested stepsreview-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.