Skip to content
Visual explainer 2h to learn 3 steps

Plan the project: features, data model & module layout

A short written spec with features, a dataclass model and the modules you will create.

By Invicly Tech, , in Python Programming from Zero. About 11 minutes to read.

Topic 33 of 34

In short

A short plan saves hours of rework. List the features you must have, sketch the data as dataclasses, and decide which module owns which job before writing any real code.

Explained simply

Before you build a house, you draw a plan. A program is the same. A one-page plan tells you what to build first, what can wait, and where each piece of code will live. It takes an hour or two and saves days of rewriting.

Start with features. Write the few things the program must do to be useful, and keep a separate list of nice ideas for later. A small list you finish is much better than a big list you abandon halfway.

Then describe your data. What does one expense, one weather reading or one task look like? Write it as a Python dataclass with a name and a type for every field. When the data is clear, most of the code becomes obvious.

Finally, split the work into modules, one file per job: one for the data model, one for saving and loading, one for the web API, one for the command line. Each file stays small, easy to read and easy to test.

Press Play on a diagram to walk through it one step at a time.

MapExample: expense tracker plan
expense-tracker
  • Must-have features
    • Add expense
    • List by month
    • Category totals
  • Nice-to-have
    • Currency conversion via API
    • CSV export
  • Data model
    • Expense dataclass
    • Category enum
  • Modules
    • models.py
    • storage.py
    • rates.py
    • cli.py
MapA planned project layout
expense-tracker/
  • pyproject.toml
    • Name, dependencies
    • [project.scripts] tracker
    • Ruff and pytest config
  • src/tracker/
    • models.py
    • storage.py
    • rates.py
    • service.py
    • cli.py
  • tests/
    • test_models.py
    • test_storage.py
    • test_service.py
    • test_cli.py
  • README.md
    • Install
    • Usage examples
    • Configuration
  • .gitignore
    • .venv/
    • __pycache__/
    • Local data files

In depth

Turning ideas into a feature list you can test

Write each must-have feature as a short user story and an example: "I can add an expense" becomes tracker add 12.50 --category food, which prints Added 12.50 (food). These examples are your acceptance criteria: when the real program prints that, the feature is done. They also become your first tests and the usage section of your README.

Sort ideas into must-have and nice-to-have honestly. A useful test is: "Is the tool still useful without this?" If yes, it waits. For a first capstone, three to five must-haves is plenty, for example add, list by month, totals by category, and one API feature such as currency conversion. Also write down what is out of scope (no web interface, no multiple users). Saying no early protects your time.

  • One line per feature: command, then expected output
  • Must-have: the tool is useless without it
  • Nice-to-have: parked in a list, not in the code
FlowFrom idea to a buildable spec
  1. 1
    Brain dump

    Every idea, no filtering

  2. 2
    Must vs nice

    Keep 3 to 5 must-haves

  3. 3
    Example commands

    Input and expected output

  4. 4
    Data model

    Dataclasses with typed fields

  5. 5
    Modules

    One job per file

Designing the dataclass model

Look at your example commands and ask what information each one needs. Every noun that you store (expense, category, rate) is a candidate type. Give every field a precise type: decimal.Decimal for money (floats cannot store 0.10 exactly), datetime.date for days, an Enum for a fixed set of choices like categories, and str for free text.

Give each stored record a stable id, for example uuid.uuid4().hex, so you can delete or edit it later. Put required fields first and fields with defaults last, because dataclasses require that order. Mutable defaults like a list need field(default_factory=list). Simple validation, such as rejecting a negative amount, fits in __post_init__. Decide now how the model becomes JSON: dates as ISO strings (2026-03-01), Decimals as strings, Enums by their value. Writing to_dict and from_dict by hand keeps this explicit.

  • @dataclass(frozen=True) for values that should never change
  • tags: list[str] = field(default_factory=list)
  • def __post_init__(self): raise ValueError on bad data

Module responsibilities and the direction of imports

A layout that works for most small CLI apps: models.py holds dataclasses and Enums and imports nothing from your project. storage.py reads and writes files and knows only about models. rates.py (or api.py) talks to the web API. service.py holds the real logic, like adding an expense or computing totals, using models, storage and rates. cli.py parses arguments, calls the service and prints results.

The key rule: imports point one way, from the top layer down. models never imports cli, and storage never imports service. This avoids circular imports (two modules importing each other, which fails at start-up) and means you can test lower layers without the ones above. Printing and sys.exit belong only in cli.py; lower layers return values or raise exceptions.

LayersWho may import whom (top imports below)
  1. 1
    cli.py

    argparse, printing, exit codes

  2. 2
    service.py

    Business rules: add, list, summarise

  3. 3
    storage.py and rates.py

    Files and the network

  4. 4
    models.py

    Dataclasses and Enums, no project imports

Choosing storage and configuration

For a personal CLI, a single JSON file is a good first choice: human readable, easy to back up and handled by the standard library. Add a top-level version field, like {"version": 1, "expenses": [...]}, so a future version of your program can recognise and upgrade old files. If you expect thousands of records or need queries, the built-in sqlite3 module is the next step up, with no server to install.

Decide where the file lives. Hard-coding a path in your project folder works only on your laptop. A better default is a file in the user's home directory, overridable with an option like --file or an environment variable such as TRACKER_FILE. Configuration that varies by user, like an API key, also comes from environment variables. Write these decisions into the spec so you do not invent them under pressure later.

