01 - Preheat the oven to 375°F. Thoroughly grease a 9x13 inch baking dish.
02 - Cook the ziti or penne in a large pot of salted boiling water until it is just al dente, typically 1 to 2 minutes less than the package directions. Drain the pasta and set it aside.
03 - In a large skillet, heat the olive oil over medium heat. Add the finely chopped onion and cook until softened, about 3 minutes. Stir in the minced garlic and cook for an additional minute until fragrant.
04 - Add the ground beef to the skillet and cook, breaking it apart with a spoon, until it is thoroughly browned and cooked through. Drain any excess fat from the skillet.
05 - Stir in the tomato paste, crushed tomatoes, oregano, basil, red pepper flakes (if using), salt, and black pepper. Bring the sauce to a gentle simmer and cook for 10 minutes, stirring occasionally to prevent sticking.
06 - In a large mixing bowl, combine the drained pasta, the prepared meat sauce, ricotta cheese, and half of the shredded mozzarella. Mix gently to ensure all components are well incorporated.
07 - Spread half of the pasta mixture evenly into the prepared baking dish. Sprinkle with half of the Parmesan cheese. Layer the remaining pasta mixture on top, then finish by scattering the remaining mozzarella and Parmesan cheese over the surface.
08 - Cover the baking dish loosely with aluminum foil and bake for 20 minutes. Remove the foil and continue baking for an additional 10 to 15 minutes, or until the cheese is golden brown and bubbling.
09 - Allow the baked ziti to rest for 5 minutes before portioning and serving. Garnish with chopped fresh basil or parsley, if desired.