Skip to main content

datasynth_banking/
lib.rs

1#![deny(clippy::unwrap_used)]
2//! # synth-banking
3//!
4//! KYC/AML banking transaction generator for synthetic data.
5//!
6//! This crate provides comprehensive banking transaction simulation for:
7//! - Compliance testing and model training
8//! - AML/fraud detection system evaluation
9//! - KYC process simulation
10//! - Regulatory reporting testing
11//!
12//! ## Features
13//!
14//! - **Customer Generation**: Retail, business, and trust customers with realistic KYC profiles
15//! - **Account Generation**: Multiple account types with proper feature sets
16//! - **Transaction Engine**: Persona-based transaction generation with causal drivers
17//! - **AML Typologies**: Structuring, funnel accounts, layering, mule networks, and more
18//! - **Ground Truth Labels**: Multi-level labels for ML training
19//! - **Spoofing Mode**: Adversarial transaction generation for robustness testing
20//!
21//! ## Architecture
22//!
23//! The crate follows a layered architecture:
24//!
25//! ```text
26//! BankingOrchestrator (orchestration)
27//!         ↓
28//! Generators (customer, account, transaction, counterparty)
29//!         ↓
30//! Typologies (AML pattern injection)
31//!         ↓
32//! Labels (ground truth generation)
33//!         ↓
34//! Models (customer, account, transaction, KYC)
35//! ```
36//!
37//! ## Usage
38//!
39//! ```rust,ignore
40//! use datasynth_banking::{BankingOrchestrator, BankingConfig};
41//!
42//! let config = BankingConfig::default();
43//! let mut orchestrator = BankingOrchestrator::new(config, 12345);
44//!
45//! // Generate customers and accounts
46//! let customers = orchestrator.generate_customers();
47//! let accounts = orchestrator.generate_accounts(&customers);
48//!
49//! // Generate transaction stream
50//! let transactions = orchestrator.generate_transactions(&accounts);
51//! ```
52
53pub mod generators;
54pub mod labels;
55pub mod models;
56pub mod personas;
57pub mod seed_offsets;
58pub mod typologies;
59
60mod config;
61mod orchestrator;
62
63/// Parse a start date string in YYYY-MM-DD format, logging a warning and
64/// falling back to 2024-01-01 when the string is malformed.
65pub(crate) fn parse_start_date(date_str: &str) -> chrono::NaiveDate {
66    chrono::NaiveDate::parse_from_str(date_str, "%Y-%m-%d").unwrap_or_else(|e| {
67        tracing::warn!(
68            "Failed to parse start_date '{}': {}. Defaulting to 2024-01-01",
69            date_str,
70            e
71        );
72        chrono::NaiveDate::from_ymd_opt(2024, 1, 1).expect("valid date")
73    })
74}
75
76pub use config::*;
77pub use orchestrator::*;
78
79// Re-export key types for convenience
80pub use datasynth_core::models::banking::{
81    AmlTypology, BankAccountType, BankingCustomerType, Direction, LaunderingStage,
82    MerchantCategoryCode, RiskTier, Sophistication, TransactionCategory, TransactionChannel,
83};
84pub use models::{BankAccount, BankTransaction, BankingCustomer, CounterpartyPool, KycProfile};