Domain Fintech

作者 actionbook5c40d3ad7851無授權條款1.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫6 週前更新

Use when building fintech apps. Keywords: fintech, trading, decimal, currency, financial, money, transaction, ledger, payment, exchange rate, precision, rounding, accounting, 金融, 交易系统, 货币, 支付

AI 產生的概覽

為 Rust 金融科技開發提供指引,涵蓋小數金額型別、稽核軌跡與交易一致性。

功能
此技能為金融科技應用(主要針對 Rust)提供領域限制與設計指引。它把精度、可稽核性與一致性等金融規則對應到設計影響,推薦 rust_decimal、chrono、uuid 等 crate,並提出貨幣 newtype、事件溯源、稽核日誌與複式記帳等模式。內容也包含一個 Amount 型別範例,以及把 f64 用於金額等常見錯誤的清單。
適用情境
在設計或審查涉及資金處理、交易完整性或稽核要求的金融科技軟體時使用。適合支付、帳本、交易或會計功能,這些情境需要精確的小數運算與不可變記錄。
執行需求
不需要指令碼或工具,僅為說明性內容。若要套用其中的指引,需具備 Rust 專案以及所引用的 crate,例如 rust_decimal、chrono、uuid、serde 和 validator。

FinTech Domain

Layer 3: Domain Constraints

Domain Constraints → Design Implications

Domain RuleDesign ConstraintRust Implication
Audit trailImmutable recordsArc<T>, no mutation
PrecisionNo floating pointrust_decimal
ConsistencyTransaction boundariesClear ownership
ComplianceComplete loggingStructured tracing
ReproducibilityDeterministic executionNo race conditions

Critical Constraints

Financial Precision

RULE: Never use f64 for moneyWHY: Floating point loses precisionRUST: Use rust_decimal::Decimal

Audit Requirements

RULE: All transactions must be immutable and traceableWHY: Regulatory compliance, dispute resolutionRUST: Arc<T> for sharing, event sourcing pattern

Consistency

RULE: Money can't disappear or appearWHY: Double-entry accounting principlesRUST: Transaction types with validated totals

Trace Down ↓

From constraints to design (Layer 2):

"Need immutable transaction records"    ↓ m09-domain: Model as Value Objects    ↓ m01-ownership: Use Arc for shared immutable data
"Need precise decimal math"    ↓ m05-type-driven: Newtype for Currency/Amount    ↓ rust_decimal: Use Decimal type
"Need transaction boundaries"    ↓ m12-lifecycle: RAII for transaction scope    ↓ m09-domain: Aggregate boundaries

Key Crates

PurposeCrate
Decimal mathrust_decimal
Date/timechrono, time
UUIDuuid
Serializationserde
Validationvalidator

Design Patterns

PatternPurposeImplementation
Currency newtypeType safetystruct Amount(Decimal);
TransactionAtomic operationsEvent sourcing
Audit logTraceabilityStructured logging with trace IDs
LedgerDouble-entryDebit/credit balance

Code Pattern: Currency Type

rust
use rust_decimal::Decimal;
#[derive(Clone, Debug, PartialEq)]pub struct Amount {    value: Decimal,    currency: Currency,}
impl Amount {    pub fn new(value: Decimal, currency: Currency) -> Self {        Self { value, currency }    }
    pub fn add(&self, other: &Amount) -> Result<Amount, CurrencyMismatch> {        if self.currency != other.currency {            return Err(CurrencyMismatch);        }        Ok(Amount::new(self.value + other.value, self.currency))    }}

Common Mistakes

MistakeDomain ViolationFix
Using f64Precision lossrust_decimal
Mutable transactionAudit trail brokenImmutable + events
String for amountNo validationValidated newtype
Silent overflowMoney disappearsChecked arithmetic

Trace to Layer 1

ConstraintLayer 2 PatternLayer 1 Implementation
Immutable recordsEvent sourcingArc<T>, Clone
Transaction scopeAggregateOwned children
PrecisionValue Objectrust_decimal newtype
Thread-safe sharingShared immutableArc (not Rc)

Related Skills

WhenSee
Value Object designm09-domain
Ownership for immutablem01-ownership
Arc for sharingm02-resource
Error handlingm13-domain-error

來源與署名

來源:actionbook/rust-skills位於skills/domain-fintech提交5c40d3a

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架