Problem
Fraud detection sits where real-time event processing, encoded domain expertise and explainability meet. Production fraud systems often need auditable decisions: a declined transaction has to be justified.
I built this project to explore expert-system design: encoding real fraud patterns as verifiable, traceable rules rather than opaque model weights.
Architecture
Four independently buildable Maven modules. For each request, the Spring Boot service creates a stateful Drools session, inserts the transaction, the customer profile and the transaction history, fires all rules, and returns a structured decision with the full rule trace.
Modules
-
fraud-detection-model
Shared domain model: transactions, customer profiles, fact classes, risk scoring.
-
fraud-detection-kjar
Drools KJAR: the compiled rule artifact containing all fraud detection logic.
-
fraud-detection-service
Spring Boot REST API: manages the KIE session lifecycle and exposes the analysis endpoints.
-
fraud-detection-ui
Angular SPA for interactive transaction analysis.
Rule levels
Rules run in four salience-ordered levels, so derived facts exist before the higher-level pattern rules that depend on them.
Hierarchical rule execution
-
Level 1 · classification (salience 100)
Raw attributes become typed facts: Small/Medium/LargeTransaction, ForeignTransaction, RiskyMerchantCategory, NightTransaction, SuspiciousIP.
-
Level 2 · profile deviation (salience 80)
Facts compared with the customer profile: SpendingAnomaly (>3× daily average), UnknownLocation, UnusualMerchant, CompromisedCard.
-
Level 3 · temporal patterns (salience 60)
CEP time windows over the history: card testing, impossible travel, velocity attack, dormant awakening, high frequency, multi-country.
-
Level 4 · bonuses and decision (salience 10–200)
Extra weight for dangerous combinations, then APPROVE (<30), REVIEW (30–79) or BLOCK (≥80).
Key decisions
- Salience levels instead of one flat rule set. Lower-level classification always completes before composite pattern detection begins.
- Complex event processing in STREAM mode. Time-windowed
accumulatepatterns count, average and group transactions over intervals. Examples: 3+ micro-transactions (under 5 EUR) within 10 minutes is card testing; transactions from different countries within 120 minutes is impossible travel; 5+ transactions within 5 minutes is a velocity attack. - Backward chaining for composite risk. An
isRiskSatisfiedquery lets rules ask whether a composite condition holds, and Drools resolves the dependency graph on demand instead of materializing every intermediate fact. - Explainability as a first-class requirement. The
RiskScorefact accumulates both the score and the ordered list of rules that produced it, and every decision ships with that trace:
FraudDecision {
transactionId: "TXN-001",
customerId: "CUST-42",
decision: BLOCK,
riskScore: 85,
reasons: ["R2.3_SpendingAnomaly", "R3.2_ImpossibleTravel", "R4.8_Bonus_ImpossibleTravel_Foreign"]
}
- Additive scoring with a cap. Each fired rule adds a fixed 5–40 points, capped at 100. A single low-severity signal produces REVIEW, while correlated signals escalate to BLOCK without per-combination thresholds.
Tech
Java 11, Drools / KIE 7.73.0 (STREAM mode, backward chaining), Spring Boot 2.7.9, multi-module Maven, Angular 20 with Angular Material, and a Postman collection for the API.