To avoid bankruptcy, the main key is to be able to manage finances well. By being able to manage finances well, we can avoid bankruptcy when the economy is not good or when facing other problems related to finances. Managing finances is indeed not easy, there will be many temptations that make us not control our finances well, but believe me, if you do it continuously, you will get used to it. So it is important to apply financial management as early as possible.
For example, by recording income and expenses, this is the most difficult thing to do in personal finance.
An accountant alone is able to record company finances, but not necessarily able to record personal finances. Therefore, you must stick to the principle, if you work, work while others are sleeping. Save while others are shopping, study while others are partying, and enjoy life while they are dreaming.
All of that can be achieved if you make a mature spending plan and a clear monthly budget. Prioritize basic needs such as bills, food, and avoid debt. If you have extra money, set aside some of your income to save and invest for future targets.
Not everyone can "manage" their finances, not because they are incapable of doing it, but life isn't always straight forward. If everything is going normal and you are just overspending on useless stuff and you bankrupt because of that, then yeah it's your problem. But if everything is hectic, there are health problems, there are machinery problems, there is a natural disaster, whatever that is "unusual", like not a normal day, then you could bankrupt without anything you can do about it.
This is what happened to my dad, he lost his job because of a sickness, thankfully he recovered and did fine afterwards, but for 11 months we were quite poor and got a lot of debt when I was a kid, he paid it all back and retired now, but it was a tough period and he didn't do anything about his finances, it was just a sickness he had and there wasn't anything he can do. Even though he saved some money, how much can you really save, it was good enough for 5-6 months which is a lot for many people to save that much, but then we needed more.