Heat the olive oil in a large skillet over medium heat.
Add the minced garlic and finely diced onion and sauté for 3–5 minutes, until the onion is soft and fragrant.
Add the can of whole peeled tomatoes (break them up with your spoon), then season with salt, freshly ground black pepper, and crushed red pepper flakes if using.
Bring the sauce to a gentle simmer and cook for about 20 minutes, stirring occasionally, until flavors meld and sauce thickens slightly.
Meanwhile, bring a large pot of salted water to a boil and cook the spaghetti until al dente, about 8–10 minutes; reserve 1/2 cup pasta cooking water before draining.
Stir the chopped basil into the sauce. Add the drained spaghetti to the skillet and toss to combine, adding reserved pasta water a little at a time to loosen the sauce as needed.
Divide the spaghetti among plates, garnish with extra basil, and top with grated Parmesan if desired. Serve immediately.