Financial applications—banking apps, payment gateways, trading platforms—face constant threats from fraudulent activities. Fraudulent transactions can be costly and damage customer trust. Detecting fraud in real time requires a combination of machine learning, rule-based systems, and transaction monitoring.
A modern fraud detection system should:
Detect suspicious patterns and anomalies in real time
Minimize false positives while maximizing fraud detection
Integrate with backend APIs and front-end dashboards
Be scalable and maintainable in enterprise environments
In this article, we will design and implement a Fraud Detection System using AI, covering:
Understanding fraud detection requirements
Architecture overview
SQL Server data design
ASP.NET Core backend implementation
AI model integration (anomaly detection, classification)
Angular dashboard for monitoring
Real-world best practices
Security, compliance, and audit considerations
Performance and scaling
Testing and validation
1. Understanding Fraud Detection Requirements
1.1 Common Fraud Patterns
Unusual Transaction Amounts – sudden high-value transactions
Geographical Anomalies – transactions from unexpected locations
Rapid Transactions – multiple transactions in a short period
Account Behavior Deviations – unusual device, IP, or login time
Known Blacklists – flagged accounts or merchants
1.2 System Requirements
Real-time scoring for incoming transactions
AI-assisted classification of transactions (fraud or legitimate)
Risk scoring for manual review
Historical analysis for model training
Admin dashboards for alerts and review
2. System Architecture Overview
Angular Admin Dashboard
|
ASP.NET Core API Layer
|
Fraud Detection Service (AI Scoring)
|
SQL Server (Transactions, Users, Audit Logs)
|
Optional ML Training Pipeline (Python/ML.NET)2.1 Component Responsibilities
SQL Server – stores transactions, historical labels, risk scores
ASP.NET Core API – exposes endpoints for scoring, alerts, and dashboards
AI Service – evaluates transactions using trained models
Angular Dashboard – visualizes risk scores, alerts, and transaction history
ML Training Pipeline – periodically retrains models with new data
3. SQL Server Data Design
3.1 Transactions Table
CREATE TABLE Transactions (
TransactionID BIGINT PRIMARY KEY IDENTITY,
UserID INT NOT NULL,
Amount DECIMAL(18,2),
Currency NVARCHAR(10),
TransactionDate DATETIME2 NOT NULL DEFAULT GETDATE(),
MerchantID INT,
Location NVARCHAR(100),
DeviceID NVARCHAR(100),
IPAddress NVARCHAR(50),
Status NVARCHAR(50) DEFAULT 'Pending', -- Pending, Completed, Fraud
RiskScore FLOAT DEFAULT 0,
CreatedAt DATETIME2 DEFAULT GETDATE()
);3.2 Users Table
CREATE TABLE Users (
UserID INT PRIMARY KEY IDENTITY,
Name NVARCHAR(150),
Email NVARCHAR(150),
Phone NVARCHAR(20),
CreatedAt DATETIME2 DEFAULT GETDATE()
);3.3 Fraud Alerts Table
CREATE TABLE FraudAlerts (
AlertID BIGINT PRIMARY KEY IDENTITY,
TransactionID BIGINT NOT NULL,
RiskScore FLOAT,
AlertType NVARCHAR(50),
CreatedAt DATETIME2 DEFAULT GETDATE(),
Resolved BIT DEFAULT 0
);4. ASP.NET Core Backend Implementation
4.1 Transaction Repository
public class TransactionRepository
{
private readonly string _connString;
public TransactionRepository(string connString)
{
_connString = connString;
}
public async Task<Transaction> AddTransaction(Transaction txn)
{
using var con = new SqlConnection(_connString);
var sql = @"INSERT INTO Transactions (UserID, Amount, Currency, MerchantID, Location, DeviceID, IPAddress)
VALUES (@UserID, @Amount, @Currency, @MerchantID, @Location, @DeviceID, @IPAddress);
SELECT CAST(SCOPE_IDENTITY() AS BIGINT);";
txn.TransactionID = await con.ExecuteScalarAsync<long>(sql, txn);
return txn;
}
}4.2 Fraud Scoring Service
public class FraudDetectionService
{
private readonly HttpClient _http;
public FraudDetectionService(HttpClient http)
{
_http = http;
}
public async Task<float> ScoreTransactionAsync(Transaction txn)
{
var payload = new
{
transactionId = txn.TransactionID,
userId = txn.UserID,
amount = txn.Amount,
location = txn.Location,
deviceId = txn.DeviceID,
ipAddress = txn.IPAddress,
timestamp = txn.TransactionDate
};
var response = await _http.PostAsJsonAsync("/api/ai/score", payload);
var json = await response.Content.ReadFromJsonAsync<dynamic>();
return (float)json.riskScore;
}
}
Join the conversation! Your thoughts help the community grow.