So many great responses so far. Let me see if I can add anything helpful to you from my experience.

Initially, I did the same as you. I optimized based on mechanics. Created an archetype but not a character. Anyone could take on this role. So after some experience, I began trying to roleplay more than roll play.

One of the biggest things that have helped me? Explaining in-game as the character, how I learned all my new tricks when I leveled up. I try to rationalize the process of leveling up from the character's perspective. Once I have that road map figured out, I fill in the details on who would want to walk this path and what motivates them to keep walking it.

For example, I had a Sun Soul Monk that was known as the "****ty" wizard in the group. Even though, his comrades made fun of him especially when the actual wizard could do far more effective magic then he could, he would still smile because they called him a wizard. All he could do was make smaller fireballs (Produce Flame), fix broken things (Mend), and thanks to what a Druid showed him, make some really good berries that kept hunger at bay (Goodberry).

What kind of character could this be? Why would he still be happy? The reason is he came from a city where magic was everywhere and if you couldn't do it well, you were second class. He tried everything in school but couldn't do more than the 2 cantrips. This led to him being bullied a lot. He got really good at avoiding firebolts from his peers (good dex) and really understood the world around him (good wisdom).

He began working in the Library to try and learn how to like his peers and finally accepted. One day he found an old battered tome that seemed to have a magical quality to it. He opened it to discover many pages gone. He asked the head Librarian about it and she explained it to him. The book was found in a massive crater and though damaged seemed to be "frozen" in that state, for nothing could mend nor damage the book. One day, one of the city elders found a page written in the same text, that could also not be damaged. Bring the page and book to each other, the page returned to the book and could no longer be torn out.

This inspired him. He read what remained of the book and kept seeing things about the power of the Inner Light (Ki) and decided he would find the remaining pages and learn what the book had to teach.

There is more of course, but as he leveled, the book would be more complete and reveal more tricks and power (Sun Soul Monk class progression). My DM loved the idea and I loved playing that "****ty" wizard.