<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gagandeep </title>
    <description>The latest articles on DEV Community by Gagandeep  (@gagan_builds).</description>
    <link>https://dev.to/gagan_builds</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4041657%2F73ad9d7e-339e-41ee-b4ac-ce60499e4b3f.png</url>
      <title>DEV Community: Gagandeep </title>
      <link>https://dev.to/gagan_builds</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gagan_builds"/>
    <language>en</language>
    <item>
      <title>Stop Cursor AI From Writing Broken Code</title>
      <dc:creator>Gagandeep </dc:creator>
      <pubDate>Thu, 23 Jul 2026 06:00:42 +0000</pubDate>
      <link>https://dev.to/gagan_builds/stop-cursor-ai-from-writing-broken-code-1h0d</link>
      <guid>https://dev.to/gagan_builds/stop-cursor-ai-from-writing-broken-code-1h0d</guid>
      <description>&lt;p&gt;If you've spent more than a few hours building apps with Cursor or Replit AI, you've probably seen this happen.&lt;/p&gt;

&lt;p&gt;You ask the AI to build a feature.&lt;/p&gt;

&lt;p&gt;Instead, it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates files in random places.&lt;/li&gt;
&lt;li&gt;Rewrites code that was already working.&lt;/li&gt;
&lt;li&gt;Hallucinates imports.&lt;/li&gt;
&lt;li&gt;Keeps fixing one error only to create three more.&lt;/li&gt;
&lt;li&gt;Gets trapped in an endless "I fixed it" → "New error" loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sound familiar?&lt;/p&gt;

&lt;p&gt;You're not alone.&lt;/p&gt;

&lt;p&gt;The biggest mistake most developers make isn't using Cursor. It's asking Cursor to code before giving it a proper architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Problem Isn't Cursor
&lt;/h2&gt;

&lt;p&gt;Cursor is incredibly good at writing code.&lt;br&gt;
But it's terrible at guessing your project structure.&lt;/p&gt;

&lt;p&gt;When the AI doesn't know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the tech stack,&lt;/li&gt;
&lt;li&gt;folder organization,&lt;/li&gt;
&lt;li&gt;database design,&lt;/li&gt;
&lt;li&gt;coding standards,&lt;/li&gt;
&lt;li&gt;or implementation order,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;it starts making assumptions.&lt;/p&gt;

&lt;p&gt;Those assumptions become:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;duplicate components,&lt;/li&gt;
&lt;li&gt;inconsistent APIs,&lt;/li&gt;
&lt;li&gt;broken imports,&lt;/li&gt;
&lt;li&gt;conflicting state management,&lt;/li&gt;
&lt;li&gt;endless refactors,&lt;/li&gt;
&lt;li&gt;and eventually an agent that keeps chasing its own mistakes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why people think Cursor is "hallucinating."&lt;/p&gt;

&lt;p&gt;Most of the time, it's simply missing context.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Core Realization
&lt;/h2&gt;

&lt;p&gt;Think of Cursor as a junior software engineer.&lt;/p&gt;

&lt;p&gt;Would you tell a junior developer:&lt;/p&gt;

&lt;p&gt;"Go build my entire SaaS app."&lt;/p&gt;

&lt;p&gt;Of course not.&lt;/p&gt;

&lt;p&gt;You'd first provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Architecture&lt;/li&gt;
&lt;li&gt;Requirements&lt;/li&gt;
&lt;li&gt;Folder structure&lt;/li&gt;
&lt;li&gt;Database design&lt;/li&gt;
&lt;li&gt;Development plan&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only then would they start coding.&lt;/p&gt;

&lt;p&gt;AI code builders work exactly the same way.&lt;/p&gt;

&lt;p&gt;They perform dramatically better when they're given a complete system architecture before generating a single file.&lt;/p&gt;

&lt;p&gt;That one change eliminates a surprising number of AI-generated bugs.&lt;/p&gt;
&lt;h2&gt;
  
  
  The 3-Step Workflow That Changed Everything
&lt;/h2&gt;

&lt;p&gt;Instead of asking Cursor to "build the app," break the process into three phases.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1 — Define the Tech Stack and Database Schema
&lt;/h3&gt;

