Bring a large pot of water to a boil and salt the water. Add pasta and cook the pasta to al dente doneness which means that the pasta will still have a bite to it or be a little chewy. I usually shave a minute or so off the boxed directions.
Preheat a deep, big skilletor a medium sauce pot over medium heat. Add extra-virgin olive oil to the pan, add garlic, onions, and cook, stirring a lot, for 5 minutes until the onions are translucent. Add the ham (optional) and tomatoes to the onions and stir. When the tomatoes come to a bubble, reduce the heat to low.
Preheat your broiler to high and place the oven rack in the center of the oven.
Drain pasta and transfer it to a 9×13 casserole dish. Top with pesto sauce, ricotta cheese, and Parmesan cheese. Stir carefully and coat the hot pasta with the pesto and cheeses. Pour the hot tomato and basil sauce over the pasta, as much as you like. You can always serve a little extra at the table, to pass around or use it for personal pizzas.
Sprinkle mozzarella cheese over the pasta and broil it for 2-3 minutes, until the mozzarella cheese has melted. Remove from oven and serve immediately.