Skip to content

Intermediate Project: CLI Task Manager

Beginning of the lesson

Intermediate Project: CLI Task Manager

The capstone: assemble comprehensions, classes, files, exceptions and tests into one real command-line app

Big Idea: Everything you learned in this course was a single tool. A real program is many tools working together. Here we build a task manager you can run from the terminal: it stores your to-dos in a file, lets you add and complete them, filters them with comprehensions, models each item as a class, survives bad input with exceptions, and is protected by automated tests.
By the end you will be able to:
  • split an app into layers (data, logic, storage, interface) that each do one job,
  • model a to-do item as a Task class with to_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 Task class: what a single to-do is.
  • Logic - the TaskManager class: 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 from argv, call the logic, print results.
CLI reads argv TaskManager the logic Storage save / load tasks.json on disk call list save load
The command line calls the logic, the logic asks storage to save or load, and tasks.json holds the data between runs.

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.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers