Preheat the oven to 375°F (190°C).
Cook the ziti pasta in salted boiling water until al dente. Drain and set aside.
In a skillet, heat olive oil over medium heat. Add chopped onion and garlic, sautéing until soft.
If using meat, add ground beef or sausage and cook until browned. Stir in Italian seasoning, red pepper flakes, and crushed tomatoes. Let simmer for 10 minutes.
In a mixing bowl, combine ricotta, Parmesan cheese, and half of the shredded mozzarella.
In a baking dish, spread a layer of the meat sauce, followed by half of the pasta and dollops of the ricotta mixture. Repeat the layers and top with the remaining mozzarella.
Cover with foil and bake for 20 minutes. Remove foil and bake for another 10-15 minutes until the cheese is bubbly and golden.
Let rest for 5-10 minutes before serving. Garnish with fresh basil.