A robust inventory management system written in Rust that helps track products, sales, and purchases.
- Clone the repository:
git clone https://github.com/mustafaangi/rusty-store.git
cd rusty-store
- Build the project:
cargo build --release
- Run the application:
cargo run
Username: admin
Password: admin123
- First run will create:
- users.json (user accounts)
- store.json (inventory and transactions)
- Login with default admin credentials
- Start adding products and managing inventory
-
Adding Products (Manager only):
- Login as admin
- Select "Add Product"
- Enter product details
-
Recording Sales:
- Select "Record Sale"
- Choose product from inventory
- Enter quantity
-
Recording Purchases:
- Select "Record Purchase"
- Choose product
- Enter quantity and price
-
Viewing Reports:
- Select "View Reports"
- Choose report type:
- Inventory
- Sales
- Purchases
rusty-store/
├── src/
│ ├── main.rs # Application entry
│ ├── auth.rs # Authentication
│ ├── store.rs # Core business logic
│ ├── models.rs # Data structures
│ ├── errors.rs # Error handling
│ └── lib.rs # Library interface
├── Cargo.toml
└── README.md
The system handles common errors:
- Invalid login credentials
- Insufficient inventory
- Product not found
- File system errors
- Invalid input values
Data is stored in JSON files:
users.json
: User accounts and rolesstore.json
: Products and transactions
cargo test
cargo doc --no-deps --open
RUST_LOG=debug cargo run
- Delete users.json to reset admin account
- Verify file permissions
- Check username/password carefully
- Ensure write permissions in directory
- Verify JSON files are not corrupted
- Check available disk space
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature
) - Commit changes (
git commit -m 'Add AmazingFeature'
) - Push branch (
git push origin feature/AmazingFeature
) - Open Pull Request
-
Authentication System (
auth.rs
)- User management
- Password hashing using bcrypt
- Role-based access (Manager/Employee)
- File-based user persistence
- Session management
-
Store Operations (
store.rs
)- Product CRUD operations
- Transaction handling
- Inventory management
- Report generation
- Data persistence
-
Data Models (
models.rs
)Product { id: UUID, name: String, description: String, price: f64, quantity: i32 } Transaction { id: UUID, product_id: UUID, quantity: i32, price: f64, transaction_type: Enum(Sale, Purchase), timestamp: DateTime<Utc> } User { id: UUID, username: String, password_hash: String, role: Enum(Manager, Employee) }
-
Manager
- Full system access
- Add/Edit/Delete products
- View all reports
- Record transactions
- Manage inventory
-
Employee
- View inventory
- Record sales
- Record purchases
- View reports
-
users.json
{ "username": { "id": "uuid", "username": "string", "password_hash": "string", "role": "Manager/Employee" } }
-
store.json
{ "products": { "product_id": { "id": "uuid", "name": "string", "description": "string", "price": float, "quantity": integer } }, "transactions": [ { "id": "uuid", "product_id": "uuid", "quantity": integer, "price": float, "transaction_type": "Sale/Purchase", "timestamp": "datetime" } ] }
-
Inventory Report
- Current stock levels
- Product details
- Pricing information
Inventory Report ================ Product: [name] Quantity: [number] Price: $[amount]
-
Sales Report
- Transaction history
- Total sales amount
- Individual sale details
Sales Report =========== Sale ID: [uuid] Product ID: [uuid] Quantity: [number] Price: $[amount] Total: $[amount]
-
Purchase Report
- Purchase history
- Total cost
- Individual purchase details
Purchase Report ============== Purchase ID: [uuid] Product ID: [uuid] Quantity: [number] Cost: $[amount] Total: $[amount]
-
Authentication Errors
- Invalid credentials
- User not found
- Password verification failed
-
Inventory Errors
- Insufficient stock
- Product not found
- Invalid quantity
-
File System Errors
- File not found
- Permission denied
- Corrupted data
-
Setting Up Development Environment
# Install Rust and Cargo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Clone and Build git clone https://github.com/yourusername/rusty-store.git cd rusty-store cargo build
-
Running Tests
# Run all tests cargo test # Run specific test cargo test test_authentication # Run with logging RUST_LOG=debug cargo test
-
Adding New Features
- Create feature branch
- Add tests first
- Implement feature
- Update documentation
- Submit PR