You can have multiple jobs there is no law against it. One or more of them could be working self-employed ("Selbstständiger"/"Freiberufler") or for your own company. Not every profession can be "Selbstständiger", it must be some kind of creative, mental work. Programming would work. Scrubbing toilets would not. But you can have your own company for any sort of work.
In theory it's dead easy. You ask your local "Finanz-Amt" (tax authority) for the form to fill out. You fill in the details, pay a small fee (probably less than 20€) and then you have either a "Freiberufler" or a company you now own. You will get a second (third...) tax id that is not your personal tax id, so you can use that to write invoices as a company.
So the paperwork is really easy. I did it, it's as easy as it sounds, it maybe takes 30 minutes to fill out that form, you can do it right there and turn it in if you want. My personal experiences with our local tax authority are super positive. Of all the authorities, this one is actually happy to have you, because you bring in money, not the other way round as it normally goes with "Amt"s.
However, there is a lot of legal work to be done. And you should get a lawyer to set that up right and advise you. How to do taxes? How to get insurance? Does your job need something like malpractice insurance or a "Gewerbeschein"? Do you need separate accounts for your business? Is it better to have a company or be self-employed for your specific case? And if it's a company, what legal form should it have? Do you make enough money that you have to pay taxes up front? Or can you use one of the many exemptions? Get a professional to answer all those questions before you register.
That said, you do have a legal duty to your day job: you are required to come to work rested and fit for the job. If you program all night for your side-business and are sleepy eyed and tired and make mistakes all day at your day job, that is a reason to eventually fire you. But it's the same reason as if you would play computer games or binge watch shows or talk to your friends all night every night, it has nothing to do with why you fail at your day job. Just make sure you do not, regardless of reason.
In addition, make sure you check your current contract for clauses what to do when you have another job. Employers may require notification of your side business.
So long story short: you can do that. It's perfectly legal, many people do it. But before you sign the papers, get professional help to get it right from the start.