|
| 1 | +# Development Guidelines |
| 2 | + |
| 3 | +Guidelines for contributing to DiskDive. |
| 4 | + |
| 5 | +## Platform Support |
| 6 | + |
| 7 | +All features must work on macOS 12+, Windows 10+, and modern Linux distributions. Use build tags (`_darwin.go`, `_windows.go`, `_other.go`) for platform-specific implementations. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +``` |
| 12 | +internal/ |
| 13 | + core/ # Pure business logic - no UI dependencies |
| 14 | + controller.go # Main application controller |
| 15 | + state.go # State types (ScanState, FreedState) |
| 16 | + events.go # Event types for UI communication |
| 17 | +
|
| 18 | + ui/tui/ # Terminal UI (Bubble Tea + Lipgloss) |
| 19 | + app.go # Main TUI application |
| 20 | + tree.go # Tree panel component |
| 21 | + treemap.go # Treemap visualization |
| 22 | + styles.go # Colors and styles |
| 23 | +
|
| 24 | + scanner/ # Filesystem scanning |
| 25 | + model/ # Data structures (Node, Drive) |
| 26 | + watcher/ # Filesystem change monitoring |
| 27 | + stats/ # Usage statistics persistence |
| 28 | +``` |
| 29 | + |
| 30 | +The `core` package contains all business logic and can be used by alternative frontends (GUI, web, etc.). |
| 31 | + |
| 32 | +## Code Quality |
| 33 | + |
| 34 | +### Principles |
| 35 | + |
| 36 | +- **Keep it simple.** Write the minimum code that solves the problem. |
| 37 | +- **No duplication.** Extract shared logic into functions. DRY. |
| 38 | +- **Single responsibility.** Each file/struct/function has one clear purpose. |
| 39 | +- **Readable over clever.** Clarity beats brevity. |
| 40 | +- **Fix root causes.** Don't add workarounds that mask bugs. |
| 41 | + |
| 42 | +### Go Conventions |
| 43 | + |
| 44 | +- Use existing solutions before writing custom code (stdlib, lipgloss, bubbletea) |
| 45 | +- Prefer specific parameters over passing entire structs |
| 46 | +- Use pointer receivers for methods that modify state |
| 47 | +- Value receivers for read-only methods |
| 48 | + |
| 49 | +### TUI Guidelines |
| 50 | + |
| 51 | +- Use lipgloss for all styling and layout |
| 52 | +- Use `lipgloss.Width()` for measuring rendered text width |
| 53 | +- Use `lipgloss.Place()`/`JoinHorizontal()`/`JoinVertical()` for layout |
| 54 | +- Only use `strings.Repeat()` for visual elements (progress bars), not layout spacing |
| 55 | + |
| 56 | +### Treemap Rules |
| 57 | + |
| 58 | +- All blocks must be large enough to show a label (minimum 8×3 characters) |
| 59 | +- The "N more items" block must always be visible when items are grouped |
| 60 | +- Show as many items as possible while maintaining readability |
| 61 | + |
| 62 | +## Development |
| 63 | + |
| 64 | +### Building |
| 65 | + |
| 66 | +```bash |
| 67 | +go build . |
| 68 | +go test ./... |
| 69 | +``` |
| 70 | + |
| 71 | +### Running |
| 72 | + |
| 73 | +```bash |
| 74 | +# Scan current directory |
| 75 | +go run . ./ |
| 76 | + |
| 77 | +# Scan specific path |
| 78 | +go run . /path/to/scan |
| 79 | + |
| 80 | +# With debug logging |
| 81 | +DEBUG=1 go run . ./ |
| 82 | +``` |
| 83 | + |
| 84 | +### Testing Changes |
| 85 | + |
| 86 | +After making changes, verify: |
| 87 | +1. `go build .` succeeds |
| 88 | +2. `go test ./...` passes |
| 89 | +3. Manual testing with both small directories and full drives |
0 commit comments