01 - Preheat oven to 375°F. Grease a 9x13-inch baking dish.
02 - Boil salted water and cook ziti pasta until al dente, about 8 minutes. Drain and set aside.
03 - Heat olive oil in a large skillet over medium heat. Add chopped onion and sauté for 3 to 4 minutes until softened. Add minced garlic and cook for 1 minute more.
04 - If using, add ground beef or Italian sausage. Brown thoroughly, breaking it up with a spoon. Drain excess fat if necessary.
05 - Incorporate crushed tomatoes, tomato sauce, tomato paste, oregano, basil, red pepper flakes, salt, and pepper. Simmer uncovered for 10 to 12 minutes, stirring occasionally.
06 - In a large bowl, blend ricotta cheese, 1 cup shredded mozzarella, ¼ cup grated Parmesan, and the egg until smooth. Set aside.
07 - Add drained pasta to the sauce and toss until well coated.
08 - Spread half of the pasta and sauce mixture in the prepared baking dish. Dollop and gently spread half of the ricotta cheese mixture over the pasta. Repeat with the remaining pasta and ricotta mixture.
09 - Sprinkle remaining 1 cup mozzarella and ¼ cup Parmesan over the top.
10 - Cover loosely with foil and bake for 25 minutes. Remove foil and bake an additional 10 to 15 minutes until bubbly and golden brown.
11 - Allow to cool for 10 minutes. Garnish with fresh parsley or basil before serving.