Preheat your oven to 400°F (200°C) and line a baking sheet with parchment paper.
Place the halved tomatoes, quartered onion, and garlic cloves on the prepared baking sheet, drizzle with olive oil, and sprinkle with salt and black pepper.
Roast in the preheated oven for about 30-40 minutes, or until the tomatoes are soft and slightly charred around the edges.
Remove the roasted vegetables from the oven and let them cool slightly, then transfer to a blender or food processor and blend until smooth, doing this in batches if needed.
Pour the blended mixture into a large saucepan, stir in the dried oregano, dried basil, and red pepper flakes (if using), add sugar if the sauce is too acidic, and simmer over medium heat for 15-20 minutes, stirring occasionally.
Taste the sauce and adjust the seasoning as needed, and if the sauce is too thick, add a little water to reach the desired consistency.
Serve the sauce immediately over your favorite pasta or use as desired, and garnish with fresh basil if you like.