You don't have access to this class
Keep learning! Join and start boosting your career
AI-assisted programming is revolutionizing the way we develop software. Cursor is positioned as one of the most powerful code editors on the market, combining the familiarity of Visual Studio Code with advanced artificial intelligence capabilities. In this article, we will explore how to use Cursor to create a complete project from scratch, taking full advantage of its code generation and development assistance features.
Cursor is a text editor based on Visual Studio Code that integrates artificial intelligence in all its functionalities. Unlike other editors, Cursor not only allows you to write code, but actively assists you in the development process through:
It is important to note that to get the most out of Cursor, you still need fundamental software engineering skills. The tool enhances your capabilities, but it does not replace the need to understand basic programming concepts.
To demonstrate Cursor's capabilities, let's create an API project with FastAPI and Python. The interesting thing is that most of the code will be generated by the AI built into the editor.
The first thing we need to do is open the Cursor chat with the keyboard shortcut Command + L
on Mac (or Control + L
on Windows). This allows us to interact with the AI through a conversational interface.
For this project, we will select the Claude 3.7 model, which has been shown to generate better code according to benchmarks. Then, we can start with a simple prompt:
I want to create a project with Python in which an API is created with FastAPI. Create the main skeleton of the application and generate the necessary commands to be able to create a Python project. Use UV to create the project.
The AI will provide us step by step with the necessary commands to:
A key advantage of Cursor is that we can directly execute the suggested commands from the interface, greatly simplifying the setup process.
One of the most powerful features of Cursor is its ability to process different types of input, including images. This is extremely useful when working with architectural diagrams or schematics.
Let's imagine we have a simple diagram of a "Dish" entity with three attributes: ID (integer), name (string) and price (float). We can export this diagram as an image and ask Cursor to generate the corresponding code:
Generate a Pydantic model that complies with what you have in the image.
The AI will recognize the structure of the diagram and generate the appropriate code:
from pydantic import BaseModelfrom typing import Optional
class Plato(BaseModel): id: int name: str price: float.
Then we can ask you to place this code in a specific file:
I need what you just generated to be inside a file named schemas.py.
And Cursor will take care of creating the file and placing the generated code in it.
A particularly useful feature of Cursor is its ability to index external documentation. This allows the AI to have a more complete context about the technologies we are using.
To index FastAPI documentation, we simply:
Once indexed, we can reference this documentation in our prompts:
In the main file, generate the endpoints needed to make a CRUD of the Plato schema. Use the information you know from FastAPI.
The AI will use the indexed documentation to generate high quality code following FastAPI best practices.
Cursor allows you to define rules for the AI to follow when generating code, which is extremely useful for maintaining consistency and following your team's standards.
We can create files with a .cursor-rules
extension that define the global rules for our project:
Every function should have a docstring that explains what the function is for.The documentation should be in English.
For more specific rules, we can create a .cursor/rules/
folder structure with MDX files defining rules for particular contexts:
// .cursor/rules/functions.mdxThis file is useful for when you have to generate docstrings on functions---extensions: [".py"]---Make the documentation in English, and for each function generate docstrings.
The Cursor community has also created a repository of predefined rules in cursor.directory, where we can find and generate rules for different technologies and scenarios.
Cursor also facilitates integration with Git, allowing us to generate commit messages based on the changes made. Simply put:
This streamlines the process of documenting changes and keeps a clear history of the changes made.
The combination of all these features makes Cursor an extremely powerful tool for modern software development, allowing us to focus on the business logic while the AI takes care of the more repetitive and mechanical tasks.
Have you tried Cursor or other AI-assisted programming tools? Share your experience and tell us how these technologies are transforming the way you program.
Contributions 17
Questions 0
Want to see more contributions, questions and answers from the community?