&lt;p&gt;Before writing any code, document the foundation.&lt;/p&gt;

&lt;p&gt;Include things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend framework&lt;/li&gt;
&lt;li&gt;Backend framework&lt;/li&gt;
&lt;li&gt;Database&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;State management&lt;/li&gt;
&lt;li&gt;API style&lt;/li&gt;
&lt;li&gt;Deployment target&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Frontend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Next.js&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;TypeScript&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Tailwind CSS&lt;/span&gt;

&lt;span class="na"&gt;Backend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Node.js&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Express&lt;/span&gt;

&lt;span class="na"&gt;Database&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PostgreSQL&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Prisma ORM&lt;/span&gt;

&lt;span class="na"&gt;Authentication&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Clerk&lt;/span&gt;

&lt;span class="na"&gt;Hosting&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Vercel&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then define your database schema.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users
- id
- email
- password_hash
- created_at

Projects
- id
- user_id
- title
- created_at

Tasks
- id
- project_id
- title
- completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Cursor understands what data exists before it starts inventing tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 — Design the Directory Structure
&lt;/h3&gt;

&lt;p&gt;This step is skipped surprisingly often.&lt;/p&gt;

&lt;p&gt;That's exactly why AI starts dumping files into the root directory.&lt;/p&gt;

&lt;p&gt;Instead, define the project layout first.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;src/&lt;/span&gt;
&lt;span class="s"&gt;├──components/&lt;/span&gt;
&lt;span class="s"&gt;├──pages/&lt;/span&gt;
&lt;span class="s"&gt;├──hooks/&lt;/span&gt;
&lt;span class="s"&gt;├──services/&lt;/span&gt;
&lt;span class="s"&gt;├──lib/&lt;/span&gt;
&lt;span class="s"&gt;├──utils/&lt;/span&gt;
&lt;span class="s"&gt;├──types/&lt;/span&gt;
&lt;span class="s"&gt;├──styles/&lt;/span&gt;
&lt;span class="s"&gt;├──database/&lt;/span&gt;
&lt;span class="s"&gt;├──prisma/&lt;/span&gt;
&lt;span class="s"&gt;├──api/&lt;/span&gt;
&lt;span class="s"&gt;├──tests/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also define rules such as:&lt;/p&gt;

&lt;p&gt;Shared components belong in components/ &lt;br&gt;
API logic stays inside services/&lt;br&gt;
Database code only lives in database/&lt;br&gt;
Utility functions stay inside utils/&lt;/p&gt;

&lt;p&gt;This removes a huge amount of ambiguity.&lt;/p&gt;

&lt;p&gt;The AI no longer has to guess where new files belong.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 — Build Using a Phased Prompt Sequence
&lt;/h3&gt;

&lt;p&gt;This is the biggest improvement you can make.&lt;/p&gt;

&lt;p&gt;Never ask Cursor to build everything at once.&lt;/p&gt;

&lt;p&gt;Instead, split development into separate prompts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 1 — Build the UI
&lt;/h3&gt;

&lt;p&gt;Prompt only for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pages&lt;/li&gt;
&lt;li&gt;layouts&lt;/li&gt;
&lt;li&gt;reusable components&lt;/li&gt;
&lt;li&gt;navigation&lt;/li&gt;
&lt;li&gt;styling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't mention authentication.&lt;/p&gt;

&lt;p&gt;Don't mention APIs.&lt;/p&gt;

&lt;p&gt;Don't mention databases.&lt;/p&gt;

&lt;p&gt;Just the interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 2 — Add Authentication and Database
&lt;/h3&gt;

&lt;p&gt;Once the UI is complete, move to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;authentication&lt;/li&gt;
&lt;li&gt;database schema&lt;/li&gt;
&lt;li&gt;migrations&lt;/li&gt;
&lt;li&gt;API routes&lt;/li&gt;
&lt;li&gt;CRUD operations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the UI already exists, Cursor has a stable target to connect everything to.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 3 — Add Business Logic
&lt;/h3&gt;

