Skip to content

Commit 655082b

Browse files
committed
feat: reorganize and enhance entire repository
Major refactoring and enhancements to transform the project into a professional, production-ready Go application. BREAKING CHANGE: Project structure completely reorganized from single file to modular architecture. Users will need to rebuild the application. Project Structure: - Implemented standard Go project layout with cmd/, internal/, pkg/ - Created separate packages for models, storage, and commands - Improved separation of concerns and maintainability New Features: - Added unique IDs for each expense - Implemented delete functionality - Added expense summary by category with percentages - Added category filtering - Added category listing - Support for expense descriptions - Thread-safe storage with mutex locks Code Quality: - Added comprehensive test coverage for all packages - Fixed deprecated ioutil usage (replaced with os package) - Implemented proper error handling and validation - Added concurrent-safe data access Documentation: - Created comprehensive README with examples and usage guide - Added CONTRIBUTING.md with development guidelines - Added detailed package documentation Build & Development: - Initialized Go modules - Created Makefile with common tasks (build, test, lint, etc.) - Added GitHub Actions CI/CD workflow - Multiple Go version testing (1.21, 1.22, 1.23) - Integrated linting and security scanning Enhanced .gitignore: - Added coverage reports - Added IDE-specific files - Added OS-specific files - Added application data files Files Changed: - Removed: expense-tracker.go (monolithic file) - Added: Proper project structure with 10+ new files - Modified: .gitignore with comprehensive exclusions Testing: - All tests passing with full coverage - Models validation tests - Storage CRUD operation tests - Utils ID generation tests
1 parent 420c8c9 commit 655082b

File tree

14 files changed

+1524
-103
lines changed

14 files changed

+1524
-103
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
build:
11+
name: Build and Test
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
go-version: ['1.21', '1.22', '1.23']
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: ${{ matrix.go-version }}
25+
26+
- name: Verify dependencies
27+
run: go mod verify
28+
29+
- name: Build
30+
run: go build -v ./cmd/expense-tracker
31+
32+
- name: Run tests
33+
run: go test -v -race -coverprofile=coverage.out ./...
34+
35+
- name: Upload coverage to Codecov
36+
if: matrix.go-version == '1.23'
37+
uses: codecov/codecov-action@v3
38+
with:
39+
file: ./coverage.out
40+
flags: unittests
41+
name: codecov-umbrella
42+
43+
lint:
44+
name: Lint
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Go
51+
uses: actions/setup-go@v5
52+
with:
53+
go-version: '1.23'
54+
55+
- name: Run golangci-lint
56+
uses: golangci/golangci-lint-action@v3
57+
with:
58+
version: latest
59+
60+
security:
61+
name: Security Scan
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
67+
- name: Run Gosec Security Scanner
68+
uses: securego/gosec@master
69+
with:
70+
args: './...'

.gitignore

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# If you prefer the allow list template instead of the deny list, see community template:
22
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3-
#
3+
44
# Binaries for programs and plugins
55
*.exe
66
*.exe~
77
*.dll
88
*.so
99
*.dylib
10+
expense-tracker
1011

1112
# Test binary, built with `go test -c`
1213
*.test
1314

1415
# Output of the go coverage tool, specifically when used with LiteIDE
1516
*.out
17+
coverage.out
18+
coverage.html
1619

1720
# Dependency directories (remove the comment below to include it)
1821
# vendor/
@@ -23,3 +26,17 @@ go.work.sum
2326

2427
# env file
2528
.env
29+
30+
# Application data
31+
expenses.json
32+
33+
# IDE specific files
34+
.vscode/
35+
.idea/
36+
*.swp
37+
*.swo
38+
*~
39+
40+
# OS specific files
41+
.DS_Store
42+
Thumbs.db

