Cook the Spaghetti:
Bring a large pot of salted water to a boil. Add the spaghetti and cook according to the package instructions until al dente. Drain and set aside.
Prepare the Meat Sauce:
Heat the olive oil in a large skillet over medium heat. Add the chopped onion and sauté for about 4-5 minutes until softened. Add the minced garlic and cook for another minute.
Add the ground beef (or turkey) and cook until browned. Stir in crushed tomatoes, tomato paste, oregano, basil, salt, pepper, and red pepper flakes (if using). Simmer for 15-20 minutes, stirring occasionally.
Prepare the Cheese Mixture:
In a large bowl, combine ricotta cheese, 1 cup of mozzarella, Parmesan, and fresh parsley. If using, add the egg and mix until smooth.
Assemble the Baked Spaghetti:
Preheat the oven to 375°F (190°C).
Spread a thin layer of the meat sauce at the bottom of a 9x13-inch baking dish. Add half of the cooked spaghetti, followed by half of the cheese mixture. Repeat the layers with the remaining spaghetti, meat sauce, and cheese mixture. Top with the remaining mozzarella cheese and Parmesan.
Bake the Spaghetti:
Cover the baking dish with foil and bake for 20 minutes. After 20 minutes, remove the foil and bake for another 10 minutes until the cheese is golden and bubbly.
Serve:
Let the baked spaghetti rest for 5-10 minutes before slicing and serving. Garnish with fresh parsley if desired.