Image source : https://www.pexels.com/@ella-olsson-572949/

Organizing Your AI-Generated Code

For the Vibe Coder

6 min readFeb 26, 2025

--

AI coders like Cursor, Copilot, and/or your choice of LLM have and will continue to empower folks from all kinds of backgrounds to develop software — no matter their proficiency level, including zero! If you’re experienced and feel some apprehension, fear not — you are now capable of doing a team’s worth of coding by your lonesome, so everybody wins… in theory.

Writing working code and writing good, maintainable code are two different (and often subjective) things. If you add the current AI limitations — mostly script length, coverage, and hallucinations — organizing your AI-generated code makes even more sense. Without it, you can’t code past a certain point; it becomes a nightmare to maintain and expand, leading to more hallucinations, etc., etc.

VIBE CODING ?

In the strict sense, vibe coding is when you tell an AI to make a piece
of software and let it do the whole thing unattended—the result either
works or it doesn’t, and there’s not much to organize.

But most likely, you have some interest and experience in software
development and want to create code in an interactive way.
That is, you and the AI are more or less equal partners.
I believe this approach gets better results (for now), and it’s the
vibe coding I both practice and recommend—this short piece
is meant for that.

Organize Early

Since you generate code via prompts, there’s no reason you can’t request an organized file structure from the start. This does require you to understand and document what every part does, but you can also request a summary of everything, allowing you to automate organization to a certain extent.

Organize Late.

Most of the “oohs and aahs” demos of AI coders these days are single-script programs. While impressive, they can be challenging to maintain or expand. Yet, most of my projects start as a single-file script, and sometimes that’s okay. Organization can also be a second stage, along with refactoring, if needed.

Whatever Serves the Project Better.

Organizing is often a tradeoff between speed and efficiency. Sometimes, you need something fast to demo, patch, or validate an idea, and organizing can actually slow you down or be unnecessary. Other times — like with a shared codebase or a big project — organizing and documenting things is a prerequisite and a necessity. Current AIs might be too biased toward early organization, so just keep that in mind if you ask them when to organize.

When Organization is No Longer Optional.

A current limitation of AI coders is script length. I usually start seeing issues around the 200th line of a single script. Even if this gets solved, keeping all your code in a single file is not great. Breaking apart your code into multiple files can become the only way to proceed as your project grows.

Leverage Templates, Style Guides, Workspaces, and AIs

You’re probably not the first person to make an Android app, React website, or Python script. You can prompt your AI for pre-existing templates (look around on GitHub for something that serves your language or project), ask to use a specific style guide, utilize the project/workspace feature in your IDE (which allows your AI coder to consider the whole project rather than just a single file), and ultimately, get the AI to help you learn how to organize your code — every language has its own organizational specifics.

I kept the recommendations vague and general so you can use them regardless of your project, language, or skill level. But here’s a middle-of-the-road example I encountered recently that’s a bit more specific. It’s mostly Node/JS, but no worries if you come from a different language — or even if you don’t know any language.

The example is a small section of a bigger quant/finance research project. It’s a process called backtesting, where you come up with a trading or investing strategy and run it on past data to see its performance. Here’s the final local webpage:

The top section is a bunch of statistics and details about the strategy
The bottom section is a plot that shows how the strategy progressed against a benchmark and the individual trades partially shown.

A common issue when coding and organizing is that you don’t always know what the end product will look like. When I started this project, I only had a vague idea of the sections I would end up using. It began with just three files:

server.js Creates endpoints to query a postgress pricing database.

index.js All the logic goes here.

index.html An html entry point.

The earliest iterations included just the trading log and a few basic statistics, but as the statistics and page grew, the AI coder (Copilot on VS Code) started returning incorrect or partial code.

A side note/tip: Before every new prompt and after a successful code 
generation, make a copy and store it in a bak folder. That way, you
can revert to a working version if the AI gives you incorrect code.
Reverting from a repo is also valid, but sometimes it's more of a
hassle if you're working solo.

This is the final organization:

backtesting/
├── bak/
├── backtesting_modules/
│ ├── calculations.js
│ ├── display.js
│ ├── plots.js
│ ├── utils.js
│ └── strategies/
│ ├── buyAndHoldStrategy.js
│ └── weeklyStrategy.js
├── db_config.json
├── index.html
├── index.js
└── server.js

This organization requires you to understand both your project and how to structure things in your language of choice — in this case, JavaScript. Instead of keeping all the individual functions in the main file (index.js), you create a module for them and import them into your main file. For instance:

// This goes at the top of the index.js file:

import {
calculateReturns,
calculateBeta,
calculateVolatility,
calculateCAGR,
calculateSortinoRatio,
calculateMaxDrawdown
} from './backtesting_modules/calculations.js';

Benefits:

If you need more calculations, you can generate and test them in your main file, then later move them to calculations.js. The same applies to utilities, plots, displays, tables, etc. The code is now modular and easier to maintain.

Expanding functionality becomes simpler. For example, if you want to add a new strategy, you just create it and import it from the strategies folder.

Readability & delegation of responsibility — Most of these new files are under 100 lines, and since they only handle one type of functionality, it’s easy to find what you need. Want to tweak the calculation formula for annual volatility? Check calculations.js. Need to change the line color for a plot? That’s in plots.js. Plus, your AI coder will handle smaller files much more effectively.

Documentation — This helps remind your future self (or someone new to the project) what everything does. AIs already do a great job of including line-level comment explanations, but you can go a step further. Ask it to describe every file in your project, explain what it does, how to run it, and check for errors. Dump that into a readme.txt file, and Bob’s your uncle!

It’s a new dawn for software developers. You can produce thousands of lines of good code and multiple finished projects in just a few weeks. I say “produce” because you write very little — unless you count the prompts, which can be in the hundreds. While it’s possible that AI coders will improve their organizational skills or that we’ll all be replaced by an AI code viber, for now, this is one of the few areas where you (a human`) are still needed for the whole thing to work.

These are rapidly changing times. Maybe future coding AIs will become better at organization, but for now, I hope this helped you in some way. If something’s missing or you have other tips, please post them in the comments.

Also see here for more organizational specifics :

https://k3no.medium.com/organizing-your-python-code-ca5445843368

--

--

Keno Leon
Keno Leon

No responses yet