One, very few real-world projects are totally "greenfield" -- as in, you get to (or in your case, have to) design things from scratch, without legacy code or peer projects/APIs to support. Most of the time you're inheriting someone else's code anyway, so refactoring & optimizing it IS the job, with small improvements along the way.
Two, I think it's totally normal for the first draft of software (or anything, really) to be just barely good enough. Whether you iterate and optimize it or someone else does, the idea is that it can get better over time. Maybe write it, rewrite it, optimize it, test it, further refactor it in a series of commits until you feel it's polished enough to actually PR? It doesn't have to all happen in one single pass. This is the sort of thing you'll probably just naturally get better at over the years, as long learn more and more patterns and algorithms and best practices that you can re-use in subsequent projects.
Three... do you LIKE optimizing existing stuff more than writing new code? If so, you can specifically look for projects (big corps maintaining legacy systems) or positions (test engineers, devops, DB admin, performance engineer, etc.) that focus on that IF that is your preference. But if you LIKE writing new code and just don't think you're that good at it yet, well, just keep doing it and you'll get better! It's a practice like any other.
FWIW, I've always considered myself a mediocre, self-taught dev who's never learned many of the best practices of computer science. I would never call myself an "engineer" because it's way too fancy a title. Still, it's been easier for me to find jobs in this field than any other that I've been in. There's way more demand than supply, for now, so even mediocre devs can build careers for themselves, and in so doing, learn from others along the way (sorry, coworkers, and thanks for the coaching!) Maybe just don't expect to join the FAANGs from the get-go, but get more experience in smaller businesses and tech-adjacent enterprises first?