Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Fraud Detection System

Enterprise-grade fraud detection system with microservices architecture, implementing Java 23/Spring Boot 3.2+ backend and event-driven processing.

πŸš€ Features

  • Clean Architecture: Domain-driven design with clear separation of concerns
  • Asynchronous Processing: Redis Streams-based message queue with worker pools
  • Advanced Rules Engine: Pluggable fraud detection rules (threshold, pattern, composite, ML-based)
  • Circuit Breaker Pattern: Resilient external service calls
  • Comprehensive Monitoring: Metrics collection with Prometheus/Grafana
  • Structured Logging: JSON logging with correlation IDs
  • Database Migrations: Liquibase-managed schema evolution

πŸ—οΈ Architecture

fraud-detection-system/
β”œβ”€β”€ fraud-core/              # Domain entities and business logic
β”œβ”€β”€ fraud-persistence/       # JPA entities and repositories
β”œβ”€β”€ fraud-api/               # REST API controllers and DTOs
β”œβ”€β”€ fraud-infrastructure/    # Application configuration
└── fraud-rules-engine/      # Fraud detection rules engine

πŸ› οΈ Technology Stack

  • Backend: Java 23, Spring Boot 3.2+, Lombok, MapStruct
  • Database: PostgreSQL 16 with JSONB support
  • Queue: Redis 7 Streams for message persistence
  • Build: Maven with multi-module structure
  • Testing: JUnit 5, Testcontainers, RestAssured
  • Monitoring: Micrometer, Prometheus, Grafana

πŸš€ Quick Start

Prerequisites

  • Java 21+ (tested with OpenJDK 21)
  • Docker and Docker Compose
  • Maven 3.8+ (if not using Docker)

Using Docker Compose

  1. Clone the repository

    git clone <repository-url>
    cd fraud-detection-system
  2. Start all services

    docker-compose up -d
  3. Check service health

    curl http://localhost:8080/actuator/health

Manual Setup

  1. Start PostgreSQL and Redis

    docker run -d --name postgres -p 5432:5432 -e POSTGRES_DB=fraud_detection -e POSTGRES_USER=frauduser -e POSTGRES_PASSWORD=password postgres:16-alpine
    docker run -d --name redis -p 6379:6379 redis:7-alpine redis-server --appendonly yes
  2. Build the application

    mvn clean package -DskipTests
  3. Run the application

    java -jar fraud-api/target/fraud-api-1.0.0-SNAPSHOT.jar

πŸ“‘ API Usage

Ingest Transaction

curl -X POST http://localhost:8080/api/v1/transactions \
  -H "Content-Type: application/json" \
  -d '{
    "transactionId": "txn-123456",
    "timestamp": "2025-01-17T10:30:00",
    "senderAccount": "ACCOUNT001",
    "receiverAccount": "ACCOUNT002",
    "amount": 150.50,
    "transactionType": "TRANSFER",
    "paymentChannel": "WEB",
    "correlationId": "550e8400-e29b-41d4-a716-446655440000"
  }'

Response

{
  "transactionId": "txn-123456",
  "correlationId": "550e8400-e29b-41d4-a716-446655440000",
  "status": "QUEUED",
  "queuedAt": "2025-01-17T10:30:00Z"
}

Health Check Endpoints

  • Application Health: GET /actuator/health
  • Queue Status: GET /api/v1/admin/queue/health
  • Circuit Breakers: GET /api/v1/admin/circuit-breakers
  • Metrics: GET /actuator/prometheus

🎯 Fraud Detection Rules

The system includes several built-in fraud detection rules:

Threshold Rules

  • High Amount Rule: Triggers on transactions β‰₯ $50,000
  • Suspicious Amount Rule: Triggers on transactions β‰₯ $100,000

Rule Evaluation Process

  1. Ingestion: Transaction received via REST API
  2. Queue: Transaction queued for async processing
  3. Processing: Worker processes transaction through rules engine
  4. Evaluation: All enabled rules evaluated in priority order
  5. Result: Fraud decision stored with confidence scores

πŸ“Š Monitoring & Observability

Metrics Collected

  • fraud.transactions.received.total - Total transactions ingested
  • fraud.transactions.processed.total - Transactions processed
  • fraud.transactions.alerted.total - Fraud alerts generated
  • fraud.rule.evaluation.duration - Rule evaluation timing
  • fraud.queue.depth - Current queue depth

Logging

Structured JSON logs with correlation IDs for request tracing:

{
  "timestamp": "2025-01-17T10:30:45.123Z",
  "level": "INFO",
  "logger": "com.fraud.detection.RulesEngine",
  "message": "Transaction evaluated",
  "correlationId": "550e8400-e29b-41d4-a716-446655440000",
  "transactionId": "txn-123456",
  "triggered_rules": ["high-amount-rule"],
  "result": "ALERT"
}

πŸ”§ Configuration

Application Properties

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/fraud_detection
    username: frauduser
    password: ${DB_PASSWORD}

  redis:
    host: localhost
    port: 6379

fraud:
  queue:
    workers:
      count: 4
      batch-size: 10
    retry:
      max-attempts: 3
      backoff-multiplier: 2

  rules:
    hot-reload: true

πŸ§ͺ Testing

Unit Tests

mvn test

Integration Tests

mvn verify -Pintegration-test

Load Testing

# Using JMeter (configure test plan for fraud-detection.jmx)
jmeter -n -t fraud-detection.jmx -l results.jtl

πŸ“ˆ Performance Benchmarks

  • Throughput: 1000+ transactions/second
  • Latency: p99 < 100ms for API, < 500ms for processing
  • Concurrent Workers: Configurable pool (default: 4)
  • Queue Backlog: Handles 10k+ pending messages

πŸ”’ Security Considerations

  • Input Validation: Comprehensive JSR-303 validation
  • Rate Limiting: IP-based request throttling
  • Authentication: JWT-based auth (extensible)
  • Data Protection: PII masking in logs
  • Container Security: Non-root execution

🚒 Deployment

Docker Compose (Development)

docker-compose up -d

Kubernetes (Production)

kubectl apply -f k8s/

CI/CD Pipeline

  • GitHub Actions for automated testing
  • Docker image builds
  • Integration with artifact registries

πŸ“š API Documentation

Complete OpenAPI 3.0 specification available at:

  • Swagger UI: http://localhost:8080/swagger-ui.html
  • OpenAPI JSON: http://localhost:8080/v3/api-docs

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🎯 Roadmap

  • Phase 1: Foundation & Architecture
  • Phase 2: Message Queue & Async Processing
  • Phase 3: Advanced Rules Engine (Base Framework)
  • Phase 3.2-3.5: Complete Rules Engine (Pattern, Composite, ML Rules)
  • Phase 4: Notification System
  • Phase 5: Admin Panel Frontend
  • Phase 6: Monitoring & Logging
  • Phase 7: Testing & Quality Assurance
  • Phase 8: Production Deployment

Built with ❀️ using Clean Architecture principles

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages