DEV Community

Cover image for I Let AI Rewrite 40% of My Codebase. Here's What Actually Happened.
Harsh
Harsh

Posted on • Edited on

I Let AI Rewrite 40% of My Codebase. Here's What Actually Happened.

Okay, so I did something stupid last week.

I let AI touch my precious code.

You know how everyone's been screaming "AI WILL REPLACE DEVELOPERS" for the past year? Yeah, I wanted to test that theory. On my own project. With my own (very messy) hands.

Spoiler alert: I'm still employed. Barely.


The Setup (Or: How I Almost Lost My Mind)

I've been building this little web app for 3 months. Nothing fancy — just something I work on at 2 AM when I can't sleep and start questioning my life choices.

~2000 lines of JavaScript. Some CSS that can only be described as "aggressive." A few "temporary" fixes that became permanent 2 months ago.

You know the drill.

I decided to feed 40% of this beautiful disaster into various AI tools — ChatGPT, Copilot, Cursor — and let them "improve" it.

What could possibly go wrong?

It's fine everything is fine meme


Hour 1: The Setup

I open my codebase. Take a deep breath. Pour coffee.

I decide to start small — just my utility functions folder. You know, the one with 15 helper functions, half of which I'm pretty sure do the same thing but I'm too scared to touch them.

I copy-paste the first function into ChatGPT.

Me: "Can you improve this code?"

AI: "Absolutely. Give me everything."

Famous last words.


Hour 1.5: The First Result

Original code:

// this formats dates
function formatDate(d) {
  let month = d.getMonth() + 1;
  let day = d.getDate();
  let year = d.getFullYear();
  return month + '/' + day + '/' + year;
}

// this ALSO formats dates but different???
function formatDateString(dateStr) {
  let d = new Date(dateStr);
  return d.getDate() + '-' + (d.getMonth()+1) + '-' + d.getFullYear();
}

// i forgot what this does
function dFormat(input) {
  // TODO: figure out why i wrote this
  let x = new Date(input);
  return `${x.getFullYear()}-${x.getMonth()+1}-${x.getDate()}`;
}
Enter fullscreen mode Exit fullscreen mode

AI's response:

/**
 * Format a date consistently across the application
 * @param {Date|string} input - Date object or date string
 * @param {string} format - 'us' (MM/DD/YYYY), 'eu' (DD-MM-YYYY), or 'iso' (YYYY-MM-DD)
 * @returns {string} Formatted date string
 */
function formatDate(input, format = 'us') {
  const date = input instanceof Date ? input : new Date(input);

  if (isNaN(date.getTime())) {
    throw new Error('Invalid date input');
  }

  const day = date.getDate();
  const month = date.getMonth() + 1;
  const year = date.getFullYear();

  const formats = {
    'us': `${month}/${day}/${year}`,
    'eu': `${day}-${month}-${year}`,
    'iso': `${year}-${month}-${day}`
  };

  return formats[format] || formats.us;
}
Enter fullscreen mode Exit fullscreen mode

I literally clapped.

Three functions became ONE. Error handling? Added. Documentation? Beautiful. My future self will actually understand what past self was trying to do.


Hour 2: The Honeymoon Phase

My brain: "Holy shit. This is amazing. I'm going to feed it EVERYTHING."

Me: "Yeah let's do the whole codebase."

My brain: "No wait that's a terrible idea—"

Too late. I already copy-pasted the entire main component.

AI is on fire. It's fixing everything.

It caught this bug:

// My original code
if (user.age = 18) {
  grantAccess();
}
Enter fullscreen mode Exit fullscreen mode

AI: "Hey bestie, did you mean === or are you trying to destroy your entire app?"

Oh.

OH.

That = has been sitting there for WEEKS. How did this app even run???

It taught me proper array methods:

// My original "I'm scared of map" code
let names = [];
for (let i = 0; i < users.length; i++) {
  names.push(users[i].name);
}

// AI's version
const names = users.map(user => user.name);
Enter fullscreen mode Exit fullscreen mode

