01 - Preheat the oven to 375°F. Grease a 9x13 inch baking dish.
02 - Boil the pasta in salted water until al dente, about 2 minutes less than package instructions. Drain and set aside.
03 - Heat olive oil in a large skillet over medium heat. Sauté the chopped onion until translucent, approximately 3 to 4 minutes. Add minced garlic and cook for an additional minute.
04 - Add crushed tomatoes, tomato paste, oregano, basil, and red pepper flakes if using. Season with salt and pepper. Simmer uncovered for 10 minutes, stirring occasionally, then remove from heat.
05 - In a medium bowl, mix ricotta cheese, egg, Parmesan cheese, chopped herbs, and season with salt and pepper until well combined.
06 - Toss the cooked pasta with half of the tomato sauce in a large bowl.
07 - Spread half of the sauced pasta into the prepared baking dish. Dollop and gently spread the ricotta mixture evenly over the pasta. Sprinkle half of the shredded mozzarella over the cheese mixture. Top with the remaining pasta, pour remaining tomato sauce over it, then finish with remaining mozzarella and grated Parmesan cheese.
08 - Cover the dish loosely with foil. Bake for 25 minutes. Remove foil and bake an additional 10 to 15 minutes until the cheese is golden and bubbling.
09 - Let the dish stand for 10 minutes before serving. Garnish with extra chopped parsley or basil if desired.