Intermediate Project: CLI Task Manager
The capstone: assemble comprehensions, classes, files, exceptions and tests into one real command-line app
class, survives bad input with exceptions, and is protected by automated tests.
- split an app into layers (data, logic, storage, interface) that each do one job,
- model a to-do item as a
Taskclass withto_dict/from_dict, - query and filter with list, generator and dict comprehensions,
- persist data to a JSON file and recover from a missing or corrupt one with exceptions,
- drive it all from the command line and lock in behaviour with unit tests.
1. Architecture: four layers, one app
A common beginner mistake is to cram an entire program into one long script. Professionals instead split it into layers, where each layer has a single responsibility and talks only to its neighbours. Our task manager has four:
- Data - the
Taskclass: what a single to-do is. - Logic - the
TaskManagerclass: add, complete, filter, count. It knows nothing about files or the screen. - Storage -
save/load: turn tasks into JSON on disk and back. It knows nothing about the command line. - Interface - the CLI (
main): read the user's command fromargv, call the logic, print results.
Why bother? Because each layer can be understood, changed and tested on its own. You could swap the JSON file for a database, or the CLI for a web page, without touching the logic. This separation is the single most important idea in the whole project.