Preheat your oven to 350°F (175°C).
- Cook the spaghetti according to package instructions until al dente (about 8-10 minutes). Drain and set aside.
- In a large skillet, heat olive oil over medium heat. Add the chopped onion and cook for 2-3 minutes until softened. Add the minced garlic and cook for 30 seconds until fragrant. Add ground beef and cook until browned, breaking it apart as it cooks. Drain excess fat.
- Stir in marinara sauce, diced tomatoes (if using), basil, oregano, salt, and pepper. Simmer for 5-7 minutes, allowing the flavors to meld together.
- In a large mixing bowl, combine the cooked spaghetti with the sauce mixture, making sure the pasta is well-coated. If using ricotta cheese, mix it into the pasta and sauce for extra creaminess.
- Transfer the spaghetti mixture to a greased 9×13-inch baking dish. Top with shredded mozzarella and Parmesan cheese.
- Cover with aluminum foil and bake for 20-25 minutes. Remove the foil and bake for another 5-10 minutes until the cheese is melted and bubbly.
- Let the casserole rest for 5 minutes before serving. Garnish with freshly chopped parsley if desired.