Project — CLI Task Manager
What you will build
A command named tasker that stores tasks in a JSON file.
tasker add "Learn slices"
tasker list
tasker complete 1
tasker remove 1
This first checkpoint defines behaviour before implementation.
What you will learn
- modules and packages;
- structs, defined types, slices, and methods;
- parsing input and returning errors;
- JSON and file ownership;
- dependency boundaries that make tests possible.
User stories
- As a learner, I can add a task with a non-empty title.
- I can list tasks in creation order.
- I can mark an existing task complete.
- I can remove a task.
- My tasks remain after the process exits.
- Invalid commands explain what I need to correct.
Command contract
tasker add <title>
tasker list [--all]
tasker complete <id>
tasker remove <id>
tasker help
Choose predictable exit behaviour:
0: command completed successfully;- non-zero: invalid input, missing task, or storage failure;
- ordinary output goes to stdout;
- diagnostics and usage errors go to stderr.
The exact non-zero code policy can become more detailed later. Start consistent.
Domain model
type TaskID int
type Task struct {
ID TaskID `json:"id"`
Title string `json:"title"`
Completed bool `json:"completed"`
CreatedAt time.Time `json:"created_at"`
}
Questions to answer before writing storage:
- Can an ID be zero or negative?
- Is an empty or whitespace-only title valid?
- Are IDs reused after deletion?
- Does
completesucceed when already complete? - How are corrupted files reported?
Suggested decisions:
- IDs start at 1 and are never reused within one data file.
- Titles are trimmed and must remain non-empty.
- Completing an already-complete task succeeds without changing state.
- Corrupt data returns an error; it is never silently replaced.
Package shape
tasker/
├── go.mod
├── cmd/tasker/main.go
└── internal/task/
├── task.go
├── service.go
├── store.go
└── file_store.go
Do not create extra packages until responsibility is clear.
Define the storage boundary
type Store interface {
Load(ctx context.Context) ([]Task, error)
Save(ctx context.Context, tasks []Task) error
}
For a small single-process project, replacing the whole file is understandable. A database would need a different, operation-oriented interface. Interfaces should match the consumer and use case rather than pretending every storage system is identical.
Acceptance checklist
- A new data file is created only after the first successful change.
- Whitespace-only titles are rejected.
- Unknown and malformed commands return useful errors.
- A corrupt JSON file is preserved and reported.
- Writes do not intentionally leave half-written JSON.
- Domain logic is tested without the real filesystem.
- File behaviour is tested inside
t.TempDir().
Practice
Write the command contract and domain rules in your own README. Then create the module and package directories without implementing the commands.
mkdir tasker
cd tasker
go mod init example.com/learner/tasker
package task
import "time"
type ID int
type Task struct {
ID ID `json:"id"`
Title string `json:"title"`
Completed bool `json:"completed"`
CreatedAt time.Time `json:"created_at"`
}
At this checkpoint the program does not run. That is intentional: requirements and type boundaries are established before command parsing and persistence are allowed to shape them accidentally.
Summary
- Begin a project with observable behaviour and failure decisions.
- Give domain identifiers a distinct type.
- Keep storage behind the behaviour the application needs.
- Preserve corrupted user data instead of overwriting it silently.
- Use acceptance criteria to decide when the project is complete.
Ready to wrap up?
Mark this complete when you can explain the main idea and finish the practice task.