moonbit-aml

moon add cstoooo/moonbit-aml@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
19 hours ago
Downloads
2
README

#moonbit-aml

moonbit-aml is a deterministic, explainable transaction-monitoring library written in MoonBit. It provides a small domain model for transactions and alerts, composable rules for batch evaluation, risk scoring, graph signals, analyst cases, and a bounded streaming adapter. The library has no database or service dependency, so it can be embedded in payment, compliance, or risk-control systems.

#Core capabilities

  • Inclusive amount, frequency, volume, region, currency, rapid-movement, and structuring rules.
  • Stable alert evidence containing the rule identifier, transaction identifier, and matching facts.
  • Validation and normalization for batch ingestion, including duplicate removal and malformed-record reporting.
  • Time-window utilities, moving totals, transaction summaries, and deterministic ordering.
  • Customer/account/transaction relationship graphs and shared-account signals.
  • Transparent risk scores, severity bands, case grouping, status transitions, and policy enable/disable controls.
  • A bounded in-memory stream processor for adapters that receive events incrementally.

#Quick start

Requirements: the current stable MoonBit CLI installed from the official installer.

moon update moon fmt --check moon check --deny-warn moon test --deny-warn

let transaction = @aml.Transaction::new(
id~="tx-001", customer_id~="customer-7", account_id~="account-7",
amount~=12500, currency~="CNY", region~="CN", occurred_at~=1700000000,
)
let rule = @aml.Rule::amount_at_least("large-transfer", 10000)
let alerts = @aml.evaluate([rule], [transaction])

Every returned alert includes explainable evidence. For ingestion paths that need validation, use evaluate_validated and inspect both outputs.

#CLI

The repository includes a native smoke-test CLI that demonstrates embedding the package:

moon run src/cmd/aml # alerts=1

Production applications can construct transactions from their own transport layer and pass them to the library; storage, authentication, and transport remain outside this package by design.

#Architecture

The module uses one public facade package under src/ and cohesive implementation files:

AreaFilesResponsibility
Domainmodel.mbt, validation.mbtTransactions, alerts, lifecycle, normalization
Detectionrules.mbt, aml.mbt, window.mbtRule definitions, evaluation, closed intervals
Risk workflowscore.mbt, case.mbt, policy.mbtScores, cases, policies
Analyticsaggregate.mbt, graph.mbt, report.mbtSummaries, relationships, reports
Adaptersstream.mbt, cmd/amlBounded event processing and executable example

Public concrete types are owned by the facade package. Functions are deterministic and do not mutate caller-owned arrays.

#Benchmarks

The benchmark record in benchmarks/README.md is generated from commands run against the checked-in revision and records the toolchain, fixture sizes, elapsed time, and test result. Re-run it locally with the commands shown there; no synthetic throughput number is claimed.

#Testing and quality gates

The test suite covers exact threshold and closed-window boundaries, future events, empty batches, normalization, malformed records, graph relationships, stream eviction, disabled policies, scoring, and case workflow.

moon fmt --check moon check --deny-warn moon test --deny-warn moon test --enable-coverage moon coverage report -f summary moon info

#CI

GitHub Actions runs formatting, warning-denied checks, API interface generation, tests, and coverage on Ubuntu, macOS, and Windows for pushes and pull requests. It installs the current stable MoonBit CLI using the official installer and runs moon update before validation. Publishing is a manual workflow that performs the same checks before calling moon publish.

#License

Apache-2.0. See LICENSE.

⚠️ Package is too large to be displayed

This package contains over 1862 items.