I'm going to be a little mean here, but it sounds like you might be the problem.

> I've been doing a lot of work to clean up the debt that was accumulated and, meanwhile, I improved the reliability and the efficiency of the infrastructure. I wrote common components and library to avoid duplication and shared it with wiki pages on how to implement certain things correctly.

Did anyone ask you to do this work? Does it benefit the company in any tangible way? Did you make the product objectively better, or did you fixate on code purity at the cost of work that generates more business value? Sometimes tech debt needs to be addressed for technical reasons, sometimes it's a vanity exercise. If your work doesn't have visibility, maybe that's because no one wanted it done in the first place. Spending time on tech debt, not under the umbrella of tangible benefits, is usually not a productive undertaking. As much as you might loathe working on some hairy piece of code, if you're not changing it for a business reason, you might be making things worse. You might be adding complexity, introducing bugs, hurting performance, or simply going off on a wild goose chase.

> On the other hands, my colleague, is more focus on building relationships and acting like he's the manager even tho he's not. In a couple of circumstances he event tried to give me orders which is not what he supposed to do.

Building relationships is critical. Most of software development is not writing code; it's understanding business problems, gathering requirements, organizing/prioritizing, delegating, getting feedback, etc. Of course you need to produce a product at some point, but doing so effectively requires that at least some team members be engaged with product owners, customers, and other teams. Your colleague sounds like a manager/team lead, and it sounds like he's viewed that way by others.

> In meetings with our manager he brag on stuff that I did sharing it as a "we did", while when he does something alone (which most of the time asks to me as well) he would say "I did".

In a functioning team, almost all tasks should be "we dids" rather than "I dids". It doesn't sound like he's taking credit for your work. He's not saying "I did" in reference to your work; he's saying "we did". Maybe he slips up and says "I did" when talking about his own work. It could be that he is trying to speak in terms of team effort and only says "I did" out of habit for his own work. Or maybe he's an underhanded dick.

> This kind of behaviour was ok at the beginning but since our boss left and he got promoted as manager is not sustainable anymore.

It sounds like he IS a manager. In fact, despite your earlier claim about how it's not his role to give you orders, it sounds like that is in fact his role. It sounds like he is YOUR manager, but you're simply not happy about it.

Maybe your colleague is an asshole who takes credit for your work, brown-noses his way up the food chain, and is less technically competent, but I don't see any of that. What I see is someone who's able to strike a balance between social engagement and technical engagement, with natural leadership abilities, who's able to effectively delegate, and has successfully transitioned into a leadership role.

You have to advocate for yourself. If you don't think your contributions are appreciated, make sure that your contributions are what the company actually wants, and not your own agenda. Make sure people know what you contribute, by building relationships with other leaders in the company. Make your voice heard during planning and review meetings.

If you really are leading a few product teams, then you must have people working under you. Delegate to them, and stop worrying about taking personal credit. When your team does well, you'll look good. And if you start saying "we did" instead of "I did," your team will appreciate it and view you as a humble leader.