In our previous lessons, we focused on building individual features like task comments. Those tasks were mostly local to our application — they involved a single database table and a few simple API rules. However, professional software often requires Multi-Component Features. These are features where the application must coordinate with external systems, such as cloud storage or third-party security tools.
The Task Attachments feature is a perfect example. To allow users to upload files to a task, we cannot simply save the file in a database. We need to:
- Store the actual file in a
cloud storage bucket(likeAmazon S3). - Save the
metadata(the file's name, size, and type) in ourdatabase. - Check the file for
virusesandsize limitsbefore saving it. - Provide a secure way for users to download it later.
Because there are so many moving parts, we use Phased Decomposition. Instead of trying to build everything at once, we group tasks into logical phases. This keeps the AI focused and ensures that the foundation of the system is solid before we build the complex API layers on top.
When building multi-component systems, the API acts like a traffic controller. It doesn't do all the work itself; instead, it tells other components what to do. For Task Attachments, we need a Storage Strategy. We don't want to just dump every file into one big folder. We organize them so they are easy to find and manage.
| Component | Responsibility | Example |
|---|---|---|
Database | Stores information about the file. | File name: contract.pdf, Size: 2MB |
S3 Storage | Stores the actual file data. | A file located at /attachments/task-123/contract.pdf |
Validators | Checks if the file is safe and allowed. | Is this file larger than 5MB? |
One new concept we use here is a Presigned URL. Since we want our files to be private and secure, we don't give users a permanent link to the file. Instead, when a user asks to see an attachment, our system generates a special link that expires after 1 hour. This ensures that only authorized users can see the files.
Before writing any code, we must ask Codex to generate a Technical Plan. This plan maps out exactly how the 13 tasks will be distributed across 5 phases. We provide Codex with our specification.md and ask it to follow the patterns in our CODEX.md file.
You would prompt Codex like this:
"Given the approved specification for task attachments, generate a technical plan for TaskMaster. Reference CODEX.md for our coding patterns and existing database conventions."
Codex will then produce a plan divided into these phases:
- Phase 1: Foundation. Creating the
Attachmentdatabase model. - Phase 2: Storage Infrastructure. Building the
S3Clientto talk to the cloud. - Phase 3: Validation. Building services to check
file typesand scan forviruses. - Phase 4: API Integration. Creating the
endpointswhere the user actually uploads the file. - Phase 5: Testing. Running
end-to-end teststo make sure a file uploaded by a user actually reachesS3and thedatabasecorrectly.
The following diagram visualizes these phases and their dependencies:
Notice how Phase 2 and Phase 3 both depend only on Phase 1, meaning they can be developed in parallel. This is a key optimization opportunity in the workflow.
In a complex 13-task project, some tasks depend on others. This is called the Critical Path. For example, you cannot build the Upload API if the Attachment Database Model doesn't exist yet.
However, many tasks are independent. We call these Parallel Opportunities. Identifying these allows a team (or you, working with Codex) to finish work faster.
| Task ID | Component | Phase | Dependencies | Can run in parallel? |
|---|---|---|---|---|
T001 | Attachment Model | 1 | None | No (Start here) |
T003 | S3Client | 2 | None | Yes (With Phase 1) |
T005 | MIME Validator | 3 | None | Yes (With Phase 2) |
T008 | Attachment Service | 4 | T002, T003, T005 | No (Needs components) |
By recognizing that the S3 Client (T003) and the Validators (T005 — T007) don't depend on the database, we can potentially work on them at the same time, reducing the total calendar time of the project from 10.5 hours to roughly 6 hours.
Now we begin execution. We will build the system step-by-step. First, we need a way to represent the attachment in our code.
Step 1: The Database Model
We define what information we want to save about a file using a proper SQLAlchemy declarative model, consistent with the rest of the codebase.
This tells our application that every attachment needs a name, a size, and an s3_key (the unique address for the file in storage).
Step 2: The Attachment Repository
Following the repository pattern from CODEX.md, all database access goes through a repository class. The create() method persists an Attachment using the standard SQLAlchemy session flow.
Step 3: The S3 Client (Mocked)
Next, we need a component that handles the actual upload. On CodeSignal and in development, we often mock (simulate) the S3 service so we don't need a real internet connection to test our code.
Note: In production code, replace
print()statements with proper logging (e.g.,logger.info(f"Uploading file to: {s3_key}")) to enable appropriate log levels, filtering, and integration with monitoring systems.
The upload_file method handles the heavy lifting, while generate_presigned_url creates that secure, temporary link we discussed earlier.
Step 4: The Attachment Service (Integration)
Now we create a service that brings the database repository and cloud storage together. Notice how db_repo.create() matches exactly the method we defined in Step 2.
By passing db_repo and s3_client into the service we allow it to use both tools to complete the upload. This is the Dependency Injection pattern from CODEX.md.
In this lesson, you have learned how to:
- Analyze Multi-Component Requirements: Move beyond local database changes to coordinate with external systems.
- Implement Phased Decomposition: Group tasks into logical phases to maintain AI focus.
- Identify Parallel Opportunities: Recognize tasks that can be developed concurrently to optimize workflow.
- Execute Integration Patterns: Use Dependency Injection to connect databases with cloud storage services.
You are now ready to apply these concepts in the practice exercises. You will use the CodeSignal IDE and Codex to build the Task Attachment system yourself, starting from a technical plan and moving through the phases of execution.
