Can you stay friends with an ex?

So I was friends with this guy for like 8 years and we fell in love and dated for about 6 months. He has a lot of issues and suffers from depression which caused some issues because he's very closed off. We've talked about it multiple times and I've done everything I could to help him but the rest is stuff he has to do on his own. So we decided to break up because he's not ready for a relationship, he needs to get help to sort through his problems. I still want him in my life because we've been friends for ages but I'm struggling because I'm still in love with him. I want to talk to him all the time and every time I see him I fall for him more. He feels the same way. How do we stay friends after breaking up?