mcpField
D
domain-fintech

domain-fintech

github.com/actionbook开发1.6k2.9k 次安装9 周前更新
代码仓库

关于 domain-fintech

面向金融软件的 Rust 领域技能,聚焦精确十进制运算、不可变审计轨迹和交易一致性,指导开发者建模金额、账本操作与可追溯记录。

主要功能

  1. 01使用 Decimal 保证金额精度
  2. 02不可变交易与审计记录
  3. 03货币与金额类型建模
  4. 04双重记账账本模式
  5. 05交易校验与结构化日志

适用场景

  1. 01建模带币种的金额类型
  2. 02记录可追溯交易事件
  3. 03设计借贷平衡账本
  4. 04防止金额计算精度损失

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/actionbook/rust-skills --skill domain-fintech

安装后在 Claude Code 中输入/domain-fintech确认已加载。

详细介绍

金融科技领域

第 3 层:领域约束

领域约束 → 设计影响

领域规则设计约束Rust 影响
审计追踪不可变记录Arc,不进行修改
精度不使用浮点数rust_decimal
一致性事务边界明确所有权
合规性完整日志记录结构化追踪
可复现性确定性执行无竞态条件

关键约束

金融精度
RULE: Never use f64 for money
WHY: Floating point loses precision
RUST: Use rust_decimal::Decimal
审计要求
RULE: All transactions must be immutable and traceable
WHY: Regulatory compliance, dispute resolution
RUST: Arc<T> for sharing, event sourcing pattern
一致性
RULE: Money can't disappear or appear
WHY: Double-entry accounting principles
RUST: Transaction types with validated totals

向下追溯 ↓

从约束到设计(第 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

关键 Crate

用途Crate
十进制运算rust_decimal
日期/时间chrono, time
UUIDuuid
序列化serde
验证validator

设计模式

模式用途实现方式
货币 newtype类型安全struct Amount(Decimal);
事务原子操作事件溯源
审计日志可追溯性带追踪 ID 的结构化日志记录
账本借贷记账借方/贷方余额

代码模式:货币类型

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))
    }
}

常见错误

错误违反的领域规则修复方法
使用 f64精度损失rust_decimal
可变事务审计追踪受损不可变 + 事件
使用字符串表示金额无法验证经验证的 newtype
溢出未处理资金消失检查算术运算

追溯到第 1 层

约束第 2 层模式第 1 层实现
不可变记录事件溯源Arc,Clone
事务作用域聚合拥有子项
精度值对象rust_decimal newtype
线程安全共享共享不可变数据Arc(而非 Rc)

相关技能

适用场景参见
值对象设计m09-domain
不可变数据的所有权m01-ownership
使用 Arc 共享m02-resource
错误处理m13-domain-error

评论

支持 Markdown