DEV Community

Md Fattan Prodan Pathul
Md Fattan Prodan Pathul

Posted on

Cope Up with An Existing Code Base and AI Driven Coding Environment

Where do you even start?

Let's say you just joined a new company. Or maybe your manager has assigned you a legacy project that you have never worked on before. You clone the repo and open it. 200 files staring at you. A README that nobody has touched in three years. And then there is that one function, handleStuff2(), which somehow touches everything. Yes, we have all been there!

Now there is a new twist. An AI assistant is sitting right inside your editor, ready to explain code, write code and clean up code, just one prompt away. The help is real, no doubt. But it also comes with its own traps.

In this post, we will see how to get comfortable in code you did not write, and how to use AI as a shortcut without creating a bigger mess.

Why existing codebases are hard

Here is the truth: most of us spend our working life inside code that already exists. A fresh, brand new project is rare, like a unicorn. And yet, nobody really teaches us how to enter an old codebase. We are just thrown into the deep end and told, "Learn swimming."

So what makes it so difficult? Let's see:

  • Missing or outdated documentation. The README says one thing, the code does something completely different. Who do you trust? Usually, the code.
  • The original authors are gone. The people who knew why things were built in a certain way have left the company. Their knowledge went with them, and nobody wrote it down.
  • Technical debt. Quick fixes, copy-pasted logic and "temporary" workarounds keep piling up for years. Remember, in every codebase, "temporary" is the most permanent word.
  • Hidden dependencies. You change one small thing on one side, and something breaks on the other side of the project. Nobody can explain how they are connected.
  • Fear of touching anything. When no one fully understands a module, everyone just stays away from it. The module becomes scarier and more confusing with time, like that one room in the house nobody enters.
  • No tests to protect you. Without tests, you never know if your change is safe until it breaks in production. And that is the worst time to find out.
  • Too many different styles. Ten developers, ten different ways of writing code. Reading it feels like reading a book written by ten authors who never met each other. But here is the important part: none of this means the code is bad. The code is simply carrying a long history that you have not learned yet. Once you understand that history, things start making sense.

How developers usually start with legacy code

Before, almost every developer learned a new codebase in the same old way. And honestly, many still do. It is a top-down walk through the code, following the same path a real user takes inside the app. Simple idea, and it works.

  1. Pick one module. Don't try to eat the whole elephant. Choose the one your task is touching, like billing or user accounts.
  2. See what it does. Run the app and use the feature yourself. Click here, click there, break something (on your local machine only, please!). Once you know the purpose, the code starts making more sense.
  3. Find its routes. Check which URLs belong to that module. These are the front doors of the feature.
  4. Open the pages. Go to each route and see what it shows on the screen.
  5. Look at the components. Find out which components each page is using and how they are connected to each other. Like a family tree, but for UI.
  6. Read the methods. Now go inside the functions, hooks, services and API calls. This is where the real logic is sitting, and this is where you will spend most of your time.
  7. Find the "why". Something looks very strange? Go and ask the developer who wrote it. If that person has already left the company, then your next option is the commit messages. This method works, no doubt. It is thorough, and slowly it builds a proper picture of the system in your head. But on a big codebase, it is slow. You are reading layer by layer even when you only need one path. And the last step often hits a wall: the original developer is gone, and the commit message just says "fix". Thank you very much, that was really helpful!

Understanding a codebase, with AI as your guide

