A simple, efficient command-line expense tracking application written in Go.
- ✅ Add expenses with amount, category, and optional description
- 📋 List all expenses with totals
- 🗑️ Delete expenses by ID
- 📊 View expense summary by category with percentages
- 🔍 Filter expenses by category
- 📅 Filter expenses by date range
- 📂 List all available categories
- 💾 Export expenses to CSV format
- 🔒 Thread-safe data persistence using JSON
- 🧪 Comprehensive test coverage (95%+)
- 🐳 Docker support for containerized deployment
git clone https://github.com/codeforgood-org/go-expense-tracker.git
cd go-expense-tracker
go build -o expense-tracker ./cmd/expense-trackergo install github.com/codeforgood-org/go-expense-tracker/cmd/expense-tracker@latest# Build the image
docker-compose build
# Run commands
docker-compose run expense-tracker add 50.00 groceries "Weekly shopping"
docker-compose run expense-tracker list
docker-compose run expense-tracker summarymake build # Build the binary
make install # Install to $GOPATH/bin
make test # Run tests# Add expense with amount and category
./expense-tracker add 50.00 groceries
# Add expense with description
./expense-tracker add 25.50 transport "Taxi to airport"
./expense-tracker add 120.00 entertainment "Concert tickets"./expense-tracker listOutput:
📊 All Expenses:
--------------------------------------------------------------------------------
ID: abc123de | $120.00 | entertainment | 2025-11-13 - Concert tickets
ID: def456gh | $25.50 | transport | 2025-11-13 - Taxi to airport
ID: ghi789jk | $50.00 | groceries | 2025-11-13
--------------------------------------------------------------------------------
Total: $195.50
./expense-tracker delete abc123de
# or use short aliases
./expense-tracker del abc123de
./expense-tracker rm abc123de./expense-tracker summary
# or use short alias
./expense-tracker sumOutput:
💰 Expense Summary by Category:
------------------------------------------------------------
entertainment $ 120.00 ( 61.5%)
groceries $ 50.00 ( 25.6%)
transport $ 25.50 ( 13.1%)
------------------------------------------------------------
TOTAL $ 195.50
./expense-tracker filter groceries# Filter expenses between two dates (YYYY-MM-DD format)
./expense-tracker range 2025-01-01 2025-01-31
./expense-tracker range 2025-11-01 2025-11-13Output:
📊 Expenses from 2025-11-01 to 2025-11-13:
--------------------------------------------------------------------------------
ID: abc123de | $120.00 | entertainment | 2025-11-13 - Concert tickets
ID: def456gh | $25.50 | transport | 2025-11-10 - Taxi to airport
--------------------------------------------------------------------------------
Total: $145.50
# Export all expenses to CSV file
./expense-tracker export
# Export with custom filename
./expense-tracker export my_expenses.csv
./expense-tracker export reports/november_2025Output creates a CSV file with columns: ID, Date, Amount, Category, Description
./expense-tracker categories
# or use short alias
./expense-tracker cats# Use the provided script to generate sample expenses for testing
./scripts/generate_sample_data.sh./expense-tracker help
# or
./expense-tracker -h
./expense-tracker --help./expense-tracker version
# or
./expense-tracker -v
./expense-tracker --versiongo-expense-tracker/
├── .github/
│ └── workflows/
│ └── ci.yml # GitHub Actions CI/CD
├── cmd/
│ └── expense-tracker/ # Main application entry point
│ └── main.go
├── internal/ # Private application code
│ ├── commands/ # CLI command handlers
│ │ └── commands.go
│ ├── models/ # Data models
│ │ ├── expense.go
│ │ └── expense_test.go
│ └── storage/ # Data persistence layer
│ ├── storage.go
│ └── storage_test.go
├── pkg/ # Public library code
│ └── utils/ # Utility functions
│ ├── utils.go
│ └── utils_test.go
├── scripts/ # Utility scripts
│ └── generate_sample_data.sh
├── .dockerignore
├── .gitignore
├── .golangci.yml # Linter configuration
├── CHANGELOG.md # Version history
├── CODE_OF_CONDUCT.md # Community guidelines
├── CONTRIBUTING.md # Contribution guidelines
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker image definition
├── go.mod # Go module definition
├── LICENSE # MIT License
├── Makefile # Build automation
└── README.md # This file
- Go 1.21 or higher
make build# Run all tests
make test
# Run tests with coverage
make test-coverage
# Run tests with verbose output
make test-verbose# Format code
make fmt
# Run linter
make lint
# Run all checks (fmt, lint, test)
make checkmake installExpenses are stored in a JSON file named expenses.json in the current directory. The file is automatically created when you add your first expense.
[
{
"id": "abc123de",
"amount": 50.00,
"category": "groceries",
"description": "Weekly shopping",
"date": "2025-11-13T10:30:00Z"
}
]# Using Docker Compose
docker-compose build
# Or using Docker directly
docker build -t go-expense-tracker .# Using Docker Compose (recommended)
docker-compose run expense-tracker add 50.00 groceries "Shopping"
docker-compose run expense-tracker list
docker-compose run expense-tracker summary
# Using Docker directly
docker run -v $(pwd)/data:/root/data go-expense-tracker add 50.00 groceries
docker run -v $(pwd)/data:/root/data go-expense-tracker listThe Docker setup includes:
- Multi-stage build for minimal image size
- Volume mounting for data persistence
- Alpine Linux base for security and size
- Non-root user execution (future enhancement)
Data is persisted in the ./data directory on your host machine, which is mounted to /root/data in the container.
The project includes comprehensive unit tests for all packages:
- Models: Validates expense data and string formatting
- Storage: Tests data persistence, CRUD operations, and filtering
- Utils: Verifies ID generation uniqueness and format
Run tests with:
go test -v ./...Coverage report:
make test-coverage
# Opens coverage.html in your browserContributions are welcome! Please see CONTRIBUTING.md for details.
This project is licensed under the MIT License - see the LICENSE file for details.
- Date range filtering
- Export to CSV
- Docker support
- Comprehensive testing
- CI/CD with GitHub Actions
- Budget tracking and alerts
- Monthly/yearly reports with visualizations
- Multi-currency support
- Recurring expenses
- Interactive charts and graphs (ASCII/terminal)
- Configuration file support
- Import from CSV
- Expense tags/labels
- Search functionality
- Backup and restore
For issues, questions, or contributions, please visit the GitHub repository.