Medications make it easier for that to happen. Find a good therapist and join a depression support group. Unfortunately, there are a lot of people for whom the psychiatric medications don't work. If we really want to recover from depression, we have to change how we go about living. Depression is something we get good at, something that reinforces itself.
Depression is a response to stress.
Often a loss of a relationship, but other stresses as well. There is a vulnerability that is partly genetic, partly the result of childhood and adolescent experience. Enough stress in a vulnerable individual means depression. But I agree with you, depression is also a signal that we're not doing something right. Some basic assumption we've been making doesn't work for us anymore.