Before you panic and start scrolling through all 200 files one by one, take a deep breath. You don't need any magic here. The old, proven ways still work. AI just makes them faster. Think of it as the same road, but now with a GPS. Here is the plan, and what you can ask AI at every step.

  1. Run the project on your machine first. Nothing teaches you faster than seeing the thing actually work. Setup is failing? No problem. Ask the AI to read the config files and build scripts and tell you what the project is expecting. (Most setup errors are just a missing version or a missing environment variable, anyway.)
  2. Read the tests. Tests are like a free user manual. They show what the code is supposed to do. Ask the AI to summarize what a test file is covering, and more importantly, what is left untested. Those gaps are where the surprises are hiding.
  3. Follow one feature from start to end. Pick one user action, like clicking the "Login" button, and trace it from the UI to the database and all the way back. Ask the AI to walk you through the data flow across different files. Suddenly the 200 files start looking like one story.
  4. Go through the git history. Commit messages and diffs tell you why the code changed. Got a big, messy diff that makes no sense? Paste it and ask the AI, "What was the developer trying to do here?" It is like having a detective explain the old case to you.
  5. Start with small and safe changes. Fix a tiny bug, add one log line, improve one test. Before you commit, ask the AI what else could get affected by your change. A second pair of eyes never hurts. Here is a good prompt to start with:

"Explain what this file does, what calls it, and what would break if I changed it."

But here is the golden rule: always verify the AI's answer against the actual code. The AI can sound very confident and still be wrong. Trust, but check. Why this matters so much, we will see in the next section.

The risks nobody puts on the slide

Everyone loves to show the good side of AI in demos and presentations. But there is another side, and it deserves some attention. AI tools are confident by design. When they are right, this confidence is very helpful. When they are wrong, it is dangerous, because they will never say "I am not sure."

  • No project context. The AI does not know your business rules, your team's conventions, or why that strange workaround is sitting there. Sometimes ugly code is ugly on purpose. The AI may "clean it up" and break something that was working fine for five years.
  • Invented answers. It can describe functions, APIs or config options that do not exist at all, and it will say it in the same smooth tone as the correct answers. You will search for that function for one hour, and then realize it was never there.
  • Code nobody understands. Generated code can pass all the tests and still not match the rest of the codebase. Copy-paste it without understanding, and six months later it becomes the next handleStuff2(). Congratulations, you have created tomorrow's legacy code today!
  • Privacy and policy. Pasting your company's proprietary code into an external tool may break company policy or client agreements. Know the rules first, then paste. "I did not know" will not save you in front of the manager or the client.
  • Skill erosion. If AI is always doing the reading for you, you never build your own mental picture of the system. Then one day the AI is not available, or gives a wrong answer, and you are standing there with no idea. It is like depending on a calculator so much that you forget basic maths. The lesson is simple: use AI as your assistant, not as your boss. Let it speed you up, but keep your own brain switched on.

A working playbook

Good news: you don't have to stop using AI to stay safe. Just follow these five simple habits, and you will get the speed of AI without falling into most of its traps.

  1. Review AI output like a junior developer's pull request. Read every single line. Don't only ask, "Is it running?" Ask, "Does it actually fit our codebase?" Code that runs today can still be a headache tomorrow.
  2. Give the AI proper context. Don't expect it to read your mind. Share the project structure, your coding standards and the relevant files. Many tools also support a project rules file, so please use it. Five minutes of setup saves hours of fixing later.
  3. Understand first, generate second. Use AI to explain the code before you ask it to write anything. Code you understand is code you can maintain. Code you don't understand is just a future problem with your name on it.
  4. Keep changes small and tested. Small diffs are easy to review and easy to revert. Big diffs are a prayer. And tests will catch what both you and the AI missed, so don't skip them.
  5. Write down what you learn. Every insight you gain is one less thing the next developer has to find out the hard way. Update the README, add a small comment, or note down why a decision was taken. That next developer might even be you, six months from now, with no memory of any of this! Follow these, and AI becomes a real helper instead of a risky shortcut.

The bottom line

Inheriting a codebase used to mean weeks of slow, lonely reading. Just you, a cup of chai, and 200 files that refuse to talk back. Now AI has changed that. You can ask questions to the code and get useful answers in seconds. Honestly, that is a big relief.

But remember, the goal was never just to read code faster. The real goal is to understand the system well enough that you can change it safely, without breaking things on a Friday evening. And that part is still yours. No tool can do it for you.

AI can read the code for you, but only you can understand the system.

Top comments (0)