I feel like I'm in a better spot, but one thing I've learned consistently is that this is a universal, human issue. Very few people are lucky enough to go through life without what some would call mental illness.
We're also woefully underprepared to deal with these realities. You don't take a mental health class in high school, or college. At what point is someone supposed to train you to take care of yourself? Well, your parents, of course. But they usually have their own issues.
One thing that helped me was to get into therapy. BetterHelp is $320/mo, which is frankly a massive cost. But it was good to be in therapy on a weekly basis, and to explain all of the things that I felt were going on.
"Safe space" has been used pejoratively, and it's hard to say it without wincing. But if a safe space is important at all, therapy is the exact place that needs to be safe. And having a spot where you can simply vent to someone for 45 minutes straight was... quite therapeutic.
One advantage you have as a programmer, if you are one, is that you probably have more money than average. So if you're going through similar struggles, I encourage you to throw $320 at the problem and see what happens. It's not a cure-all, but nothing is.