I've programmed for 14 years and have 8 years of professional experience as a software engineer who is slowly entrenching in his niche -this is my personal philosophy to career management, ymmv:

What has worked for me in dealing with self doubt has been to separate my private self from my professional self when performing self evaluation. The professional self has a specific skillset with regards to the field, a specific capability to finish projects and specific market value. This is my public interface to the job market, my employer, and my co-employees when not at a coffee table, so to speak. I evaluate my situtation professionally with regards to this professional self. This creates certain detachment and alleviates emotional baggage (which I do have).

When figuring out where to professionally head next I evaluate this from the point of view of career risk and career opportunities. Projects are a one way to evolve your professional self, and they include opportunities as well as risks.

Given your situation, I would respectfully suggest a similar strategy in managing risk as with stocks. The risk of failure should come with some comparable advantage, and as you age, reduce the level of percieved risk. Be prepared to accept high risk projects early if they have some obvious percieved advantage to you.

The good part about risky projects is that if chosen correctly, they provide almost always the best benefit to you regardless of their outcome - experience.

There is good risk and bad risk, and you need to learn identify these. Bad risk is usually associated with some classical thedailywtf scenario with all the horrors of legacy software attached. Good risk is associated with scenarios that have some obvious advantage - i.e. usually learning new skills, making connections, and so on.

Reald world risky scenarios are usually a mix of these two.

Unless you are in a really precarious situation I would claim that professionally you are still in a situation where you professinal portfolio can endure quite a lot of risky situations. If you fail now you are just considered a bit wet behind the ears, a decade from now that would labeled as ineptitude.

Most of all, software engineering is a hands on craft. There more varied your experience, the better.

If you have self doubt in a perceived positive risk scenario I would advice you to dive in. But this is important - you must not give up, no matter what, you must finish the project. The result can be as hacky as necessary to fulfill you feature list (don't worry, as you gain experience you will find better ways to solve the specific feature) but it must become complete unless terminated by client. Strive for simple solutions.' Keep it simple stupid' should be your first approach in all scenarios.Complexity will happen any way, no reason why yoy should add any.

Do not burn yourself out. If you do not have the time for a project don't do it.

Like suggested, one way to make yourself a good career is to foster domain specialty in some niche that you perceive has long term traction. Specifically, what this might be, it's really hard to say. Generally, I would suggest to steer away from only specific vendor technologies towards either some abstract yet practical discipline (e.g. cryptography, computer graphics and so on) or a specific real world application domain (sensor software for heart rate monitors, for instance). Which is best for _you_ it is very hard to say.

Trying to find something that everybody around you is not doing and that sounds interesting would probably be a good start.

Declining projects for some perceived opportunity cost that is related to bad risk is a good choice.

How to find your niche? Hard to say-But as an example:
The deeper you dig into some specific area, you start to identify the missing pieces , the gray areas and zones where there are lots of obtuse papers and dusty tomes but wikipedia seems strangely bereft of any practical advice despite your acute technical need. In this case you are doing something wrong or you have diacovered a niche.

Try not to fall into a narrow and cushy niche that does not have market value. The individuals who fall into these are called expert beginners. Learn to separate these from the true experts early on, try not to become an expert beginner and you are well set.