Preheat oven to 375°F (190°C). Grease a 9x13-inch baking dish.
Cook spaghetti al dente according to package instructions. Drain and set aside.
Brown the beef: In a skillet, heat olive oil over medium heat. Add onions and garlic; sauté until soft. Add ground beef, breaking it apart until no longer pink. Drain excess fat.
Season & sauce: Stir in marinara, oregano, basil, red pepper flakes, salt, pepper, and water/broth. Simmer for 5 minutes.
Combine: Toss cooked spaghetti with the meat sauce and ½ cup Parmesan cheese. Transfer to the baking dish.
Top with cheese: Sprinkle mozzarella and remaining Parmesan evenly over the spaghetti.
Bake uncovered for 20–25 minutes until bubbly and golden.
Rest for 5 minutes before serving. Garnish with fresh basil if desired.