01 - Preheat the oven to 375°F. Lightly grease a 9x13 inch baking dish.
02 - Boil ziti in salted water until just al dente, approximately 2 minutes less than package directions. Drain and set aside.
03 - Heat olive oil in a large skillet over medium heat. Sauté chopped onion until softened, about 3 minutes. Add minced garlic and cook for 1 minute more.
04 - Add ground beef to the skillet, breaking it apart while cooking until browned and no longer pink. Drain any excess fat.
05 - Incorporate crushed tomatoes, tomato sauce, tomato paste, dried basil, oregano, thyme, red pepper flakes if using, sugar, salt, and pepper. Simmer uncovered for 10 minutes, stirring occasionally and adjusting seasoning as needed.
06 - Combine ricotta, egg, half the mozzarella, and half the Parmesan in a bowl. Mix thoroughly and season with a pinch of salt and pepper.
07 - Add cooked ziti to the meat sauce and toss until evenly coated.
08 - Spread half of the ziti mixture in the baking dish. Evenly distribute half of the ricotta mixture over it. Repeat with remaining ziti and ricotta mixtures.
09 - Sprinkle the remaining mozzarella and Parmesan evenly across the top layer.
10 - Bake uncovered for 25 to 30 minutes until cheese is melted, bubbly, and golden. Let rest for 10 minutes before serving.
11 - Optionally garnish with fresh basil or parsley before serving.