Preheat the oven to 375°F (190°C).
Heat olive oil in a skillet. Add onion, garlic, and mushrooms. Cook until softened.
Spread a thin layer of marinara sauce on the bottom of a baking dish.
Layer zucchini slices, mushroom mixture, ricotta (mixed with egg if using), more sauce, and mozzarella.
Repeat layers until ingredients are used up, finishing with mozzarella on top.
Bake uncovered for 35–40 minutes until golden and bubbly.
Let rest for 10 minutes before slicing. Garnish with fresh basil.