{"id":31801265,"url":"https://github.com/cosmicmind/rust-tx-ledger","last_synced_at":"2025-10-10T23:58:07.345Z","repository":{"id":316512304,"uuid":"1063696907","full_name":"CosmicMind/rust-tx-ledger","owner":"CosmicMind","description":"A streaming transaction ledger with ordered routing by client id.","archived":false,"fork":false,"pushed_at":"2025-09-25T02:02:58.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"release","last_synced_at":"2025-09-25T04:11:01.296Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CosmicMind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-25T02:00:50.000Z","updated_at":"2025-09-25T02:21:12.000Z","dependencies_parsed_at":"2025-09-25T04:11:05.281Z","dependency_job_id":"b3569129-b497-4442-b56f-939b9d8c1cbb","html_url":"https://github.com/CosmicMind/rust-tx-ledger","commit_stats":null,"previous_names":["cosmicmind/rust-tx-ledger"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/CosmicMind/rust-tx-ledger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmicMind%2Frust-tx-ledger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmicMind%2Frust-tx-ledger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmicMind%2Frust-tx-ledger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmicMind%2Frust-tx-ledger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CosmicMind","download_url":"https://codeload.github.com/CosmicMind/rust-tx-ledger/tar.gz/refs/heads/release","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmicMind%2Frust-tx-ledger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005575,"owners_count":26083921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-10T23:58:06.297Z","updated_at":"2025-10-10T23:58:07.339Z","avatar_url":"https://github.com/CosmicMind.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rust-tx-ledger\n\nA streaming transaction ledger with ordered routing by client id.\n\n## Overview\n\nThis project implements a toy ledger engine inspired by real-world transaction\nprocessing systems. It ingests transactions from a CSV file, validates and\nroutes them through a streaming pipeline, applies account state transitions, and\nwrites results to output files.\n\n---\n\n## Pipeline\n\n```text\nProvider (CSV)\n    ↓\nBroker (fan-out by client_id)\n    ↓\nPartitions (per-client state)\n    ↓\nPartitionWriter (accounts.csv, stdout)\n\n└──────────────→ DlqWriter (dlq.csv)\n```\n\n- **Provider**: Reads the input CSV line-by-line and validates each transaction.\n  - Good rows become `DataMessage`s sent to the Broker.\n  - Bad rows become `DlqMessage`s sent to the DLQ Writer.\n\n- **Broker**: Routes each message to a partition, keyed by client id\n  (`client_id % partition_count`).\n\n- **Partition**: Owns a set of accounts (per client). Applies transactions\n  (deposits, withdrawals, disputes, resolves, chargebacks).\n\n- **PartitionWriter**: Collects the final account maps from each partition at\n  shutdown and writes them to `accounts.csv` (stdout by default).\n\n- **DlqWriter**: Writes rejected or malformed transactions to `dlq.csv` with\n  structured error reasons.\n\n---\n\n## Invariants\n\n- **Input order preserved**: Provider uses blocking sends.\n- **Per-client FIFO**: Broker is the sole sender for each partition.\n- **Amounts**:\n  - Displayed truncated to 4 decimal places (floor).\n  - Arithmetic preserves full precision until display.\n- **Idempotency**: Duplicate `tx` ids per client are ignored.\n\n---\n\n## Concurrency\n\n- Tokio runtime.\n- Bounded `mpsc` channels for backpressure.\n- No `unsafe` code.\n\n---\n\n## CLI\n\nThe binary accepts the following options:\n\n| Flag                            | Description                                      | Default       |\n|---------------------------------|--------------------------------------------------|---------------|\n| `--data-message-capacity`       | Broker inbound queue capacity                    | 1024          |\n| `--partition-message-capacity`  | Partition inbound queue capacity                 | 1024          |\n| `--partition-thread-count`      | Number of partitions (≥2, default = CPU count)   | num_cpus      |\n| `--dlq-message-capacity`        | DLQ writer queue capacity                        | 1024          |\n| `--dlq-output-path PATH`        | DLQ output file                                  | dlq.csv       |\n\n---\n\n## Example\n\n```bash\ncargo run -- transactions.csv \u003e accounts.csv\n# Produces accounts.csv (stdout) and dlq.csv (side file for bad rows).\n```\n\n---\n\n## Sample Output\n\n### accounts.csv\n\n```csv\nclient,available,held,total,locked\n1,1.0341,0.0000,1.0341,false\n2,1.4658,0.0000,1.4658,false\n```\n\n### dlq.csv\n\n```csv\nline,byte,reason,raw\n5,85,\"csv deserialize: unknown variant `1`\",\"1,3,0.5\"\n7,117,zero amount,\"withdrawal,1,5,0\"\n9,165,negative amount,\"withdrawal,2,7,-0.10\"\n```\n\n---\n\n## Notes\n\n- `Cursor` positions are attached to each message, enabling replay and traceability.\n- Partitioning strategy is pluggable; currently simple modulo hashing is used.\n- This is a learning exercise: code emphasizes clarity and composable patterns\n  (Tokio, channels, oneshot, `rust_decimal` for amounts).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmicmind%2Frust-tx-ledger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosmicmind%2Frust-tx-ledger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmicmind%2Frust-tx-ledger/lists"}