CONTRIBUTING.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# Contributing to Go Expense Tracker
2+
3+
Thank you for your interest in contributing to Go Expense Tracker! This document provides guidelines and instructions for contributing.
4+
5+
## Code of Conduct
6+
7+
By participating in this project, you agree to maintain a respectful and inclusive environment for all contributors.
8+
9+
## How to Contribute
10+
11+
### Reporting Bugs
12+
13+
Before creating a bug report, please check existing issues to avoid duplicates. When creating a bug report, include:
14+
15+
- A clear, descriptive title
16+
- Steps to reproduce the issue
17+
- Expected behavior vs. actual behavior
18+
- Your environment (OS, Go version, etc.)
19+
- Any relevant logs or screenshots
20+
21+
### Suggesting Enhancements
22+
23+
Enhancement suggestions are welcome! Please provide:
24+
25+
- A clear, descriptive title
26+
- Detailed description of the proposed enhancement
27+
- Use cases and benefits
28+
- Any relevant examples or mockups
29+
30+
### Pull Requests
31+
32+
1. **Fork the repository** and create your branch from `main`
33+
34+
```bash
35+
git clone https://github.com/codeforgood-org/go-expense-tracker.git
36+
cd go-expense-tracker
37+
git checkout -b feature/your-feature-name
38+
```
39+
40+
2. **Make your changes**
41+
- Follow the coding standards (see below)
42+
- Add tests for new functionality
43+
- Update documentation as needed
44+
45+
3. **Test your changes**
46+
47+
```bash
48+
# Run tests
49+
make test
50+
51+
# Run with coverage
52+
make test-coverage
53+
54+
# Format code
55+
make fmt
56+
57+
# Run linter
58+
make lint
59+
60+
# Run all checks
61+
make check
62+
```
63+
64+
4. **Commit your changes**
65+
66+
Use clear, descriptive commit messages following the conventional commits format:
67+
68+
```
69+
feat: add export to CSV functionality
70+
fix: correct date parsing in filter command
71+
docs: update README with new examples
72+
test: add tests for storage layer
73+
refactor: simplify expense validation logic
74+
```
75+
76+
5. **Push to your fork**
77+
78+
```bash
79+
git push origin feature/your-feature-name
80+
```
81+
82+
6. **Open a Pull Request**
83+
- Provide a clear title and description
84+
- Reference any related issues
85+
- Ensure all CI checks pass
86+
87+
## Development Setup
88+
89+
### Prerequisites
90+
91+
- Go 1.21 or higher
92+
- Git
93+
- Make (optional but recommended)
94+
95+
### Getting Started
96+
97+
```bash
98+
# Clone the repository
99+
git clone https://github.com/codeforgood-org/go-expense-tracker.git
100+
cd go-expense-tracker
101+
102+
# Install dependencies
103+
go mod download
104+
105+
# Build the project
106+
make build
107+
108+
# Run tests
109+
make test
110+
```
111+
112+
## Coding Standards
113+
114+
### Go Style Guide
115+
116+
- Follow [Effective Go](https://golang.org/doc/effective_go.html)
117+
- Use `gofmt` to format your code
118+
- Use meaningful variable and function names
119+
- Keep functions small and focused
120+
- Add comments for exported functions and types
121+
122+
### Code Organization
123+
124+
```
125+
cmd/ - Application entry points
126+
internal/ - Private application code
127+
commands/ - CLI command handlers
128+
models/ - Data models
129+
storage/ - Data persistence
130+
pkg/ - Public library code
131+
utils/ - Utility functions
132+
```
133+
134+
### Testing
135+
136+
- Write tests for all new functionality
137+
- Maintain or improve code coverage
138+
- Use table-driven tests where appropriate
139+
- Test both success and error cases
140+
141+
Example test structure:
142+
143+
```go
144+
func TestFeature(t *testing.T) {
145+
tests := []struct {
146+
name string
147+
input string
148+
want string
149+
wantErr bool
150+
}{
151+
// test cases
152+
}
153+
154+
for _, tt := range tests {
155+
t.Run(tt.name, func(t *testing.T) {
156+
// test implementation
157+
})
158+
}
159+
}
160+
```
161+
162+
### Documentation
163+
164+
- Update README.md for user-facing changes
165+
- Add godoc comments for exported functions and types
166+
- Update CHANGELOG.md (if exists) with notable changes
167+
168+
## Project Structure Guidelines
169+
170+
### Adding New Commands
171+
172+
1. Add command handler in `internal/commands/commands.go`
173+
2. Register command in `cmd/expense-tracker/main.go`
174+
3. Add tests in `internal/commands/commands_test.go`
175+
4. Update README.md with usage examples
176+
177+
### Adding New Storage Features
178+
179+
1. Implement in `internal/storage/storage.go`
180+
2. Add tests in `internal/storage/storage_test.go`
181+
3. Update commands to use new features
182+
4. Update documentation
183+
184+
### Adding New Models
185+
186+
1. Define in `internal/models/`
187+
2. Add validation methods
188+
3. Write comprehensive tests
189+
4. Update storage layer if needed
190+
191+
## Review Process
192+
193+
1. All submissions require review before merging
194+
2. Reviewers will check for:
195+
- Code quality and style
196+
- Test coverage
197+
- Documentation completeness
198+
- Breaking changes
199+
3. Address reviewer feedback promptly
200+
4. Maintain a single commit history (squash if needed)
201+
202+
## Release Process
203+
204+
Maintainers will:
205+
206+
1. Review and merge approved PRs
207+
2. Update version numbers
208+
3. Create release notes
209+
4. Tag releases following semantic versioning
210+
211+
## Getting Help
212+
213+
- Open an issue for questions
214+
- Join discussions in existing issues/PRs
215+
- Check the README.md for basic usage
216+
217+
## License
218+
219+
By contributing, you agree that your contributions will be licensed under the MIT License.
220+
221+
## Recognition
222+
223+
Contributors will be acknowledged in:
224+
- Git commit history
225+
- Release notes (for significant contributions)
226+
- Future CONTRIBUTORS.md file
227+
228+
Thank you for contributing to Go Expense Tracker!

0 commit comments

Comments
 (0)