Section Project: Task Management CLI

Problem Statement

Task management is a fundamental need in software development and daily productivity. While many GUI applications exist, command-line tools offer speed, scriptability, and integration with development workflows. This project challenges you to build a production-ready CLI task manager that demonstrates all the Go fundamentals learned in this section.

Why Build This?

  • Real-world application: Every developer needs task management
  • Comprehensive practice: Combines structs, methods, error handling, file I/O, and testing
  • Portfolio piece: Demonstrates practical Go skills to potential employers
  • Daily utility: You'll actually use what you build

Learning Objectives:

  • Design clean package architecture
  • Implement persistent storage with SQLite
  • Build user-friendly CLI with colored output
  • Write comprehensive unit tests
  • Use Go modules for dependency management
  • Apply error handling best practices
  • Create distributable binaries

Requirements

Functional Requirements

Core Features:

  1. Task Creation

    • Add tasks with title and optional description
    • Set priority levels
    • Auto-assign creation timestamps
    • Generate unique task IDs
  2. Task Management

    • List all tasks with filtering options
    • Mark tasks as complete
    • Delete tasks
    • Update task details
    • Filter by status
    • Filter by priority
  3. Data Persistence

    • Store tasks in SQLite database
    • Survive application restarts
    • Handle concurrent access safely
    • Support database migrations
  4. User Interface

    • Colorful, readable output
    • Clear success/error messages
    • Intuitive command structure
    • Help documentation

Non-Functional Requirements

Quality Standards:

  • Code Quality: Pass go vet and gofmt
  • Test Coverage: Minimum 70% coverage
  • Error Handling: All errors properly handled and reported
  • Performance: Sub-second response for all commands
  • Portability: Works on Linux, macOS, Windows

Usability:

  • Simple command syntax: taskmaster add "Buy groceries"
  • Colored output for better readability
  • Clear error messages with suggestions
  • Help text for all commands

Maintainability:

  • Clean separation of concerns
  • Documented public APIs
  • Consistent code style
  • Minimal external dependencies

Constraints

Technical Constraints:

  • Use Go standard library where possible
  • SQLite for storage
  • Single binary deployment
  • No GUI or web interface
  • Must compile with Go 1.21+

Scope Limitations:

  • Single-user application
  • Local storage only
  • English language only
  • No task dependencies or subtasks

Design Considerations

Architecture Overview:

The application follows clean architecture principles with clear separation between layers:

  • CLI Layer: Entry point, argument parsing, user interaction
  • Command Handlers: Command logic, output formatting
  • Domain Models: Task struct, validation, business logic
  • Storage Layer: Data persistence abstraction and SQLite implementation

Key Design Decisions:

  1. Storage Interface: Abstract the persistence layer to allow future implementations
  2. Package Structure: Use internal/ to prevent external packages from importing implementation details
  3. Error Handling: Wrap errors with context using fmt.Errorf with %w verb
  4. CLI Design: Use standard library flag package for simplicity
  5. Testing Strategy: Unit tests for storage layer, integration tests for CLI commands

Technology Choices:

  • SQLite: Embedded database requiring no separate server
  • fatih/color: Popular library for colored terminal output
  • Standard library: Minimize external dependencies for maintainability
  • Makefile: Cross-platform build automation

Acceptance Criteria

Your implementation is complete when it satisfies all of the following criteria:

Core Functionality:

  • Add tasks with title, description, and priority
  • List all tasks with formatted output
  • Mark tasks as complete with timestamp
  • Delete tasks by ID
  • Filter tasks by status
  • Filter tasks by priority level

Data Persistence:

  • Tasks persist across application restarts
  • Database schema created automatically on first run
  • No data corruption on unexpected shutdown
  • Proper handling of NULL values

Code Quality:

  • All code passes go fmt and go vet
  • Test coverage at or above 70%
  • No hard-coded file paths
  • All public functions have documentation comments
  • Error messages are clear and actionable

User Experience:

  • Colored output distinguishes status and priority
  • Help command shows all available commands
  • Error messages suggest corrective actions
  • Command syntax is intuitive and consistent
  • Time displays are human-readable

Build & Distribution:

  • Single make build command produces working binary
  • make test runs all tests successfully
  • Binary works on Linux, macOS, and Windows
  • README provides clear installation and usage instructions
  • No external dependencies required at runtime

Bonus Criteria:

  • Dockerfile for containerized deployment
  • Shell completion scripts
  • Configuration file support
  • Export tasks to JSON/CSV
  • Benchmarks for critical operations

Usage Examples

Once built, TaskMaster provides an intuitive CLI interface:

Adding Tasks:

 1# Add a simple task
 2$ taskmaster add "Buy groceries"
 3✓ Task added successfully!
 4  ID: 1
 5  Title: Buy groceries
 6  Priority: Medium
 7
 8# Add a task with priority and description
 9$ taskmaster add "Deploy production" -priority critical -desc "v2.0 release"
10✓ Task added successfully!
11  ID: 2
12  Title: Deploy production
13  Priority: Critical
14
15# Add a low-priority task
16$ taskmaster add "Update documentation" -priority low
17✓ Task added successfully!
18  ID: 3
19  Title: Update documentation
20  Priority: Low

Listing Tasks:

 1# List all tasks
 2$ taskmaster list
 3ID  STATUS  PRIORITY   TITLE                  CREATED
 4──  ──────  ────────   ─────                  ───────
 52   [ ]     Critical   Deploy production      just now
 61   [ ]     Medium     Buy groceries          2 min ago
 73   [ ]     Low        Update documentation   5 min ago
 8
 9Total: 3 tasks
