Skip to content
Manoj Deshmukh
All English essays

Essay · 25 Jun 2025 · 3 min read

🚀 Modernising Legacy Code with Cursor AI: My Experience Porting a PHP Backend to .NET

By Manoj Deshmukh
🚀 Modernising Legacy Code with Cursor AI: My Experience Porting a PHP Backend to .NET

“How do you eat an elephant? One bite at a time.”

That’s exactly how I approached our recent migration of a legacy PHP CodeIgniter backend to a modern ASP.NET Core Web API — one method, one endpoint, one parity check at a time. And a tool that helped immensely during this journey was Cursor AI Studio.


🧩 The Challenge

We were tasked with modernising an e-commerce platform backend — a large, business-critical platform — without disrupting the existing client apps. This meant:

  • Preserving business logic and edge cases from a loosely typed PHP codebase.

  • Maintaining request and response model parity so that React Native client apps worked as-is.

  • Bringing the backend into the modern world of JWT auth, DI, Swagger, EF Core, and typed DTOs.

But how do you go from a procedural, scattered PHP app to a clean, testable .NET Web API — without missing a beat?


🧠 My Workflow with Cursor AI

I spent days experimenting, breaking, fixing, and iterating. What eventually worked best was a hybrid approach:

🔼 Top-Down

  • I analysed the client apps first to discover all API endpoints and documented them as a JSON contract.

  • I scaffolded all DTOs, controllers, and stubs upfront — almost like creating a skeleton from the outside-in.

🔽 Bottom-Up

  • Then I dove into the old PHP code, method by method, extracting business rules, conditions, and side effects.

  • With Cursor AI, I could feed context-rich prompts — combining legacy code, desired response structure, and the new .NET method — and iterate efficiently.

The trick? Stick to one model. One thread of logic. Cursor became more effective as I gave it consistent context and feedback.


🛠️ 10 Best Practices We Followed

Here are some ground rules that helped us maintain speed without sacrificing quality:

  1. One Endpoint at a Time: Never migrate a whole controller in one go.

  2. Always Green Builds: Don’t move forward unless the current code compiles and passes.

  3. Test Early, Test Often: We used Postman to validate every endpoint before the next.

  4. Business Logic Parity: Read every line of PHP — assumptions were costly.

  5. Standardize Responses: Used a common ApiResponse<T> wrapper across the board.

  6. JWT Best Practices: Extract IDs from tokens, not from request bodies.

  7. Data Type Rigor: PHP was forgiving; .NET is not. Handle string-float-boolean mismatches carefully.

  8. Default DB Values: For missing NOT NULL fields, set smart defaults in entities or DTOs.

  9. Swagger + README: Document as you go, not at the end.

  10. Celebrate Wins: Migrations are hard. Each successful controller deserved a mini-milestone celebration.


⚠️ Gotchas We Encountered

  • Auth Flow Differences: PHP returned tokens in headers; our .NET version initially returned them in the body — subtle but important.

  • Email Notifications: These were stubbed or incomplete in the original; we marked them as TODOs for .NET.

  • Identifier Misalignment: Some PHP methods used user_id, while the .NET equivalents used email. We had to realign these for perfect parity.

  • Hidden Logic: Legacy apps often hide business logic across random helper files. We found a few the hard way.


📘 What Made a Difference

Toward the end, I consolidated everything — learnings, contracts, decisions — into a single README.md file inside the codebase. This wasn’t just documentation — it was a playbook. A source of truth for anyone working on or reviewing the migration. I also used this to benchmark confidence levels for each endpoint.


✨ Final Thoughts

Using Cursor AI wasn’t about replacing my thinking — it was about accelerating it. By merging engineering discipline with AI assistive tools, we completed a tricky migration with over 95% parity confidence.

And perhaps more importantly, we walked away with a repeatable migration blueprint — ready to be reused for the next legacy project on the horizon.


Have you tried using AI tools like Cursor for code migration or modernization?

Would love to hear your experience — drop a comment or let’s connect!

First published on LinkedIn.

Read next