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 从公开仓库中收录这些内容。

举报或申请下架