Heat some olive oil in a large frying pan. Gently fry finely sliced onion and crushed garlic until golden. Set aside.
Spread passata or tomato sauce at the base of a gratin dish. Mix in onion mixture, thyme and fennel seeds. Season to taste.
Cut aubergine, courgette and tomatoes into thin slices.
Add the sliced vegetables on top of the tomato base alternating them evenly. Make sure vegetables overlap, packing everything neatly together. Season and add a drizzle of olive oil on top before baking in the oven for 30 mins.
After 30 mins, add grated parmesan on top, followed by olives and pine nuts. Return to the oven for another 5 mins.
Serve hot or warm with basil leaves sprinkled all over.