This library provides comprehensive Avro schemas for the codedx-transfraud real-time fraud detection system built with Apache Flink. The schemas define the data contracts for financial transactions, fraud alerts, and processed outputs, enabling type-safe data streaming and interoperability across system components.
Core schema representing financial card transactions with comprehensive metadata.
Key Fields:
transactionId: Unique transaction identifiercardId/customerId: Entity identifierstransactionAmount: Monetary amount with currencymerchantInfo: Merchant details including location and categorytransactionType: POS, ONLINE, ATM, CONTACTLESS, RECURRINGdeviceInfo: Device metadata for digital transactions
Schema for fraud detection alerts generated by the AI model.
Key Fields:
alertId: Unique alert identifierfraudScore: AI model probability (0.0-1.0)severity: LOW, MEDIUM, HIGH, CRITICALalertType: Pattern type (AMOUNT_ANOMALY, LOCATION_ANOMALY, etc.)recommendedAction: ALLOW, REVIEW, BLOCK_CARD, etc.riskFactors: Contributing risk factors
Schema for transaction outputs after feature engineering and model inference.
Key Fields:
fraudProbability: Final fraud probability scorestatus: APPROVED, REJECTED, FLAGGED_FOR_REVIEWfeatureVector: Engineered features for model inferencewindowedFeatures: Temporal aggregation featuresmodelMetadata: AI model version and performance data
Schema for customer behavioral profiles used in feature engineering.
Key Fields:
typicalTransactionHours: Behavioral patternsfrequentMerchants: Merchant preferencestransactionVelocity: Historical transaction rateshomeLocation: Geographic reference point
<dependency>
<groupId>com.codedstream</groupId>
<artifactId>codedx-transaction-fraud-library</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>implementation 'com.codedx.transfraud:avro-schemas:1.0-SNAPSHOT'java -jar avro-tools-1.0-SNAPSHOT.jar compile schema \
src/main/avro/ \
src/main/java/// Consume transactions from Kafka
DataStream<CardTransaction> transactions = env
.addSource(new FlinkKafkaConsumer<>(
"transactions-topic",
ConfluentRegistryAvroDeserializationSchema.forSpecific(
CardTransaction.class,
"http://schema-registry:8081"
),
properties
));
// Produce fraud alerts
alerts.addSink(new FlinkKafkaProducer<>(
"fraud-alerts-topic",
ConfluentRegistryAvroSerializationSchema.forSpecific(
FraudAlert.class,
"fraud-alerts-topic-value",
"http://schema-registry:8081"
),
properties
));All schemas are designed with forward and backward compatibility:
- Optional fields use
["null", "type"]unions with defaults - New fields can be added with default values
- Enum symbols can be added (but not removed)
- Apache Avro 1.11+
- Java 8 or higher
- Maven 3.6+
mvn clean compile
mvn packagemvn generate-sourcesThese schemas are compatible with Confluent Schema Registry:
// Register schemas
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data @src/main/avro/CardTransaction.avsc \
http://localhost:8081/subjects/transactions-value/versionsCardTransaction (Input)
↓
Feature Engineering
↓
ProcessedTransaction (Intermediate)
↓
AI Model Inference
↓
FraudAlert (Output)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Contact: nestorabiawuh@gmail.com
- LinkedIn: Nestor Martourez
- Apache Avro community
- Apache Flink community
- Financial industry best practices for fraud detection data models
Nestor Martourez
- Email: nestorabiawuh@gmail.com
- LinkedIn: https://www.linkedin.com/in/nestor-abiangang/