A command-line expense tracking application written in Go that helps you manage and analyze your personal expenses.
- Add expenses with description, amount, and category
- Update existing expenses
- Delete expenses
- View all expenses in a formatted list
- Get expense summaries (total and monthly)
- JSON-based persistent storage
- Concurrent-safe operations
- Go 1.20 or higher
- Git
- Clone the repository
git clone https://github.com/yourusername/expense-tracker.git
cd expense-tracker
- Build the application
go build -o expense-tracker cmd/expense-tracker/main.go
- Set the data file path
export EXPENSES_FILE_PATH=/path/to/custom/expenses.json
- (Optional) Add to PATH
sudo mv expense-tracker /usr/local/bin/
expense-tracker add --description "Lunch" --amount 20 --category "food"
# Expense added successfully (ID: 1)
expense-tracker list
# ID Date Description Amount Category
# 1 2024-08-06 Lunch $20.00 food
# 2 2024-08-06 Dinner $30.00 food
# Total summary
expense-tracker summary
# Total expenses: $50.00
# Monthly summary
expense-tracker summary --month 2024-08
# Total expenses for August: $50.00
expense-tracker update --id 1 --description "Late Lunch" --amount 25
# Expense updated successfully
expense-tracker delete --id 1
# Expense deleted successfully
expense-tracker add --description <desc> --amount <amount> [--category <category>]
--description
: Description of the expense (required)--amount
: Amount spent (required, must be positive)--category
: Category of expense (optional, defaults to "misc")
expense-tracker list
Shows all expenses in a tabulated format.
expense-tracker update --id <id> [--description <desc>] [--amount <amount>] [--category <category>]
--id
: ID of the expense to update (required)--description
: New description (optional)--amount
: New amount (optional)--category
: New category (optional)
expense-tracker delete --id <id>
--id
: ID of the expense to delete (required)
expense-tracker summary [--month <year>-<month>]
--month
: Month number (1-12) for monthly summary (optional)
.
├── cmd
│ └── expense-tracker
│ └── main.go
├── internal
│ ├── cli
│ │ └── cli.go
│ ├── models
│ │ └── expense.go
│ ├── repository
│ │ ├── interface.go
│ │ └── file
│ │ └── repository.go
│ └── service
│ └── expense_service.go
├── pkg
│ └── utils
│ └── date.go
├── go.mod
└── README.md
Expenses are stored in a JSON file (expenses.json
) in the current directory. The file is created automatically when the first expense is added. The storage is concurrent-safe and can handle multiple operations simultaneously.
The application includes comprehensive error handling for:
- Invalid input values (negative amounts, invalid dates)
- Non-existent expense IDs
- File operations
- Data validation
go test ./...
- Fork the repository
- Create a feature branch
- Implement your changes
- Add tests
- Submit a pull request
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to the Go community for the excellent standard library
- Inspired by various CLI applications and expense tracking tools