coding standard guidelines
ai-assisted-development
software-architecture
development-best-practices
Here is the problem: You're #vibecoding with AI, things are humming along, and then BAM! 💥 The AI spits out code that's totally different from what it did yesterday. Or it duplicates stuff, or suddenly decides to try out a brand-new design pattern without asking. Super frustrating! 😡
🔥 Here's a killer trick I've found to keep things on track: take a little time to have the AI help you write some rules for your most important files.
Think about it – you probably have a handful of files that are the real MVPs of your project. Maybe you call them "Managers," "Controllers," "Coordinators," "Services," or even "Core Modules." Whatever the name, these are the files that pull the strings, connect the dots, and make sure everything runs smoothly.
For each of these VIP files, you'll create a rule file. This rule file will spell out its responsibilities, the design patterns it should follow, how it integrates with other parts of your code, naming conventions, and all that good stuff.
🤩 And here's the best part: you don't even have to write these rules yourself! The AI can do the heavy lifting, or you can snag a template you like. Easy peasy!
So, when should you get these rules down? You've got a couple of options:
If you're just diving into vibe-coding, I'd totally recommend option #2. Why? Because having some actual code already written makes it WAY easier to come up with smart rules. It's like trying to write a recipe – it's much simpler once you've actually cooked the dish a few times, right?
For example:
Let's say you're building an API in Python. You'll probably have a routes.py
file. You can ask the AI to whip up a rule that describes how that routes.py
file is structured and written. The AI will check out your existing file and describe it as a rule. That way, any new code added to routes.py
tomorrow will follow the same awesome standards. Consistency for the win! ✨
⚠️ Listen up, 'cause this is probably the second most important thing you can do when coding with AI (right after planning, of course!).
When should you pause and think about your rules? Keep an eye out for these moments – they're your cue to do a "rules audit":
/Generate Cursor Rules
, take a moment to double-check what the AI came up with.Okay, ready to make some rules? Here's how you do it:
/Generate Cursor Rules
(Your AI Helper!):
/Generate Cursor Rules
to get the AI to help you out. For example, you could prompt it with something like: "Generate a rule for how we handle WebSocket errors."websocket-handling.mdc
):
1## WebSocket Handling 2- Always include error handling and reconnection logic. 3- Here's an example:
1const socket = new WebSocket('ws://example.com'); 2 3socket.onerror = (error) => { 4 console.error('WebSocket error:', error); 5 // Don't forget to actually call your reconnect function! 6 attemptReconnect(); 7};
.cursor/rules/
directory in your project.naming-conventions.mdc
, api-endpoint-structure.mdc
).*.sql
) so Cursor automatically knows which rules apply to which files. Super handy!.mdc
rule files to git!README.md
file inside your .cursor/rules/
directory that explains what each rule file is for..mdc
files (e.g., using a Markdown linter)..cursor/rules/README.md
up-to-date. Include guidelines on how to update rules and best practices for using /Generate Cursor Rules
.Imagine you're adding a new chat feature to your app that uses WebSockets. Here's how you might use rules:
/Generate Cursor Rules
with a prompt like: "Generate a rule for WebSocket error handling in our new chat feature.".cursor/rules/chat-websocket-handling.mdc
..mdc
file to git. Make sure it gets reviewed in a pull request, just like any other code..cursor/rules/README.md
to let everyone know about this new rule and what it does.I only recommend this for very specific situations in which you are building something that you already know exactly how to build and you have built it before, for example: If you are building a simple REST API in a very similar way that you did it yesterday.
Here you will find a bunch of pre-written cursor rules that may work for that purpose.
If you are a software or marketing agency you will probably re-use lots of pre-made rules, and I strongly recommend doing so.
/Generate Cursor Rules
effectively and understands why these rules are important./Generate Cursor Rules
and refine the output, the better your prompts will become, and the better the AI will get at helping you!You've got this! By setting up these rules, you're well on your way to smoother, more consistent coding with your AI partner. Go crush it! 🚀