PluginBench
Skill
Review
Audit score 70

domain-fintech

actionbook/rust-skills

Fintech domain constraints and patterns for Rust: precision, immutability, and audit trails.

What is domain-fintech?

A domain-specific skill for building financial applications in Rust. Covers critical constraints like decimal precision (never f64), immutable transaction records for audit compliance, and double-entry accounting principles. Use this when designing ledgers, payment systems, or trading platforms.

  • Enforces financial precision using rust_decimal instead of floating-point arithmetic
  • Implements immutable transaction records with Arc<T> for audit trail compliance
  • Provides Currency and Amount newtypes for type-safe money handling
  • Guides transaction boundaries and aggregate design for consistency
  • Structures logging and tracing for regulatory requirements
  • Prevents common mistakes like silent overflow and mutable state

How to install domain-fintech

npx skills add https://github.com/actionbook/rust-skills --skill domain-fintech
Prerequisites
  • Familiarity with Rust ownership and Arc<T>
  • Understanding of double-entry accounting principles
  • Knowledge of domain-driven design patterns
Claude Code
Cursor
Windsurf
Cline

How to use domain-fintech

  1. 1.Define Currency and Amount newtypes using rust_decimal::Decimal
  2. 2.Use Arc<T> for immutable shared transaction records
  3. 3.Implement transaction types with validated totals to prevent money loss
  4. 4.Structure audit logs with trace IDs and event sourcing patterns
  5. 5.Validate all money operations with checked arithmetic and currency matching

Use cases

Good for
  • Building a payment ledger system with immutable transaction history
  • Implementing currency conversion with precise decimal math
  • Designing a trading platform with atomic transaction boundaries
  • Creating audit-compliant financial records for regulatory reporting
  • Handling multi-currency transactions with type-safe Amount validation
Who it's for
  • Fintech engineers building payment or trading systems
  • Backend developers implementing ledger or accounting features
  • Teams requiring regulatory compliance and audit trails
  • Rust developers working with financial data

domain-fintech FAQ

Why not use f64 for money?

Floating-point arithmetic loses precision due to binary representation limits, causing rounding errors in financial calculations. Always use rust_decimal::Decimal for exact decimal math.

How do I ensure transactions are immutable?

Use Arc<T> for shared immutable data and implement event sourcing patterns. Never mutate transaction records after creation; instead, create new immutable events.

What's the Currency newtype pattern?

Wrap Decimal in a struct with currency metadata: `struct Amount { value: Decimal, currency: Currency }`. This provides type safety and prevents mixing currencies.

How do I prevent money from disappearing?

Apply double-entry accounting principles: every debit must have a matching credit. Use transaction types with validated totals and checked arithmetic operations.

What crates should I use?

rust_decimal for math, chrono/time for dates, uuid for transaction IDs, serde for serialization, and validator for input validation.

Full instructions (SKILL.md)

Source of truth, from actionbook/rust-skills.


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

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 money
WHY: Floating point loses precision
RUST: Use rust_decimal::Decimal

Audit Requirements

RULE: All transactions must be immutable and traceable
WHY: Regulatory compliance, dispute resolution
RUST: Arc<T> for sharing, event sourcing pattern

Consistency

RULE: Money can't disappear or appear
WHY: Double-entry accounting principles
RUST: 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

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