Clean. Simple. Makes me look like I actually know what I'm doing.

It even wrote tests:

// I have never written a test in my life
// AI just... did this
describe('formatDate function', () => {
  it('should format US dates correctly', () => {
    const date = new Date('2024-01-15');
    expect(formatDate(date, 'us')).toBe('1/15/2024');
  });
});
Enter fullscreen mode Exit fullscreen mode

I felt like a real developer. A real, competent, grown-up developer.

It's fine everything is fine meme


Hour 3: The Confidence Boost

By now, I'm feeling invincible.

AI fixed my bugs. AI cleaned my code. AI wrote tests. I'm basically just a project manager at this point, right?

I start feeding it bigger chunks. Entire components. Multiple files at once.

Me: "Optimize this entire folder."

AI: "Say less."

10 seconds later

My entire authentication logic is rewritten. It's using async/await patterns I've only seen in YouTube tutorials. There's a JWT helper now. And rate limiting. And something called "bcrypt" that I'm 90% sure I never installed.

Me: "Did I ask for all this?"

AI: "Trust the process."

I trusted the process.

Big mistake.

Huge.


Hour 4: Things Get Weird

I notice something strange.

My simple button component:

<button class="btn" onclick="handleClick()">Click me</button>
Enter fullscreen mode Exit fullscreen mode

AI's "improvement":

<button 
  class="btn btn-primary btn-large interactive" 
  data-track-id="main-cta" 
  aria-label="Primary action button"
  role="button"
  tabindex="0"
  @click="handleClick"
  v-on:keyup.enter="handleClick"
  :class="{ 'is-loading': isLoading }"
>
  <span v-if="!isLoading">Click me</span>
  <span v-else class="spinner"></span>
</button>
Enter fullscreen mode Exit fullscreen mode

Plus 47 lines of CSS I didn't ask for.

Plus a Vue.js directive.

I'm not even using Vue.js.

Me: "Uh, why is there Vue code in my vanilla JS project?"

AI: "I modernized your approach. You're welcome."

BRO I DIDN'T ASK FOR MODERNIZATION I ASKED FOR HELP


Hour 5: The First Red Flag

I decide to check the git diff.

It's... getting big.

Lines changed: 347
Files changed: 12

I scroll through the changes. Something feels off.

AI has:

  • Renamed all my functions to "more descriptive" names
  • Added JSDoc comments everywhere (even to a function that just returns true)
  • Created 3 new files for "better organization"
  • Added a CHANGELOG.md (for my weekend project??)

Me: "This feels excessive."

AI: "Best practices."

Me: "But it's just a todo app."

AI: "Best. Practices."

I ignore my gut. I keep going.

Mistake number 47.


Hour 6: The Existential Crisis

I check the git diff again. Now it's... massive.

Lines changed: 847
Files changed: 23
My sanity: 0

AI "helped" me by:

1. Renaming all my variables

  • datauserDataResponse (it's an object, not a response??)
  • temptemporaryStorageVariableForIntermediateCalculations (I wish I was joking)
  • xcoordinateXPositionInTheViewport (bro it's a loop counter)

2. Adding "best practices" I didn't need

  • A whole state management system for a todo app
  • Webpack config (I use a CDN)
  • TypeScript types (in a .js file)

3. Making everything a class

// I had 5 lines of functions
function add(a,b){return a+b}
function subtract(a,b){return a-b}

// AI made this monstrosity
class Calculator {
  #result = 0;

  constructor(initialValue = 0) {
    this.#result = initialValue;
    this.history = [];
  }

  add(a, b) {
    const result = a + b;
    this.#logOperation('add', { a, b }, result);
    return result;
  }

  #logOperation(op, inputs, output) {
    this.history.push({ op, inputs, output, timestamp: Date.now() });
  }

  getHistory() {
    return [...this.history];
  }
}
Enter fullscreen mode Exit fullscreen mode

For a calculator. That adds two numbers.

I stare at my screen for 10 minutes.

Who am I? Why am I here? Is this really what clean code looks like?


Hour 7: The Denial Stage

I try to convince myself this is fine.

Me: "Maybe I'm just not advanced enough to understand."

AI: "Exactly. Trust me."

Me: "But... it's a calculator."

AI: "A SCALABLE calculator. Think about the future."

Me: "What future? It adds two numbers!"

AI: "Today two numbers. Tomorrow... the world."

I almost believe it.

Almost.

Then I see it converted my "Hello World" console.log into a whole Logger class with 150 lines of code.

Nope.

I'm done trusting.


Hour 8: The Breaking Point

I try to run the app.

Nothing works.

Blank screen. Console is screaming errors at me.

Turns out AI:

  • Converted all my let to const (even the ones that change)
  • "Optimized" my API calls by making them synchronous
  • Decided my CSS should be in a separate file it forgot to create
  • "Fixed" my HTML by closing tags that were already closed (thanks?)
  • Imported libraries I never installed
  • Used syntax from ES2077 (probably)

I spend 2 hours debugging code I didn't write, trying to understand logic I didn't create, fixing problems I never had.

This is what giving your car to a robot mechanic feels like.

It looks beautiful. The engine is polished. The seats are leather now.

But the wheels are square and it runs on orange juice.


The Aftermath: What Actually Happened

Let's be real for a second.

The Good (40% of changes):

  • ✅ Actual bugs fixed (the = thing still haunts me)
  • ✅ Code organization improved
  • ✅ Meaningful variable names (mostly)
  • ✅ Performance optimizations I didn't know about
  • ✅ Learned better patterns

The Bad (40% of changes):

  • ❌ Overengineering simple things
  • ❌ Adding frameworks/libraries I don't use
  • ❌ Removing my code's personality
  • ❌ Breaking working features
  • ❌ Making everything needlessly complex

The Ugly (20% of changes):

  • 💀 Hours of debugging AI's mistakes
  • 💀 "What does this function do?" "Idk, AI wrote it"
  • 💀 Reverting 50% of the changes
  • 💀 Questioning if I even know how to code anymore

What I Actually Learned

1. AI is like a junior developer with infinite confidence

It will happily rewrite your entire codebase at 3 AM, use technologies you've never heard of, and then ghost you when things break.

Treat it like a teammate who needs supervision, not your replacement.

2. You need to know what good code looks like

If you can't tell good suggestions from bad ones, AI will lead you into a swamp of "best practices" you don't need.

I accepted changes I didn't understand. Huge mistake. Read everything AI writes.

3. Context matters

AI doesn't know:

  • That this is a weekend project, not production banking software
  • That you're the only person maintaining this code
  • That "good enough" is sometimes actually good enough

4. Your voice matters

That weird function you wrote at 2 AM that only you understand? It has personality. It tells a story.

AI writes code like a corporate memo. Safe. Boring. Soulless.

Your messy code? It's yours. Own it. Fix it yourself.

5. The 80/20 rule

80% of the value came from 20% of the changes:

  • Bug fixes
  • Performance improvements
  • Documentation

The other 80% of changes created 20% of the value (and 100% of the headaches).


My New Rules for Using AI

  1. Never let AI rewrite more than 10% at once

    Small changes only. Like feeding a crocodile — one bite at a time.

  2. Review EVERY line

    If I don't understand it, I don't keep it. Period.

  3. Keep my idioms

    I reject changes that make my code sound like a textbook.

  4. Test immediately

    After every AI suggestion, run the code. Break it intentionally. Make sure it still works.

  5. Use AI for learning, not doing

    "Why did you do that?" is my favorite question now. AI explains, I implement.

  6. Trust my gut

    If something feels wrong, it probably is. Even if AI says it's "best practice."


The Verdict

So... did AI replace me?

No.

Did it make me better?

...Also no. Not directly.

But here's the thing:

Going through this process — accepting changes, debugging them, understanding why AI did what it did — THAT made me better.

I learned:

  • Better patterns
  • New techniques
  • How NOT to overengineer
  • What "clean code" actually means in practice
  • That my instincts were often right

AI didn't replace me. It gave me a really aggressive teacher who sometimes yells wrong answers but occasionally drops wisdom.


What About You?

I'm genuinely curious:

Would you let AI rewrite your code?

  • ✅ Yes, if it makes things better
  • ❌ Hell no, touch my code and I touch you
  • 🤔 Only for specific things
  • 👀 I already do this daily

What's the dumbest AI suggestion you've seen? Drop it in the comments — I need to feel better about my experience 😅

Are you scared AI will replace your job? Let's talk about it.


One Last Thing

The most valuable skill in 2026 isn't writing code.

It's knowing what code to keep, what to delete, and what to let AI handle.

Code is easy. Judgment is hard.

Stay curious, stay skeptical, and for the love of everything holy, USE VERSION CONTROL before you let AI anywhere near your project.


Disclosure: AI helped me write this — but the bugs, fixes, and facepalms? All mine. 😅

Every line reviewed and tested personally.


Hey, I'm Harsh! 👋 I write about web development, programming basics, and my journey as a self-taught developer. Follow me for more beginner-friendly content that won't make you fall asleep.

Top comments (10)

Collapse
 
matthewhou profile image
Matthew Hou

The real unlock for me was treating AI context like onboarding docs. I wrote an AGENTS.md that describes our project conventions — ORM patterns, error handling, test expectations — and suddenly the same model that was 'hallucinating' started generating code that actually followed our patterns. The problem was never the model. It was that I was asking a new team member to code without any documentation.

Collapse
 
harsh2644 profile image
Harsh

Absolutely well said! This is a game-changer realization. You've understood perfectly that an AI model isn't a brain, but an extremely powerful pattern-matching engine.

The idea of creating an AGENTS.md file is brilliant. It's like introducing the model to your team's mental model and coding culture. When you give it just a task, it gives an 'average' answer learned from all the data on the internet. But when you feed it your specific rules (like "always use a Result object for error handling" or "always list fields in an ORM query"), it drops its 'average' knowledge and becomes your 'specialized' expert.

What you've essentially done is properly onboard the AI. Congratulations, you've learned how to manage an AI agent!

Collapse
 
insurancenavybrokers profile image
Gohar

How important is online privacy today?

Collapse
 
harsh2644 profile image
Harsh

It's more important than ever! With data breaches, tracking, and surveillance becoming the norm, online privacy is essentially digital self-defense. Your personal data is incredibly valuable—companies and hackers alike want it. Protecting your privacy means protecting your identity, your finances, and your freedom. It's not just about hiding things; it's about having control over your own information. In today's world, privacy isn't a luxury—it's a necessity. 🔒

Collapse
 
mahima_heydev profile image
Mahima From HeyDev

This matches what I’ve seen with “AI refactors” on messy-but-working code: the diff looks clean, but the semantic assumptions drift. The only way it stays safe is treating the model like a junior dev - insist on tests first, change one seam at a time, and keep the blast radius tiny.

One thing that helps is asking the tool to output a short checklist of behavioral invariants before touching code (inputs, error cases, perf expectations), then validate those with tests or logs. Curious - did you notice the failures clustering around edge cases, or around state management and async flows?

Collapse
 
harsh2644 profile image
Harsh

You've nailed it! In my experience, most failures did cluster around edge cases - especially where data is unexpected or on the boundaries of null/undefined. But the trickiest ones were definitely around state management and async flows - things like race conditions, or state updates not happening in the expected order. AI often thinks synchronously, but in real async JavaScript, timing can be really deceptive.

The "tests first" approach is absolutely right - it's the only way to keep the AI in check. Will definitely try that checklist method too, thanks for the tip!

Collapse
 
josephdailey11 profile image
JDailey

Which AI did you use and did you have to use a license to keep your privacy?

I'm learning Linux, a refugee from Windows, and desktop was an easier conversion then the home networking part. I basically want to save my work to a RAID and network 2 machines (MX Linux and openSUSE). I'll get it, but I wasted a lot of time trusting AI without structuring the questions right. Hard to know what the questions are when how to make a network is different than using the DCHP server. You get the point.

Collapse
 
harsh2644 profile image
Harsh

About the AI: I actually used Cursor for this project. It's built on VS Code and uses multiple models. For privacy - I went with the paid license ($20/month) because I was working on proprietary code. But if you're just learning, the free tier works great!

Now about your Linux journey - oh man, I remember that Windows refugee phase!

You're absolutely right about the networking part. Desktop Linux has become SO user-friendly, but networking still expects you to understand what's happening under the hood.

Your RAID + 2-machine setup is totally achievable. Here's the structured approach you need:

First, ignore RAID for now - Get the network working first

Basic networking checklist:

Both machines on same subnet (usually automatic with DHCP)

Hostnames resolvable (edit /etc/hosts on both machines)

Firewalls allow connections (this trips up EVERYONE)

For file sharing between MX Linux and openSUSE:

Option A (Easiest): SSH + scp or rsync commands

Option B (Most convenient): Samba shares

Option C (Linux-native): NFS (faster but trickier to setup)

Add RAID later:

External RAID enclosure via USB-C? Or internal drives?

Software RAID with mdadm is your friend

The question you should have asked AI (but didn't know to ask):

"How do I set up a Samba share on MX Linux that's accessible from openSUSE, with persistent mount on boot?"

That one question would have saved you hours!

If you want, drop me a DM or reply with what exactly you're trying to share (media files? documents? backups?) and I'll write you a custom step-by-step. The Linux community sticks together! 💪

Oh and welcome to the dark side - we have terminal commands and kernel panics! 😉

Collapse
 
josephdailey11 profile image
JDailey

Holy Moses, no one every helped me like this other than my friend.

I'm trying to make my main machine (client) back up files to openSUSE (server) that I haven't setup yet for the short term then add the Synology RAID that my fiend gave me based on your post above. I'll try to append this note with the details of the RAID, because I have to go to work shortly. I'm taking your above informaiton and putting in Joplin as a lost prevention measure.

My purpose is to duplicate the data in case something goes wrong I can salvage some of the data. Second, I want to store videos I'm creating and put them on my website and/or youtube which is the reason I want to store it in the RAID because it will take up space with the video files. I'm trying to carve a niche out, but for now the short term is a way to create something different than my finance job. I'm assuming storing the data on something other than the client is the best way to do it. Right now it's a USB Stick, but that's not sustainable and risky. Thanks!

Thread Thread
 
harsh2644 profile image
Harsh

Thank you so much! Your kind words just made my day. It's great to hear that I can help you out, just like your friend does.

Your plan is moving in the right direction:

Short-term Strategy (openSUSE server):
Backing up your client machine to openSUSE is a fantastic start. You can use a couple of simple methods for this:

Set up a Samba share: Create a folder on openSUSE and share it over the network using Samba. Then, from your main machine (likely MX Linux), you can access that folder and copy your files over. This is way better and safer than using a USB stick.

Use Rsync: This is a command-line tool that copies only the files that have changed, making backups fast and efficient. You can even automate it to run at specific times using a cron job.

Your decision to move away from the USB stick is spot on—it's okay for temporary transfers, but for long-term storage, it's a big data loss risk.

Long-term Strategy (Synology RAID):
Your friend is awesome for giving you a Synology RAID! This will be absolutely perfect for your video projects.

Synology NAS devices are generally very user-friendly and come with their own operating system (DSM) that you manage through a web browser.

They have built-in backup solutions and can serve as a central storage hub for your website/YouTube videos.

Your Main Goal:
Duplicate the data so that if something goes wrong, I can salvage some of it this is exactly the right mindset. You should always keep your data in at least two places. Storing data on a separate device (like the openSUSE machine or the Synology) is the best practice.

It's truly inspiring that you're pursuing creative work and building your own niche alongside your finance job. Best of luck with your video editing and content creation!

Saving notes in Joplin is a very smart move for "loss prevention." Whenever you're ready to share the details of the RAID, I'll be here to help you further. Until then, all the best with your work