1. Preheat the oven to 200°C. Bring a large pot of salted water to a boil. Cook the pasta according to the package directions. Drain and reserve 1/2 cup of the pasta water.
2. Meanwhile, lay the bacon in a large ovenproof skillet and cook over medium heat until brown and slightly crispy, 4 to 5 minutes per side. Remove the skillet from the heat, transfer the bacon to a paper-towel-lined plate and pour off all but 1 tablespoon of the drippings. Break up the bacon into bite-size pieces.
3. Return the skillet to medium heat, add the garlic and cook, stirring frequently, until soft, about 1 minute. Add the tomatoes and juices, reserved pasta water, chilli flakes, basil, endive and 1/2 teaspoon salt. Bring to a simmer and cook until the sauce thickens, 15 to 20 minutes.
4. Mix together the ricotta and Parmesan. Add the cooked pasta and mozzarella to the sauce and stir to thoroughly coat. Drop spoonfuls of the ricotta-Parmesan mixture on top. Sprinkle with the bacon pieces and bake until bubbly and the cheese melts, 15 to 20 minutes. Let rest for a few minutes before serving. Garnish with additional basil if using.