In our previous lessons, we learned how to create a high-level technical plan. This plan acts as our map. Now, we are ready to move from planning to building. Our goal is to add a comments feature to our task management app. This feature allows users to add comments to tasks, see a list of comments, and delete their own comments.
If we ask an AI like Codex to "Build the whole comment system," it might get overwhelmed and make mistakes. Instead, we take our technical plan and break it into small, executable steps. This ensures that the code is high-quality and easy to test.
In the CodeSignal IDE, you will find that the libraries we use, like SQLAlchemy for databases and Pytest for testing, are already installed. You can focus entirely on the logic of building your feature.
To build a feature successfully, we group our work into logical phases. We call these atomic tasks. A task is atomic if it focuses on one thing, affects only a few files, and can be finished in one sitting — usually in under 2 hours.
For our comments feature, we split the work like this:
| Phase | Task ID | Focus | Dependencies |
|---|---|---|---|
| Foundation | T001, T002 | database model and repository | None |
| Business Logic | T003, T004 | services and validation schemas | T001, T002 |
| API Layer | T005, T006 | endpoints and authorization | T003, T004 |
| Integration | T007 | Final end-to-end tests | All previous |
By following this order, we ensure that we never build a "roof" (the API) before we have a "foundation" (the database).
Every task needs a clear set of instructions so that Codex knows exactly what "done" looks like. We use a standard template for this. Let's look at the requirements for our first task, T001.
Task Template: [T001] Create Comment Model
- Files Modified:
src/models/comment.py,tests/unit/test_comment_model.py. - acceptance criteria:
- Model defined as a SQLAlchemy declarative model with proper Python type hints.
- Fields:
id(Integer, primary key),task_id(Integer, Foreign Key),author_id(Integer, Foreign Key),content(String),created_at(DateTime). - Relationships:
task(toTaskmodel),author(toUsermodel). - All foreign key columns explicitly marked as
nullable=False. - unit tests verify field types, relationships, and timestamp handling.
- Dependencies: None.
- Estimated Time:
45minutes.
Notice the checkboxes. These are called acceptance criteria. They act as a checklist for both you and Codex. If every box is not checked, the task is not finished.
When you start a task with Codex, you should use a test-first workflow. This means we ask Codex to write the test before the actual code. This ensures that the code actually does what we want.
Let's walk through how you would prompt Codex for T001.
Step 1: The Initial Prompt
You tell Codex: "Create the Comment model following the T001 acceptance criteria. Write the tests first, verify they fail, then implement the model, and verify they pass."
Step 2: Writing the Failing Test
Codex will first create a test file. Since the Comment model does not exist yet, the test will fail.
When Codex runs this test, the output will look like this:
Step 3: Implementing the Model Now Codex writes the actual code to make the test pass, following the exact patterns used in this project.
Key Pattern Details:
- We use
Integeras the primary key type, consistent with theUserandTaskmodels already in this project. - We use
DateTimefor timestamp columns withdefault=lambda: datetime.now(timezone.utc)to set the creation time automatically. - All foreign key columns are explicitly marked with
nullable=False, ensuring data integrity at the database level. - We use
Stringforcontentto store the comment text. - The column is named
author_id(notuser_id) to be semantically clear that this field refers to the comment's author. - Relationships use
back_populatesfor bidirectional references —taskpoints back to theTaskmodel'scommentsrelationship, which you can see defined insrc/models/task.py. - We follow
snake_casenaming conventions for both the table name and all column names.
Step 4: Verifying Success Codex runs the test again. This time, it passes!
Finally, you would commit this work with a clear message: feat(comments): Add Comment model (T001).
Sometimes, we accidentally make a task too big. This is called task bloat. Imagine trying to combine "Create validation schemas" and "Create API endpoints" into one single task.
The Failure Mode:
If a task touches 4 or 5 files and has 12 different acceptance criteria, Codex might lose focus. It might generate incomplete tests or forget to add validation. You will notice this if the test coverage is low or if Codex starts hallucinating (writing code that does not exist).
The Recovery: If you see Codex getting confused, stop! This is a signal to split the task.
- Stop the current execution.
- Split the bloated task into two smaller tasks:
T004:Commentvalidation schemas with Pydantic (2files,45mins).T005: API endpoints with FastAPI (2files,60mins).
- Execute them one by one.
By splitting the work, Codex can focus 100% on the validation schemas first and then 100% on the API endpoints. This leads to significantly better results.
In this lesson, we moved from high-level planning to understanding the execution methodology. Here are the key takeaways:
- Decompose First: Break features into atomic tasks (
T001,T002...) before writing any code. - Use Templates: Define clear files, acceptance criteria, and dependencies for every task.
- Follow Patterns: Always match existing codebase conventions (
Integerprimary keys, SQLAlchemy model decorators, timezone-aware timestamps usingdefault=lambda: datetime.now(timezone.utc), explicitnullable=Falseon required fields). - Test-First Workflow: Always ask Codex to write a failing test before the implementation.
- Stay Atomic: If a task is too large, Codex will lose focus. Split it into smaller chunks to maintain quality.
In the upcoming practice exercises, you will enter the CodeSignal IDE and use Codex to execute these exact tasks. You will apply this methodology hands-on, writing tests, implementing features, and seeing them come to life in the actual TaskMaster codebase!
