You tagged this germany and this is very specific to Germany:
A little warning first: It's legal to have 4 weeks notice period, because the company employs less then 20 people and that is an exception, but please check your contract very carefully. Most of the time, employers just copy the legal default minimum, which is "4 weeks to the end of the month" or "4 weeks to the 15th of the month". In that case, you need to give 4 weeks notice at a specified point in time or before, not just 4 weeks before you want to leave.
Generally speaking, there is no harm in being a little early with handing in your notice. All the other horror stories you hear about unfair employers that fire you are in other countries that do not have Germany's strong laws and worker protections.
What may happen is that for your notice period, you will be getting the boring tasks. Routine maintenance, bugfixing, documenting. Not because anyone is out for you, but because that's what a notice period is for. Making sure your work is properly documented, making sure nothing is missing. The cool new shiny project? That is being worked on by your coworker. Not as a punishment, but because that person is probably still around when it launches.
So, make sure you read your contract correctly. Calculate the date you have to hand in your notice. Write it down, address the letter properly, make sure all the boxes are checked (you can google what needs to be in a Kündigung for your specific job and contract type), make sure you write a sentence or two about how you enjoyed it and appreciated the opportunity. Then print it twice and take it to work. Make sure you catch your boss at a good moment, not when they are fuming mad for a completely different reason already.
You can prepare all that in advance. There is no harm in handing in your resignation a week or two early. Do not wait until the last day if there is a better opportunity a few days earlier. Nothing bad can come out of it in Germany legally but there is a lot that can go wrong on that specific last day you need to hand it in.