Skip to content

himanshu634/simple-banking-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 Rust Banking System

A comprehensive CLI-based banking application built with Rust, demonstrating advanced programming concepts and best practices.

🌟 Features

  • Customer Management: Register new customers with unique IDs
  • Account Operations: Create accounts with initial deposits
  • Transactions:
    • Deposit money
    • Withdraw money
    • Transfer between accounts
  • Transaction History: View detailed transaction logs with timestamps
  • Data Persistence: Automatic saving/loading of bank data in JSON format
  • Search & Statistics: Search customers and view comprehensive bank statistics

πŸ¦€ Rust Concepts Demonstrated

This project showcases a wide range of Rust concepts:

1. Ownership & Borrowing

  • Transfer of ownership in Customer/Account creation
  • Immutable and mutable borrowing (&self, &mut self)
  • Reference lifetimes in method signatures
  • Documentation

2. Smart Pointers

  • Arc<T>: Thread-safe reference counting
  • Mutex<T>: Thread-safe interior mutability
  • Documentation

3. Error Handling

  • Custom error types with enums
  • Result<T, E> for recoverable errors
  • Option<T> for optional values
  • Error propagation with ? operator
  • Documentation

4. Traits

  • Custom trait definition (Summarizable)
  • Trait implementation for multiple types
  • Derived traits (Debug, Clone, Serialize, etc.)
  • Documentation

5. Iterators & Closures

  • Iterator methods: filter, map, sum, collect, any, enumerate
  • Closures with different capture modes
  • Lazy evaluation
  • Documentation

6. Pattern Matching

  • Match expressions
  • if let / while let
  • Destructuring in patterns
  • Documentation

7. Collections

  • Vec<T>: Dynamic arrays
  • HashMap<K, V>: Key-value storage for O(1) lookups
  • String vs &str
  • Documentation

8. Serialization

  • Serde for JSON serialization/deserialization
  • Derive macros
  • Documentation

9. Type System

  • Type aliases (BankResult<T>)
  • Generic types (Vec<T>, HashMap<K,V>, etc.)
  • Documentation

10. Modules & Visibility

  • pub keyword for public APIs
  • Struct field visibility
  • Documentation

πŸ“¦ Dependencies

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
chrono = { version = "0.4", features = ["serde"] }
uuid = { version = "1.0", features = ["v4", "serde"] }

πŸš€ Installation & Usage

Prerequisites

  • Rust 1.70 or higher
  • Cargo (comes with Rust)

Build & Run

# Clone or navigate to the project directory
cd rust-banking-system

# Build the project
cargo build --release

# Run the application
cargo run --release

πŸ’‘ Usage Example

╔═══════════════════════════════════════════╗
β•‘   🏦  RUST BANKING SYSTEM CLI v1.0  🏦   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

═══════════════════════════════════════════
                MAIN MENU
═══════════════════════════════════════════
  1. πŸ“ Register New Customer
  2. πŸ’³ Create Account for Customer
  3. πŸ’° Deposit Money
  4. πŸ’Έ Withdraw Money
  5. πŸ”„ Transfer Money
  6. πŸ“Š View Account Details
  7. πŸ“œ View Transaction History
  8. πŸ‘₯ List All Customers
  9. πŸ” Search Customers
 10. πŸ“ˆ View Bank Statistics
 11. πŸ’Ύ Save Data
  0. πŸšͺ Exit
═══════════════════════════════════════════

Workflow Example

  1. Register a Customer

    Enter your choice: 1
    Enter customer name: John Doe
    Enter customer email: john@example.com
    
  2. Create an Account

    Enter your choice: 2
    Enter customer ID: [paste customer ID]
    Enter initial deposit amount: 1000
    
  3. Make a Deposit

    Enter your choice: 3
    Enter customer ID: [paste customer ID]
    Enter amount to deposit: 500
    
  4. Transfer Money

    Enter your choice: 5
    Enter sender customer ID: [sender ID]
    Enter recipient customer ID: [recipient ID]
    Enter amount to transfer: 200
    

πŸ—‚οΈ Data Persistence

The application automatically saves all data to bank_data.json in the project directory. This file is:

  • Created automatically on first save
  • Loaded automatically on application start
  • Updated when you select "Save Data" or exit the application

πŸ—οΈ Architecture

β”œβ”€β”€ Error Handling (BankError enum)
β”œβ”€β”€ Transaction System
β”‚   β”œβ”€β”€ TransactionType enum
β”‚   └── Transaction struct
β”œβ”€β”€ Core Banking
β”‚   β”œβ”€β”€ Account struct
β”‚   β”œβ”€β”€ Customer struct
β”‚   └── Bank struct
β”œβ”€β”€ Traits (Summarizable)
β”œβ”€β”€ CLI Interface (BankCLI)
└── Persistence Layer (JSON)

πŸ§ͺ Testing the Application

# Build and run
cargo run

# Build with optimizations
cargo build --release

# Check for issues
cargo check

# Format code
cargo fmt

# Run linter
cargo clippy

πŸ“š Learning Resources

πŸ”’ Security Notes

  • Customer IDs and Account IDs are generated using UUIDs (v4)
  • All monetary amounts use f64 for simplicity (in production, use decimal types)
  • Data is stored in plaintext JSON (in production, consider encryption)

🎯 Advanced Features Implemented

  1. Thread-Safe Design: Uses Arc<Mutex<T>> for concurrent access
  2. Functional Programming: Extensive use of iterators and closures
  3. Type Safety: Strong typing with custom error types
  4. Zero-Cost Abstractions: Efficient compiled code
  5. Memory Safety: No garbage collector, no null pointers
  6. Pattern Matching: Exhaustive matching for safety

πŸ› οΈ Future Enhancements

  • Multi-threaded transaction processing
  • Database integration (SQLite/PostgreSQL)
  • Web API interface (using Actix/Rocket)
  • Authentication and authorization
  • Interest calculation
  • Loan management
  • Transaction reversal/cancellation
  • Audit logging

πŸ“ License

This project is created for educational purposes to demonstrate Rust programming concepts.

🀝 Contributing

Feel free to fork, modify, and use this project for learning Rust!


Built with ❀️ using Rust πŸ¦€

About

Created simple banking application to learn the basics of rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages