/account-mgmt

🤖 AI codegen: Example Account Management project generated by ChatGPT4. Provides commands for buy/selling from a set of accounts and re-balancing money across those accounts.

Primary LanguageTypeScript

Account Management Language example by ChatGPT4

This project was generated almost entirely by ChatGPT4.

This software provides a set of commands that you can use to specify a list of accounts and the amount of money in each account, and then allow you to provide a "plan" to redistribute money across the accounts so that account A has 20%, account B has 30% and etc. whatever you want.

Background

I've been using ChatGPT to create some personal software projects, nothing for work yet. A pattern that I have found useful is to describe what I want to do in a couple of paragraphs and then ask ChatGPT to create a Software Design Spec for me, in Markdown format. Then, I use some prompts to refine ChatCPT's spec.

Next I ask ChatGPT to implement the spec in a specific language with a build and run script, to display the directory structure of the project and then to provide complete listings of every file required. I enter that code into my IDE and try to build an run it. When I encounter error messages, I paste them into ChatGPT and I get a fix. As I encounter bugs and problems in the code, I add new requirements and coding rules to the spec document generated by ChatGPT.

Once the code looks good and is partially working, I ask ChatGPT to regenerate the entire project based on the amended spec document. Then I fix errors, debug and continue to amend the original spec from ChatGPT. Rinse and repeat: I iterate on this process until things actually work. For this project, I probably spent 4 hours tweaking the prompt, fussing at ChatGPT and debugging things.

Everything after this point is a prompt for ChatGPT:

Provide a complete implementation of this specification, paying careful attention to the Implementation Rules and Specifications section, double check that the implementation meets those requirements! First display the projects file and directory structure. Then provide the listings of all files, complete implementations of each and every function. Do not leave any code for me to write.

Software Design Document: Account Management Language

1. Introduction

The Account Management Language (AML) is a command-line interface implemented in TypeScript that allows users to manage accounts holding money. The system supports operations like adding accounts, selling amounts from an account, buying amounts into an account, planning, and executing account rebalances. The commands are callable from a bash command line via the Commander library. All data persists between command line invocations as they are stored in a JSON file.

2. AML Commands

2.1 add <account-name> <account-amount>

This command creates a new account with the specified name and initial amount.

Inputs:

  • <account-name>: An alphanumeric string with no spaces, which will serve as the unique identifier for the account.
  • <account-amount>: A numerical value specifying the initial amount in the account.

2.2 sell <account-name> <sell-amount>

This command sells a specified amount from an existing account. The sold amount goes into the cash-on-hand account.

Inputs:

  • <account-name>: The name of an existing account.
  • <sell-amount>: A numerical value specifying the amount to be sold from the account.

2.3 buy <account-name> <buy-amount>

This command buys a specified amount into an existing account. The bought amount comes out of the cash-on-hand account.

Inputs:

  • <account-name>: The name of an existing account.
  • <buy-amount>: A numerical value specifying the amount to be bought into the account.

2.4 plan <csv-file>

This command generates a list of commands that, when executed, will re-balance accounts according to a specified plan provided as a CSV file. It doesn't execute the commands, it just prints them out.

Inputs:

  • <csv-file>: A CSV file with two columns - account_name and percentage. The account_name is the name of an existing account, and the percentage is a numerical value representing the desired proportion of the total investment for that account.

2.5 execute <csv-file>

This command re-balances accounts according to a specified plan provided as a CSV file. After the rebalance is done, the data is saved.

Inputs:

  • <csv-file>: A CSV file with two columns - account_name and percentage. The account_name is the name of an existing account, and the percentage is a numerical value representing the desired proportion of the total investment for that account.

2.6 list

This command lists all existing accounts, their amounts, and their proportions of the total investment across all accounts.

2.7 help [command]

This command displays help for a specific command.

3. AML Software Structure

The AML software has several integral components:

  • AccountManager: This TypeScript class maintains a list of accounts and their amounts, including a cash-on-hand account.

  • Account: This interface represents each account with name and amount properties.

  • ParseCSV: This class is responsible for parsing CSV files for the plan and execute commands.

  • Project Files: The system includes Account.ts, AccountManager.ts, ParseCSV.ts, package.json, tsconfig.json, AccountManager.test.ts, with all js files being ignored by .gitconfig.

4. Implementation Rules and Specifications

  • The TypeScript code does not use implicit any.
  • Account names must be alphanumeric without spaces or special characters.
  • Accounts are stored using a Map<String, Account>, with Account names as the map keys. When displayed, they are listed alphabetically.
  • Display of accounts uses a table with borders using the cli-table3 library.
  • The package.json file includes commands for build, start, and test, and lists all dependencies used in the TypeScript code.
  • Jest tests are provided for each function of AccountManager.ts, and Jest config is present in package.json.
  • The plan and execute commands share the logic for calculating new account balances and creating the list of buy and sell operations. When creating a buy/sell plan, all sells are done first.
  • There is a TUTORIAL.md document providing a tutorial on using the AML, with examples using at least four accounts and a plan.csv file for rebalancing.

5. Future Improvements

Future enhancements could include implementing transaction history, interest calculations, transaction fees, more complex rebalancing strategies, and improved error handling and validation.