There is no perfect diet which works for everyone. Doesn't exist. The best you can aim for is:
Nutrititous foods (which you enjoy) in quantities which match your goals
To stay healthy you should be eating lots of fresh, minimally processed food which your body responds well to. To lose weight you should be consuming fewer calories than you burn. To gain weight you should be consuming more calories than you burn. How each of us goes about hitting these targets can vary wildly but there are a few habits which come up more often than most.
For weight loss:
1) Eat slowly until 80% full
2) Eat mostly fresh, minimally processed food
3) Eat some protein-dense food with each meal
4) Go big on the veggies and fruits
5) Drink mostly water
6) Treat treats as treats
For weight gain
1) Eat mostly fresh, minimally processed food
2) Eat some protein-dense food with each meal
3) Eat more frequently throughout the day
4) Consume bigger portions of energy-dense foods (carbs and fats)
In most instances these simple habits are all you need.