You can receive legal aid if you meet the following requirements:
You cannot pay the costs of the legal proceedings, or you can only afford part of it. This can be the case, for instance, when you are eligible for state benefits such as Hartz IV, social benefits or asylum seeker benefits. If you earn an income, you must disclose your salary, assets, and expenses. The court then will decide whether you can afford the costs or are eligible for legal aid.
You have (at least) some chances of success in court. That means if it is clear from the very start that you will lose the case, you will not receive legal aid.
The legal process makes sense for you. That means if, for instance, the money you could end up winning is less than the costs of a lawsuit, you will not receive legal aid.
Please note: It does not matter whether you are the plaintiff or the defendant. If you meet the requirements above, you can benefit from legal aid.