In a non-stick pan, heat ghee and add whole wheat flour. Roast on low heat until it turns golden brown and aromatic (about 10 minutes).
Stir in the grated khoya and coconut (if using). Mix well and cook for another 3-4 minutes until combined.
In a blender, grind the chopped dates into a smooth paste. You can add a little warm water if needed for consistency.
Add the date paste to the roasted flour mixture. Stir thoroughly until well combined, ensuring there are no lumps.
Incorporate the chopped nuts and cardamom powder. Mix everything evenly to distribute the flavors.
Grease a plate or tray with ghee. Pour the mixture onto it, spreading it evenly. Press down firmly to set.
Allow the barfi to cool completely at room temperature. Once set, cut into squares or diamonds and serve.