01 - Preheat the oven to 375°F. Lightly grease a 9x13-inch baking dish with cooking spray or a small amount of olive oil.
02 - Bring a large pot of salted water to a boil over high heat. Add ziti pasta and cook until just al dente according to package directions. Drain well 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 and translucent. Add minced garlic and cook for 1 minute more until fragrant.
04 - Add ground beef to the skillet, breaking it up with a wooden spoon or spatula. Cook until browned and cooked through, approximately 5 to 6 minutes. Drain excess fat if necessary.
05 - Stir in marinara sauce, dried basil, dried oregano, red pepper flakes if using, salt, and black pepper. Reduce heat to low and simmer for 5 minutes to allow flavors to meld.
06 - In a large mixing bowl, combine the drained ziti pasta, beef and marinara mixture, ricotta cheese, and 1 cup of the shredded mozzarella cheese. Mix gently until evenly combined.
07 - Transfer half of the pasta mixture to the prepared baking dish. Sprinkle with half of the remaining mozzarella and half of the Parmesan cheese. Add the remaining pasta mixture on top.
08 - Cover the baking dish tightly with aluminum foil. Bake for 20 minutes to heat through and melt the cheeses.
09 - Remove foil and bake for an additional 10 to 15 minutes until the cheese is bubbly and golden brown on top. Let the baked ziti stand for 10 minutes before serving to set. Garnish with fresh basil or parsley if desired.