Milestones that always leave a working program

Break the build into milestones, and make each one end in a program that runs and is committed to Git. A typical order: models with tests, then storage with a save and load test, then the add and list commands, then summaries, then the API call, then the README. If you run out of time, you still have a working, smaller tool instead of many half-finished parts.

Estimate each milestone in hours and note the risks. Common ones are an API that needs sign-up or has a low rate limit, date and currency edge cases, and scope creep (adding features nobody asked for). Many developers write the README usage section first, because explaining how the tool will be used often reveals missing or confusing features before any code exists.

  • Each milestone: code, tests pass, git commit
  • Check the API's sign-up, limits and response format on day one
  • Re-read the must-have list before starting anything new

Learn it in 3 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    List must-have and nice-to-have features~40m
  2. 2
    Sketch the dataclass model~40m
  3. 3
    Plan modules and their responsibilities~40m

Key points

  • Keep the must-have list small enough to finish in one week.
  • Each module should have one clear responsibility.
  • Sketch dataclass fields with types before writing logic.
  • Write one example command and its expected output per feature.

Key terms

Tap a card to flip it. 0/4 known

Examples

python
from dataclasses import dataclass
from datetime import date
from enum import Enum

class Category(Enum):
    FOOD = "food"
    TRAVEL = "travel"
    OTHER = "other"

@dataclass
class Expense:
    amount: float
    category: Category
    spent_on: date
    note: str = ""

A first sketch of models.py.

A one-page spec for an expense tracker

Step 1: one sentence says what the tool is for. Step 2: must-haves are written as commands with expected output. Step 3: nice-to-haves and out-of-scope items are listed so they do not creep in. Step 4: storage and configuration decisions are written down. This page is short enough to read in two minutes and precise enough to build from.

text
Goal: track personal expenses from the terminal.

Must-have
  tracker add 12.50 --category food   -> Added 12.50 (food)
  tracker list --month 2026-03        -> table of that month
  tracker summary --by category       -> total per category
  tracker convert --to USD            -> monthly total in USD (web API)
Nice-to-have: CSV export, budgets, recurring expenses
Out of scope: web UI, multiple users, cloud sync

Storage: ~/.tracker.json {"version": 1, "expenses": [...]}
Config: --file overrides path; RATES_API_KEY from environment
Modules: models, storage, rates, service, cli

The model sketch with validation and JSON conversion

Step 1: the Category Enum fixes the allowed values. Step 2: the dataclass uses Decimal and date, with the id generated by default_factory. Step 3: __post_init__ rejects negative amounts. Step 4: to_dict decides now how each type is stored in JSON, so storage.py stays simple.

python
import enum, uuid
from dataclasses import dataclass, field
from datetime import date
from decimal import Decimal
class Category(enum.Enum): FOOD = "food"; TRAVEL = "travel"; OTHER = "other"
@dataclass
class Expense:
    amount: Decimal
    category: Category
    spent_on: date
    id: str = field(default_factory=lambda: uuid.uuid4().hex)
    def __post_init__(self):
        if self.amount < 0: raise ValueError("amount must be positive")
    def to_dict(self):
        return {"id": self.id, "amount": str(self.amount), "category": self.category.value, "spent_on": self.spent_on.isoformat()}

Quick reference

  • Write each must-have as a command plus its expected output
  • Keep 3 to 5 must-haves; park everything else in a nice-to-have list
  • Use Decimal for money, date for days, Enum for fixed choices
  • Mutable defaults need field(default_factory=list)
  • Imports point down: cli, service, storage/rates, models
  • Only cli.py prints and exits; lower layers return or raise
  • Add a version field to your JSON file format from day one
  • Every milestone ends with passing tests and a git commit

Common mistakes

  • Starting with nice-to-haves before the core works.
  • Putting storage, logic and printing all in one file.
  • Skipping the plan and discovering the data model halfway through.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Why use decimal.Decimal instead of float for money?

Question 2

2Which module should be allowed to import cli.py?

Question 3

3What is the best way to give a dataclass field an empty list as default?

Question 4

4Why write example commands with expected output in the plan?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    For a weather logger, write three must-have features as example commands with expected output, and two nice-to-haves.

  2. Exercise 2medium

    Write a Reading dataclass for the weather logger with city, temperature in Celsius, humidity percent and a timestamp, rejecting humidity outside 0 to 100.

  3. Exercise 3hard

    List the modules for the weather logger with one-line responsibilities, and state which modules each may import.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

What is a good first Python capstone project?
A small command-line tool you would really use, such as an expense tracker, a weather logger, a reading list or a habit tracker. It should store data, call one web API and have a few commands.
How detailed should my plan be?
About one page: goal, must-haves with example commands, nice-to-haves, the data model, the module list and the storage choice. More detail than that usually changes once you start coding.
Should I use a dataclass or a plain dict for my data?
Use a dataclass. Field names and types are written down in one place, typos become errors instead of silent bugs, and editors can autocomplete fields.
JSON file or SQLite for storage?
Start with JSON for a personal tool with hundreds or a few thousand records. Move to the built-in sqlite3 module when you need fast queries, many records or safe concurrent access.
ShareXLinkedInWhatsApp