RockPile is a cooperative microeconomy system designed to pool all income into a shared fund, which is then used to pay for utilities, insurance, and other shared expenses. At the end of the month, any remaining funds are redistributed equally among the members of the cooperative. The system emphasizes transparency, community, and shared benefit.
This project provides a simple implementation of the RockPile fund management system in Rust, using JSON for data persistence. It includes the ability to manage members, expenses, income contributions, and monthly cycles, making it a practical tool for small cooperatives or other collective groups.
- Member Management: Add new members to the cooperative and track their monthly income.
- Expense Management: Add shared expenses and track their payments from the pooled fund.
- Income Contribution: Automatically add each member's income to the fund each month.
- Expense Deduction: Deduct expenses from the fund, with checks for sufficient balance.
- Fund Redistribution: Redistribute any remaining funds equally among the members at the end of the month.
- Data Persistence: Save and load the fund state from a JSON file for easy recovery.
- Monthly Cycle Automation: Run the monthly cycle to add income, pay expenses, and redistribute funds.
- Rust 1.60.0 or later
serdeandserde_jsoncrates for data serialization- Basic knowledge of Rust for further customization
-
Clone the repository:
git clone https://github.com/kieracarman/rockpile.git cd rockpile -
Build and run the project:
cargo run
-
If you don't have Rust installed, follow the installation instructions from the official Rust website.
-
src/: Contains all source code files for the application.main.rs: The main entry point of the application, where the menu and user input are managed.fund.rs: Contains theFundstruct and associated methods for managing members, expenses, income, and monthly cycles.member.rs: Contains theMemberstruct and methods for displaying and managing members.expense.rs: Contains theExpensestruct and methods for displaying and managing expenses.utils.rs: Contains utility functions likeget_valid_number,cents_to_dollars, andget_menu_choice.lib.rs: Serves as the module entry point for organizing the project structure.
-
Cargo.toml: The manifest file for managing dependencies and project configuration.
Once the project is running, you'll be presented with a menu where you can:
- View Fund State: Display the current fund balance, members, and expenses.
- Add a Member: Add a new member to the cooperative by entering their name and monthly income.
- Add an Expense: Add a shared expense with a description and amount.
- Run Monthly Cycle: Automatically add income, deduct expenses, and redistribute remaining funds to members.
- Save Fund to File: Save the current state of the fund to a
fund.jsonfile. - Load Fund from File: Load a saved fund state from the
fund.jsonfile. - Exit: Exit the program.
-
Start by adding members to the cooperative:
Enter a member's name: Alice Enter Alice's income in dollars: 1000 Member added successfully! -
Add some expenses:
Enter expense description: Rent Enter expense amount in dollars: 500 Expense added successfully! -
Run the monthly cycle:
--- Starting Monthly Cycle --- Alice contributed $1000.00. Paid $500.00 for Rent. Remaining funds: $500.00 Alice received a distribution of $500.00. --- End of Monthly Cycle --- -
Save or load the fund state using
fund.jsonfor persistence between runs.
The Fund struct manages the fund, members, and expenses.
- add_member(): Adds a new member to the cooperative.
- add_expense(): Adds a shared expense.
- add_income(): Adds income contributions from all members.
- deduct_expenses(): Deducts expenses from the fund.
- redistribute(): Redistributes remaining funds equally among members.
- display_total(): Displays the total balance in the fund.
- display_state(): Displays the current state of the fund, including members and expenses.
- monthly_cycle(): Runs a full monthly cycle: add income, deduct expenses, redistribute funds.
- save_to_file(file_path): Saves the current fund state to a file.
- load_from_file(file_path): Loads the fund state from a file.
- cents_to_dollars(i64): Converts a value in cents to a string representing dollars and cents.
- get_valid_number(prompt): Prompts the user for a valid positive number.
- get_menu_choice(prompt): Prompts the user for a valid menu choice.
- The cooperative members input their monthly income, which is stored in the
Fund. - Shared expenses are added to the
Fundand paid from the pool. - At the end of each month, the fund's balance is redistributed equally among all members.
- The state is saved to a file, allowing for persistence between sessions.
For questions or suggestions, please feel free to contact me via GitHub or open an issue in the repository.