Preheat the oven to 375°F. Lightly grease a 9×13-inch baking dish and set aside.
Cook the ziti in well-salted water until just shy of al dente. Drain and set aside.
Heat the olive oil in a large skillet over medium heat. Add the chopped onion and cook until softened, about 3–4 minutes. Add the garlic and cook for about 30 seconds, until fragrant.
Add the ground beef or Italian sausage to the skillet. Season with salt and black pepper and cook until browned, breaking it up as it cooks. Drain excess grease if needed.
Stir in the marinara sauce and Italian seasoning. Reduce heat and let the sauce simmer for about 5 minutes.
Add the cooked ziti directly to the skillet with the meat sauce and stir until all the pasta is evenly coated.
In a medium bowl, mix the ricotta cheese, egg, Parmesan cheese, and a pinch of salt and black pepper until smooth.
Spread half of the ziti and sauce mixture into the prepared baking dish. Spoon the ricotta mixture evenly over the pasta and gently spread it into a layer. Top with the remaining ziti mixture, then sprinkle the mozzarella evenly over the top.
Bake uncovered for 25–30 minutes, until hot, bubbly, and lightly golden on top.
Let the baked ziti rest for 5–10 minutes before serving. Garnish with fresh basil if desired and serve with red pepper flakes on the side.