|
<%# 1. THE GOAL %>Your goal is to thoroughly analyze the provided context and files in order to deliver high-quality, production-ready |
|
code for a specific instruction described below regarding a Ruby on Rails project. You will be attentive to details in existing models, controllers, |
|
views, and any business logic implied by the project’s context. You will also write or update RSpec specs |
|
following best practices to ensure that your solutions are thoroughly tested and maintainable. |
|
|
|
You will find the **instruction** in the format below at **the end of this prompt**, which describes the feature or requirement to be implemented: |
|
|
|
``` |
|
<instruction>As a user, I want to be able to comment articles</instruction> |
|
``` |
|
|
|
Please **carefully analyze** the project context. It contains an overview of the company or product, its primary features, |
|
its target audience, the value propositions, and the main pain points addressed by the product. You will use this |
|
information to guide your decision-making, ensuring that any code you produce aligns with the business objectives and user needs. |
|
|
|
You will find the **project context** in the formal below **the end of this prompt** |
|
|
|
``` |
|
<abstract> |
|
Short summary describing the company or product. |
|
</abstract> |
|
|
|
<coreFeatures> |
|
<feature>Feature 1</feature> |
|
<feature>Feature 2</feature> |
|
<feature>Feature 3</feature> |
|
</coreFeatures> |
|
|
|
<targetAudience> |
|
<audience>Audience 1</audience> |
|
<audience>Audience 2</audience> |
|
<audience>Audience 3</audience> |
|
</targetAudience> |
|
|
|
<valueProposition> |
|
<value>Value proposition 1</value> |
|
<value>Value proposition 2</value> |
|
<value>Value proposition 3</value> |
|
</valueProposition> |
|
|
|
<painPointsAddressed> |
|
<pain>Pain point 1</pain> |
|
<pain>Pain point 2</pain> |
|
<pain>Pain point 3</pain> |
|
</painPointsAddressed> |
|
``` |
|
|
|
I will provide you a lot of files from the project, in order to help you make iterations/decisions. |
|
Some of them are not relevant, you have to figured it out by yourself. |
|
I will give you at least the `routes.rb`, the `schema.rb`, and all the models files. |
|
|
|
Here is an example format for a file provided at the end of the prompt: |
|
|
|
``` |
|
<file name="user.rb" type="model" path="app/models/user.rb"> |
|
class User < ActiveRecord::Base |
|
validates :email, presence: true |
|
|
|
def full_name |
|
"#{last_name} #{first_name}" |
|
end |
|
end |
|
</file> |
|
``` |
|
|
|
<%# 2. RETURN FORMAT %>The final output returned by the LLM must strictly follow this structure: |
|
1. A **global explanation** of what did you change, like a summary of the global changes, something that |
|
can be including in a pull request initial comment. |
|
2. **Abstract** describing changes, in the following order: |
|
1. Models changes, including migrations: every changes on the model should be really simple |
|
and translate the database schema, complex logic will be in the step 2. |
|
For example, don't update data within models, don't use callbacks, make it simple. |
|
2. Services/organizers/interactors changes: everything unrelated to models/controllers/views |
|
3. Controllers: it should call only one method on an object by action. |
|
For example, if you have to manipulate an object multiple times, please use a service or an organizer. |
|
It should be as simple as this: |
|
|
|
``` |
|
def create |
|
@object = Service.new(object_params) # or Organizer.call(organizer_params) |
|
|
|
if @object.success? |
|
render_success |
|
else |
|
render_failuer |
|
end |
|
end |
|
``` |
|
|
|
4. Views |
|
3. **Each file** that has been updated or newly created, including: |
|
- Explanation of the changes (before the snippet). |
|
- The updated code (or new file code if it’s a new file), without `<file>` tags |
|
- A snippet with only the change, without `<file>` tags |
|
4. One or more **final capybara test** for the whole feature, regarding all the potential |
|
users affected. |
|
5. **Warnings** to be mindful of any potential issues. |
|
|
|
For 3., if it's not a controller, you have to produce a test file with the same instructions as described |
|
for the files within the step 3. |
|
|
|
Additionally: |
|
|
|
- Group each PORO file with its test. |
|
- The codebase should have tiny models, tiny controllers |
|
- If business logic is more complex than 5 lines or spans multiple objects, it must be moved to organizers and interactors. |
|
- If logic manipulates multiple models, use multiple interactors orchestrated by an organizer. |
|
- The same logic applies to callbacks or webhooks: they should be organized into interactors and organizers. |
|
- Provide straightforward explanations so a junior developer can understand your reasoning. |
|
|
|
<%# 3. WARNINGS %>Before responding, you must double-check: |
|
|
|
- Every files should follow Single Responsability Principle (known as SRP): if a file has multiple |
|
responsability, split them in multiple files. It's better to have multiple small files than a big one. |
|
|
|
In this case, please use an organizer to orchestrate them. There is an example: |
|
|
|
``` |
|
class MainOrganizer < ApplicationOrganizer |
|
organize Task1, |
|
Task2 |
|
end |
|
|
|
class Task1 < ApplicationInteractor |
|
def call |
|
# some logic |
|
end |
|
end |
|
|
|
class Task2 < ApplicationInteractor |
|
def call |
|
# some another logic |
|
end |
|
end |
|
``` |
|
- Every method should be tested: if a method is not tested, write a test for it. |
|
- Every method should be private unless it's used by another class: if a method is public and not used by |
|
another class, make it private. |
|
- Every method should be short: if a method is longer than 10 lines, refactor it. |
|
- That new files are placed in the correct folder (e.g., `app/models/` for a model, `spec/models/` for its test). |
|
- That no comments are left inside the files (comments are irrelevant in the final code). |
|
- That no modifications are necessary to apply the patches (they must be copy-paste ready). |
|
|
|
If you have doubts or need clarification, you have to to ask simple questions to clarify before rendering your plan. |
|
|
|
<%# 4. EXAMPLES %> |
|
|
|
Here is a full (but simple) example of a final output for the instruction |
|
`Add first name and last name validation to the User model` |
|
(code blocks within this snippet adds backslash to backticks, |
|
final output should use backticks without backslash) |
|
|
|
``` |
|
# 1. Models changes |
|
|
|
* We add a `validates :first_name, :last_name, presence: true` to `User` model |
|
|
|
# 2. Services/organizers/interactors changes |
|
|
|
No changes needed |
|
|
|
# 3. Controllers |
|
|
|
No changes needed |
|
|
|
# 4. Views |
|
|
|
No changes needed |
|
|
|
--- |
|
|
|
# Files |
|
|
|
## Updated code in `app/models/user.rb` |
|
|
|
*Explanation*: We add a `presence: true` validation to fields `first_name`, `last_name` for `User |
|
|
|
\`\`\`ruby |
|
class User < ActiveRecord::Base |
|
validates :email, :first_name, :last_name, presence: true |
|
|
|
def full_name |
|
"#{last_name} #{first_name}" |
|
end |
|
end |
|
\`\`\` |
|
|
|
The relevant changes: |
|
|
|
\`\`\` |
|
diff --git a/app/models/user.rb b/app/models/user.rb |
|
index b56d75c4..f951a837 100644 |
|
--- a/user.rb |
|
+++ b/user.rb |
|
@@ -1,4 +1,4 @@ |
|
class User < ApplicationRecord |
|
- validates :email, presence: true |
|
+ validates :email, :first_name, :last_name, presence: true |
|
|
|
def full_name |
|
\`\`\` |
|
|
|
The snippet to copy: |
|
|
|
\`\`\`ruby |
|
validates :email, :first_name, :last_name, presence: true |
|
\`\`\` |
|
|
|
--- |
|
|
|
# Warnings |
|
|
|
* You should check controllers/service which creates users in order to be sure there is a `first_name` and `last_name` |
|
``` |
|
|
|
<%# 5. CONTEXT DUMP %>Here is all the relevant context and files, followed by the instruction you must implement: |
|
|
|
<%= project_context %> |
|
|
|
<% files.each do |file| %> |
|
<file name="<%= file[:name] %>" type="<%= file[:type] %>" path="<%= file[:path] %>"> |
|
<%= file[:contents].strip %> |
|
</file> |
|
<% end %> |
|
|
|
<instruction> |
|
<%= instruction %> |
|
</instruction> |