Cook the spaghetti in salted water until al dente.
Meanwhile, halve the onions, cut into thin slices and place in a bowl. Dice tomatoes and mozzarella and add to the bowl. Also cut and add the basil leaves. Now pour the balsamic vinegar and olive oil over the ingredients, season with salt and pepper and mix well. When the spaghetti is cooked, drain it, add to the remaining ingredients in the bowl and mix everything well.
Tastes great when the spaghetti is still slightly warm. When cooled, it is also a delicious pasta salad that e.g., goes well with grilling. However, it should be served fresh as the pasta swells up after a while in the vinegar and the dish then no longer tastes so good.