Mental Model: Todo List TUI in Python

This todo app teaches one of the most important backend habits: state has a lifecycle.

Lifecycle Mental Model

For task data, repeat this cycle:

  1. load from disk
  2. mutate in memory
  3. save after successful changes

That load-mutate-save loop is your reliability backbone.

Data Model That Scales

A small Task dataclass gives you stable structure.

  • id is identity
  • text is content
  • done is status

Then keep list[Task] as the in-memory store. Simple, explicit, and easy to inspect.

IDs vs Positions

Important beginner idea: IDs are not list positions.

  • list positions can change after deletes
  • IDs should stay stable across sessions

Your next_id helper encodes that rule.

Python-Specific Insight

Python makes persistence straightforward with built-ins.

  • json for storage
  • asdict for serialization
  • list comprehensions for filtering and deletes

This is real-world utility code without heavy frameworks.

Mutation Pattern

For every write command (add, done, edit, delete):

  1. validate input
  2. locate task
  3. mutate task list
  4. save
  5. print result

That repeatable pattern prevents accidental data loss.

Practice Extensions

Try adding:

  • priorities
  • due dates
  • sort and grouping views

Keep the same lifecycle model and your complexity stays under control.