Begin by preheating your oven to 350°F (175°C) to prepare for baking.
Cook the spaghetti in a large pot of boiling salted water according to the package instructions until it reaches al dente. Once done, drain it well and set aside for later use.
In a large skillet over medium heat, add the ground beef. Cook until nicely browned, breaking it apart with a wooden spoon as it cooks. When the beef is almost done, stir in the diced onion and minced garlic, and sauté until the onion turns translucent and aromatic.
Carefully stir in the tomato sauce and diced tomatoes, and then season the mixture with Italian seasoning, red pepper flakes (if using), salt, and black pepper. Allow this mixture to simmer for about 5 minutes so the flavors can meld together.
In a separate large mixing bowl, combine the ricotta cheese, half of the shredded mozzarella cheese, and half of the grated Parmesan cheese. Mix until everything is thoroughly combined and creamy.
Lightly grease a 9x13 inch baking dish with cooking spray or olive oil. Start layering your ingredients in the dish: begin with half of the cooked spaghetti, then add half of the meat sauce, followed by half of the ricotta mixture. Repeat this layering process with the remaining spaghetti, meat sauce, and ricotta mixture.
Finish by evenly sprinkling the top with the reserved mozzarella and Parmesan cheeses, ensuring a cheesy crust when baked.
Cover the baking dish tightly with aluminum foil and bake in the preheated oven for 25 minutes. After this time, remove the foil and continue baking for an additional 15 minutes, or until the cheese on top is golden and bubbly.
Once done, allow the dish to cool for about 10 minutes before slicing and serving. Garnish each portion with fresh basil leaves for a touch of color and flavor.
Notes
Pair this rich baked spaghetti with a simple side salad and garlic bread for a complete and satisfying meal.