10
11# List only pending tasks
12$ taskmaster list -status pending
13ID  STATUS  PRIORITY   TITLE                  CREATED
14──  ──────  ────────   ─────                  ───────
152   [ ]     Critical   Deploy production      2 hours ago
161   [ ]     Medium     Buy groceries          3 hours ago
17
18Total: 2 tasks
19
20# Filter by priority
21$ taskmaster list -priority critical
22ID  STATUS  PRIORITY   TITLE                CREATED
23──  ──────  ────────   ─────                ───────
242   [ ]     Critical   Deploy production    2 hours ago
25
26Total: 1 tasks

Completing Tasks:

 1$ taskmaster complete 1
 2✓ Task #1 marked as complete!
 3
 4$ taskmaster list
 5ID  STATUS  PRIORITY   TITLE                  CREATED
 6──  ──────  ────────   ─────                  ───────
 72   [ ]     Critical   Deploy production      3 hours ago
 81   []     Medium     Buy groceries          4 hours ago
 93   [ ]     Low        Update documentation   5 hours ago
10
11Total: 3 tasks

Deleting Tasks:

 1$ taskmaster delete 3
 2✗ Task deleted: Update documentation
 3
 4$ taskmaster list
 5ID  STATUS  PRIORITY   TITLE                CREATED
 6──  ──────  ────────   ─────                ───────
 72   [ ]     Critical   Deploy production    3 hours ago
 81   []     Medium     Buy groceries        4 hours ago
 9
10Total: 2 tasks

Getting Help:

 1$ taskmaster help
 2TaskMaster - A simple CLI task manager
 3
 4Usage:
 5  taskmaster <command> [flags] [arguments]
 6
 7Commands:
 8  add        Add a new task
 9  list       List all tasks
10  complete   Mark a task as complete
11  delete     Delete a task
12  version    Show version information
13  help       Show this help message
14
15Examples:
16  taskmaster add "Buy groceries" -priority high
17  taskmaster add "Write report" -desc "Q4 summary" -priority medium
18  taskmaster list
19  taskmaster list -status pending
20  taskmaster list -priority high
21  taskmaster complete 1
22  taskmaster delete 2

Key Takeaways

Go Fundamentals Applied:

  1. Structs and Methods: Task struct with validation and business logic methods
  2. Interfaces: Storage interface for abstraction and testability
  3. Error Handling: Proper error wrapping with fmt.Errorf and %w
  4. Packages: Clean separation with cmd/ and internal/
  5. Testing: Comprehensive unit tests with table-driven approach
  6. File I/O: SQLite database interaction with proper resource cleanup
  7. CLI Parsing: Flag package for command-line argument handling
  8. Code Organization: Logical structure following Go best practices

Production Skills:

  • Database integration
  • Dependency management with Go modules
  • Build automation with Makefiles
  • Containerization with Docker
  • Test-driven development practices
  • User-friendly error messages
  • Cross-platform compatibility

Design Patterns:

  • Repository Pattern: Storage interface abstracts persistence
  • Clean Architecture: Layers don't depend on implementation details
  • Dependency Injection: Pass storage to CLI handlers
  • Factory Pattern: NewSQLiteStorage constructor
  • Command Pattern: Each CLI command is a separate handler

Next Steps

Enhancements to Try:

  1. Advanced Features:

    • Task tags and categories
    • Due dates with reminders
    • Recurring tasks
    • Task dependencies
    • Export to JSON/CSV
  2. Technical Improvements:

    • Add database migrations system
    • Implement in-memory storage for testing
    • Add concurrent access safety
    • Create benchmarks for storage operations
    • Add fuzzing tests
  3. User Experience:

    • Interactive mode with prompts
    • Search functionality
    • Task sorting options
    • Configuration file support
    • Shell completion scripts
  4. Distribution:

    • Create installer scripts
    • Publish to package managers
    • Generate man pages
    • Create web UI version
    • Build mobile companion app

Related Topics to Explore:

  • Section 2: Standard Library
  • Section 3: Advanced Topics
  • Section 4: Production Engineering
  • Section 5: Practice Exercises

Further Learning:

Congratulations on building your first production-ready Go application! This project demonstrates mastery of Go fundamentals and readiness for more advanced topics.

Continue your journey with Section 2: Standard Library to deepen your understanding of Go's powerful built-in packages.

Download Complete Solution

📦 Download Complete Solution

Get the complete working CLI application with all features implemented:

⬇️ Download Solution

Contains: Complete source code • SQLite integration • Comprehensive tests • Makefile • Docker support • Full README with implementation guide

What's Included:

  • ✅ Complete working application
  • ✅ SQLite database integration
  • ✅ Colored CLI output with fatih/color
  • ✅ Comprehensive unit tests
  • ✅ Makefile for build automation
  • ✅ Dockerfile for containerization
  • README with complete implementation guide
  • ✅ All CRUD operations implemented
  • ✅ Priority and status filtering
  • ✅ Error handling and validation

Quick Start:

 1# Extract the archive
 2unzip task-cli-solution.zip
 3cd taskmaster
 4
 5# Read the implementation guide
 6cat README.md
 7
 8# Install dependencies
 9make deps
10
11# Run tests
12make test
13
14# Build the application
15make build
16
17# Start using it!
18./bin/taskmaster add "My first task" -priority high
19./bin/taskmaster list

Note: The downloaded README.md contains the complete implementation guide with:

  • Detailed architecture explanation
  • Full source code for all components
  • Step-by-step implementation phases
  • Testing strategies and examples
  • Build and deployment instructions
  • Troubleshooting tips