Cook the Spaghetti:
Bring a large pot of salted water to a boil. Add the spaghetti and cook according to package instructions until al dente (usually about 8-10 minutes). Stir occasionally to prevent sticking.
Prepare the Sauce:
While the pasta cooks, heat the olive oil in a frying pan over medium heat. Add the chopped onion and sauté until translucent (about 3-4 minutes). Then, add the minced garlic and sauté for an additional minute until fragrant.
Add the Tomatoes:
If using fresh tomatoes, chop them into small pieces. Add them to the frying pan, season with salt and pepper, and let simmer for about 10 minutes until the tomatoes soften and break down. If using canned tomatoes, crush them with your hands and add them to the pan. Let them cook down as well.
Mix in Basil:
Tear half of the basil leaves and stir them into the sauce. Let it simmer for another minute or two. Taste and adjust seasoning as necessary.
Combine Pasta and Sauce:
Once the spaghetti is cooked, reserve about 1 cup of the pasta water, then drain the spaghetti. Add the pasta to the sauce and toss well to combine. If the sauce is too thick, add a little reserved pasta water until you reach the desired consistency.
Serve:
Plate the spaghetti and garnish with fresh basil leaves and a drizzle of olive oil. Top with grated Parmesan cheese if desired.