Bring a large pot of salted water to a boil, then cook the spaghetti until al dente according to package instructions. Drain and set aside.
Heat olive oil in a skillet over medium heat. Add chopped onion and minced garlic, sauté until translucent and fragrant, about 2-3 minutes.
Add ground beef to the skillet and cook, breaking it apart with a spatula, until browned and cooked through. Season with salt and pepper.
Pour in marinara sauce and stir to combine. Let the mixture simmer gently for 5 minutes to meld flavors.
Preheat your oven to 375°F (190°C). In a baking dish, layer half of the cooked spaghetti, then spread half of the meat sauce evenly over it.
Repeat with the remaining spaghetti and meat sauce, creating a layered effect.
Sprinkle a generous amount of shredded mozzarella and Parmesan cheeses evenly over the top layer.
Bake uncovered in the preheated oven for 20-25 minutes, until the cheese is melted, bubbly, and golden brown around the edges.
Remove from oven and let it sit for 5 minutes to set before serving. The dish should be hot and cheesy with a slightly crispy top.
Slice into portions and serve hot, enjoying the combination of tender noodles, hearty sauce, and crispy cheesy topping.