DEV Community

Cover image for Migrating from .NET to NestJS: Why I Decided to Stop Rewriting and Embrace the Legacy Code
Uchkun Rakhimov
Uchkun Rakhimov

Posted on

Migrating from .NET to NestJS: Why I Decided to Stop Rewriting and Embrace the Legacy Code

Rewriting a project from scratch is every developer's dream—and often, a business’s nightmare. Recently, I found myself at the center of this exact dilemma.

The Backstory: A Failed Giant

The project was a massive CRM built with .NET (C#). After over a year of development and significant investment, the project was stalled. It was riddled with bugs, unfinished features, and a codebase that the original developers no longer wanted to touch.

The business owner decided to revive it and started looking for a new team. That’s where I came in. As a Node.js/NestJS developer, my mission was clear: relocate, join the new team (PM, Frontend, and myself), and rebuild the entire backend from scratch in NestJS.

The Strategy: How I Started the "Great Migration"

I didn’t want to go in blind. To understand the complexity, I used Cursor AI to dissect the C# logic. My plan was pragmatic:

  • Keep the Database: I stuck with the existing Postgres schema to avoid data migration headaches.
  • Prisma to the Rescue: I ran npx prisma db pull to instantly generate my NestJS models from the existing DB.
  • API Parity: I kept every endpoint name, request body, and error response identical to the original so the Frontend wouldn't have to change a single line of code.

The Realization: Breaking the "New is Always Better" Bias

Two weeks into the rewrite, something unexpected happened. After spending days reading the C# code to replicate it in NestJS, I started understanding it.

I began to see the patterns, the lifecycle of the .NET services, and specifically, where the previous team had tripped up. I realized that the core logic wasn't "bad"—it was just misunderstood and poorly maintained.

I had a choice: spend months rebuilding what already existed, or take a shortcut that could save the business.

The Pivot: Pitching the "Stay" to Stakeholders

I went to the founders with a risky proposal:
"I understand the C# codebase now. Instead of spending months rewriting this in NestJS, let me fix the existing backend. We’ll save time, money, and launch much faster."

Their response was simple: "If you can handle the responsibility, go for it."

Lessons Learned (So Far)

I am currently working within that same .NET project. I’ve cleared the major bugs, stabilized the core, and most importantly, I'm learning more than I ever would have by staying in my comfort zone.

My takeaways from this journey:

  1. AI as a Language Bridge: Tools like Cursor AI are game-changers for understanding foreign codebases. They turn "reading code" into "having a conversation" with the logic.
  2. The "Rewrite" Trap: Sometimes we want to rewrite because we're afraid of someone else's mess. But fixing that mess is often the more professional (and profitable) path.
  3. Business First, Tech Second: Our job isn't just to write code in our favorite language; it's to solve problems.

I’ll be sharing more updates as we get closer to the full release. If you’ve ever faced the "Rewrite vs. Refactor" debate, I’d love to hear your thoughts in the comments!

Top comments (0)