&lt;p&gt;Only after the app structure is stable should you implement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;validation&lt;/li&gt;
&lt;li&gt;workflows&lt;/li&gt;
&lt;li&gt;automation&lt;/li&gt;
&lt;li&gt;permissions&lt;/li&gt;
&lt;li&gt;notifications&lt;/li&gt;
&lt;li&gt;background jobs&lt;/li&gt;
&lt;li&gt;AI integrations&lt;/li&gt;
&lt;li&gt;third-party APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each phase builds on the previous one.&lt;/p&gt;

&lt;p&gt;Nothing gets rewritten unnecessarily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why This Works
&lt;/h3&gt;

&lt;p&gt;Large Language Models have limited working memory.&lt;/p&gt;

&lt;p&gt;The more unrelated tasks you ask them to solve simultaneously, the more likely they are to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lose context,&lt;/li&gt;
&lt;li&gt;overwrite existing files,&lt;/li&gt;
&lt;li&gt;generate inconsistent code,&lt;/li&gt;
&lt;li&gt;or loop while trying to repair previous mistakes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Breaking development into clear phases reduces complexity.&lt;/p&gt;

&lt;p&gt;Instead of solving twenty problems at once, the AI solves one well-defined problem at a time.&lt;/p&gt;

&lt;p&gt;The result is cleaner code, fewer regressions, and a much smoother development experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Prompting Mistakes
&lt;/h3&gt;

&lt;p&gt;Avoid prompts like :&lt;/p&gt;

&lt;p&gt;Build a complete production-ready SaaS with authentication, payments, dashboard, admin panel, AI chat, Stripe, email verification, analytics, and deployment.&lt;/p&gt;

&lt;p&gt;That's too many responsibilities in one request.&lt;/p&gt;

&lt;p&gt;A better prompt is:&lt;/p&gt;

&lt;p&gt;Build only the dashboard UI using the provided architecture. Do not create authentication, APIs, or database code. Follow the directory structure exactly.&lt;/p&gt;

&lt;p&gt;The second prompt is far more constrained, which makes the output more reliable.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Simple Rule to Remember
&lt;/h3&gt;

&lt;p&gt;Don't ask AI to design and build at the same time.&lt;/p&gt;

&lt;p&gt;First, give it the blueprint.&lt;/p&gt;

&lt;p&gt;Then let it write the code.&lt;/p&gt;

&lt;p&gt;That small change can save hours of debugging and reduce the chances of Cursor getting stuck in repetitive fix loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Open-source GitHub Workflow: &lt;a href="https://github.com/Gagan0054/Cursor-Spec-Architect-Workflow" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Copy-paste Master Prompt Sequence: &lt;a href="https://promptbase.com/prompt-edit/8QuyMpzJVleev7g9tdUu" rel="noopener noreferrer"&gt;Get Full Prompt on PromptBase&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The PromptBase collection includes structured prompts designed to help Cursor, Replit Agent, Bolt.new, and similar AI coding tools generate cleaner, more maintainable projects with fewer architectural mistakes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;AI-assisted development is evolving quickly, but the fundamentals of software engineering haven't changed.&lt;/p&gt;

&lt;p&gt;Good architecture still comes before good code.&lt;/p&gt;

&lt;p&gt;The better your specifications, folder structure, and implementation plan, the better your AI-generated output will be.&lt;/p&gt;

&lt;p&gt;Cursor isn't failing because it's incapable.&lt;/p&gt;

&lt;p&gt;It's usually failing because it's being asked to improvise an entire software architecture while simultaneously writing the implementation.&lt;/p&gt;

&lt;p&gt;Give it a plan first.&lt;/p&gt;

&lt;p&gt;Then let it build.&lt;/p&gt;

&lt;h2&gt;
  
  
  Over to You
&lt;/h2&gt;

&lt;p&gt;How do you structure your Cursor or Replit workflow?&lt;/p&gt;

&lt;p&gt;Do you use architecture documents, phased prompts, or another system that keeps AI from going off the rails?&lt;/p&gt;

&lt;p&gt;Share your workflow in the comments—I'd love to see what has worked for you.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>cursor</category>
      <category>webdev</category>
      <category>replit</category>
    </item>
  </channel>
</rss>
