Skip to content

CodeMan62/trasect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transaction Service

A Rust-based transaction processing service built with Axum and PostgreSQL.

Quick Start

# Start PostgreSQL
docker-compose up -d

# Set database URL
export DATABASE_URL="postgresql://postgres:password@localhost:5432/transaction_service"

# Run the service
cargo run

The service starts on http://localhost:8080

Test with cURL

1. Health Check

curl http://localhost:8080/health

2. Create Two Accounts

# Create account 1
curl -X POST http://localhost:8080/accounts \
  -H "Content-Type: application/json" \
  -d '{"business_id": "business-001", "currency": "USD"}'

# Create account 2  
curl -X POST http://localhost:8080/accounts \
  -H "Content-Type: application/json" \
  -d '{"business_id": "business-002", "currency": "USD"}'

3. Credit $150 to Account 1

curl -X POST http://localhost:8080/transactions \
  -H "Content-Type: application/json" \
  -d '{"transaction_type": "credit", "amount": "15000", "destination_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "description": "Initial deposit", "reference": "DEP-001"}'

4. Debit $50 from Account 1

curl -X POST http://localhost:8080/transactions \
  -H "Content-Type: application/json" \
  -d '{"transaction_type": "debit", "amount": "5000", "source_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "description": "Withdrawal", "reference": "WD-001"}'

5. Transfer $30 from Account 1 to Account 2

curl -X POST http://localhost:8080/transactions \
  -H "Content-Type: application/json" \
  -d '{"transaction_type": "transfer", "amount": "3000", "source_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "destination_account_id": "26bd0b87-d488-4fa2-977c-e41a590820fc", "description": "Transfer", "reference": "TXF-001"}'

6. Check Account Balances

# Account 1 (should be $70.00 = 7000 cents)
curl http://localhost:8080/accounts/b19a4d42-9f0f-4f82-856c-2e7af018e88a

# Account 2 (should be $30.00 = 3000 cents)
curl http://localhost:8080/accounts/26bd0b87-d488-4fa2-977c-e41a590820fc

7. Test Error Handling

# Test insufficient balance
curl -X POST http://localhost:8080/transactions \
  -H "Content-Type: application/json" \
  -d '{"transaction_type": "debit", "amount": "20000", "source_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "description": "Large withdrawal", "reference": "WD-002"}'

# Test invalid account
curl http://localhost:8080/accounts/invalid-uuid

Save this as test.sh, make it executable (chmod +x test.sh), and run it with ./test.sh.

API Endpoints

Method Endpoint Description
GET /health Health check
POST /accounts Create account
GET /accounts/{id} Get account details
POST /transactions Process transaction

Data Format

  • Amounts: Stored as integers in cents (e.g., 1000 = $10.00)
  • Account IDs: UUID format
  • Transaction Types: credit, debit, transfer
  • Currency: 3-letter ISO codes (USD, EUR, etc.)

Architecture

  • Web Framework: Axum (async Rust)
  • Database: PostgreSQL with SQLx
  • Migrations: Automatic on startup
  • Transactions: ACID compliant with database transactions

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages