A comprehensive command-line inventory management system for small retail stores, built with Rust. This system provides secure authentication, product management, sales tracking, purchase recording, detailed reporting capabilities, and persistent data storage.
- Authentication: Secure login system for store managers
- Product Management: Add, update, remove, and view products with validation
- Inventory Tracking: Real-time inventory quantity management
- Sales Recording: Track sales with automatic profit calculations
- Purchase Management: Record purchases and automatically update inventory
- Reporting: Generate detailed reports with human-readable timestamps
- Data Persistence: JSON-based storage in organized
data/directory - Data Validation: Input validation using the
validatorcrate - CLI Interface: User-friendly command-line interface with short and long flags
- Comprehensive Testing: Full test suite covering all core functionality
- Rust (latest stable version)
- Cargo (comes with Rust)
-
Clone the repository:
git clone <repository-url> cd rust-store-inventory-management-system
-
Build the project:
cargo build --release
-
Run the application:
cargo run -- --help
The system includes a comprehensive test suite with 13 unit tests covering all core functionality:
# Run all tests
cargo test
# Run tests with verbose output
cargo test -- --nocapture
# Run specific test module
cargo test inventory::tests
cargo test purchase::tests
cargo test sales::tests-
Inventory Management Tests (5 tests):
test_add_item: Validates successful product additiontest_remove_item: Validates product removaltest_update_item: Validates product updatestest_get_item: Validates product retrievaltest_add_invalid_item: Validates input validation for invalid products
-
Purchase Management Tests (5 tests):
test_record_purchase: Validates successful purchase recordingtest_record_purchase_invalid_product_name: Validates empty product name rejectiontest_record_purchase_invalid_quantity: Validates zero quantity rejectiontest_record_purchase_invalid_price: Validates zero price rejectiontest_record_purchase_invalid_description: Validates empty description rejection
-
Sales Management Tests (3 tests):
test_record_sale: Validates successful sale recordingtest_record_sale_insufficient_stock: Validates insufficient inventory handlingtest_record_sale_invalid_product_name: Validates product existence validation
All tests use proper error handling and validate both successful operations and edge cases.
The system requires authentication before accessing any functionality:
- Username:
store_manager - Password:
pass1234
Add a new product to the inventory:
cargo run -- add-product --name "Product Name" --price 19.99 --quantity 100 --description "Product description"
# Or using short flags:
cargo run -- add-product -n "Product Name" -p 19.99 -q 100 -d "Product description"Update an existing product's details:
cargo run -- update-product --name "Product Name" --price 24.99 --quantity 150 --description "Updated description"
# Or using short flags:
cargo run -- update-product -n "Product Name" -p 24.99 -q 150 -d "Updated description"Remove a product from inventory:
cargo run -- remove-product "Product Name"View details of a specific product:
cargo run -- show-product --name "Product Name"
# Or using short flags:
cargo run -- show-product -n "Product Name"Record a purchase and automatically update inventory:
cargo run -- record-purchase --product-name "Product Name" --quantity 50 --purchase-price 15.00 --description "Supplier ABC"
# Or using short flags:
cargo run -- record-purchase -n "Product Name" -q 50 -p 15.00 -d "Supplier ABC"Record a sale and update inventory:
cargo run -- record-sale --product-name "Product Name" --quantity 5 --sale-price 25.00
# Or using short flags:
cargo run -- record-sale -n "Product Name" -q 5 -s 25.00Generate various types of reports with human-readable timestamps:
Inventory Report:
cargo run -- report --report-type inventory
# Or using short flags:
cargo run -- report -r inventorySales Report:
cargo run -- report --report-type sales
# Or using short flags:
cargo run -- report -r salesPurchase Report:
cargo run -- report --report-type purchase
# Or using short flags:
cargo run -- report -r purchasesrc/
├── main.rs # Main application entry point and CLI handling
├── auth.rs # Authentication module
├── inventory.rs # Product and inventory management
├── sales.rs # Sales recording and tracking
├── purchase.rs # Purchase recording and inventory updates
├── report.rs # Report generation with formatted timestamps
└── persistence.rs # Generic data persistence with JSON storage
data/ # Data storage directory (auto-created)
├── inventory.json # Product inventory data
├── sales.json # Sales transaction history
└── purchases.json # Purchase transaction history
name: String (1-50 characters)price: f64 (positive value)quantity: u32description: String
product_name: Stringquantity: u32sale_price: f64profit: f64 (calculated automatically)total: f64 (calculated automatically)timestamp: DateTime (formatted as "YYYY-MM-DD HH:MM:SS UTC")
product_name: Stringquantity: u32purchase_price: f64total_cost: f64 (calculated automatically)timestamp: DateTime (formatted as "YYYY-MM-DD HH:MM:SS UTC")
clap: Command-line argument parsing with short and long flagsvalidator: Data validation with custom error messagesserde&serde_json: JSON serialization and deserializationchrono: Date and time handling with human-readable formatting
- Location: All data files are stored in the
data/directory - Format: JSON files for easy inspection and portability
- Auto-creation: The
data/directory is created automatically if it doesn't exist - Persistence: Data is automatically saved after each operation
The system includes comprehensive error handling for:
- Invalid authentication credentials
- Product not found scenarios
- Insufficient inventory for sales
- Data validation failures
- File I/O operations
- JSON parsing errors
- Password-protected access with authentication requirement
- Input validation and sanitization for all user inputs
- Safe memory management with Rust's ownership system
- Proper error handling without exposing sensitive information
For faster usage, the following short flags are available:
-n, --nameor--product-name: Product name-p, --priceor--purchase-price: Price/purchase price-q, --quantity: Quantity-d, --description: Description-s, --sale-price: Sale price-r, --report-type: Report type (inventory, sales, purchase)
SALES REPORT
============
Product: Apple | Qty: 5 | Price: $1.50 | Total: $7.50 | Profit: $2.50 | Date: 2025-07-31 14:39:43 UTC
Total Sales: $7.50 | Total Profit: $2.50