Enterprise-grade fraud detection system with microservices architecture, implementing Java 23/Spring Boot 3.2+ backend and event-driven processing.
- 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
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
- 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
- Java 21+ (tested with OpenJDK 21)
- Docker and Docker Compose
- Maven 3.8+ (if not using Docker)
-
Clone the repository
git clone <repository-url> cd fraud-detection-system
-
Start all services
docker-compose up -d
-
Check service health
curl http://localhost:8080/actuator/health
-
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
-
Build the application
mvn clean package -DskipTests
-
Run the application
java -jar fraud-api/target/fraud-api-1.0.0-SNAPSHOT.jar
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"
}'{
"transactionId": "txn-123456",
"correlationId": "550e8400-e29b-41d4-a716-446655440000",
"status": "QUEUED",
"queuedAt": "2025-01-17T10:30:00Z"
}- 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
The system includes several built-in fraud detection rules:
- High Amount Rule: Triggers on transactions β₯ $50,000
- Suspicious Amount Rule: Triggers on transactions β₯ $100,000
- Ingestion: Transaction received via REST API
- Queue: Transaction queued for async processing
- Processing: Worker processes transaction through rules engine
- Evaluation: All enabled rules evaluated in priority order
- Result: Fraud decision stored with confidence scores
fraud.transactions.received.total- Total transactions ingestedfraud.transactions.processed.total- Transactions processedfraud.transactions.alerted.total- Fraud alerts generatedfraud.rule.evaluation.duration- Rule evaluation timingfraud.queue.depth- Current queue depth
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"
}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: truemvn testmvn verify -Pintegration-test# Using JMeter (configure test plan for fraud-detection.jmx)
jmeter -n -t fraud-detection.jmx -l results.jtl- Throughput: 1000+ transactions/second
- Latency: p99 < 100ms for API, < 500ms for processing
- Concurrent Workers: Configurable pool (default: 4)
- Queue Backlog: Handles 10k+ pending messages
- 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
docker-compose up -dkubectl apply -f k8s/- GitHub Actions for automated testing
- Docker image builds
- Integration with artifact registries
Complete OpenAPI 3.0 specification available at:
- Swagger UI:
http://localhost:8080/swagger-ui.html - OpenAPI JSON:
http://localhost:8080/v3/api-docs
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- 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