DEV Community

Rami_by
Rami_by

Posted on

I built a deterministic Spring Boot 3.5 Generator to fix AI Hallucinations

We all love coding. But let's be honest: the first 48 hours of a new Spring Boot project are painfully repetitive.

You set up the pom.xml, configure H2, write the same BaseEntity class, create the Controllers, generic services, and configure Swagger. It’s boring work.

So, we turn to AI. We ask ChatGPT or Cursor to "scaffold a backend." And it works... sort of.

The Problem: The "Vibe Coding" Trap AI is great at "vibes" (Frontend, CSS, simple logic). But when you ask an LLM to generate a complex database schema with bidirectional relationships (@OneToMany, @ManyToMany) and circular dependency handling, it often fails.

It hallucinates imports.

It misses the mappedBy parameter.

It generates code that looks right but doesn't compile.

I realized that LLMs are great for creativity, but terrible for structural rigor.

So I built a tool called ScaffoldAI to fix this.

The "Sandwich" Architecture 🥪
I decided to separate the workflow into three distinct layers, using the right tool for the job:

Layer 1: The Context (AI Power) 🧠 Before writing code, you need to know what you are building. I use AI here to act as a "Product Manager." You chat with it to generate a Lean Canvas and Pitch Deck. This isn't just fluffy business stuff—it acts as the "Context Window" for what follows.

Layer 2: The Structure (Visual Control) 📐 I didn't want the AI guessing my database schema blindly. I built a hybrid workflow:

  1. AI Suggestion: The AI analyzes your Lean Canvas and suggests the initial Entities and attributes.

  2. Manual Refinement: You take control. You can add, delete, or modify entities and define the relationships explicitly using a visual editor.

  3. Visualization: Finally, you get a static, auto-generated ERD Diagram to verify your entire architecture before a single line of code is written.

Layer 3: The Code (Deterministic Algorithms) ⚙️ This is the controversial part. I do not use LLMs to generate the final Java code. Once the ERD is validated, I use a deterministic engine to map that JSON structure into a compiling Spring Boot Proof-of-Concept (POC).

Because it's algorithmic:

  • It compiles 100% of the time.
  • No hallucinated annotations.
  • Core relationships are wired up correctly automatically.

The Stack
The generated output is a solid architectural foundation to build on:

Java 21

Spring Boot 3.5

H2 Database (configured for dev)

SpringDoc OpenAPI (Swagger UI)

Lombok & Jakarta Validation

Why "Validation First"?
I call this framework ScaffoldAI because, like in construction, you shouldn't pour concrete (write code) until you have scaffolding (validation) in place.

Too many of us build "ghost town" products. By forcing a Lean Canvas step before the Code Generation step, I'm trying to solve the #1 cause of startup failure: building the wrong thing.

Roast My Architecture 🔥
I’m currently in Public Beta. I’m looking for experienced Spring Boot developers to stress-test the generated code.

The goal isn't to replace your job—it's to give you a working, compiling POC in 30 seconds so you can skip the boilerplate and start coding the real business logic.

Does the architecture hold up?

Are the relationships handling the FetchType.LAZY correctly?

You can try it for free (no credit card) and export the code to your IDE.

👉 Try ScaffoldAI here: https://scaffoldai.io

Let me know in the comments if you think deterministic code gen is the future, or if LLMs will eventually solve the consistency problem.

Top comments (0)