Celebrate Small Wins
Writing software is full of frustrations. Almost by its very nature you'll find yourself in situations where you don't understand things much more often than you have that feeling of mastery over a system or problem. The only way to continue working through these situations of uncertainty is the have the confidence that eventually you'll be able to figure it out.
Our lows are often more salient (and memorable) than our highs so it's important to consciously focus on your wins. Make an effort to explicitly acknowledge and write down your accomplishments. You'll need these as evidence to yourself (and others) that you can get through hard problems and to bolster your confidence when things are frustrating. If you never focus on the wins, you'll only remember the struggles.