r/webdev • full-stack • 1d ago

Showoff Saturday I built MirageUI – a wireframe-to-code tool that uses geometric heuristics instead of LLMs for layout detection

Post image

I've been working on MirageUI with my team, and I wanted to share the project and some of the engineering behind it.

Live: https://mirageui.vercel.app/
Source: https://github.com/Veer1778/Mirage

The idea was to explore an alternative to prompt-based website generation.

Instead of describing a webpage to an AI, you draw a rough wireframe using rectangles, and the editor interprets the layout and generates frontend code.

How it works

The interesting part is the layout interpretation engine.

I deliberately avoided using an LLM for component recognition. Instead, Mirage uses geometric heuristics to infer what the user is trying to build.

It considers four main signals:

  1. Position: A full-width rectangle at the top is likely a navbar; the same rectangle at the bottom is likely a footer.
  2. Aspect ratio: Tall and narrow shapes can indicate rails, while wider shapes suggest horizontal sections.
  3. Spatial relationships: Multiple similarly sized rectangles sharing a row can indicate a card grid.
  4. Width and alignment: Elements snap to a 12-column grid before being interpreted.

One implementation decision I'm particularly happy with is storing sketches as integer grid coordinates rather than raw pixel positions.

Each box is represented using its column, row, width and height. This makes snapping, collision detection and layout calculations much more predictable.

Boxes that overlap vertically are grouped into horizontal bands, which are then translated into CSS grid layouts.

The editor also prevents overlapping boxes. When a drag is blocked, movement is retried along individual axes so elements can slide around obstacles.

Component detection

Mirage currently supports 19 component types, with nine detected automatically.

When the classifier isn't confident, it flags the element instead of silently guessing. Users can manually override classifications, and manually overridden elements aren't reclassified.

Code generation

The same sketch can be exported into three targets:

  • HTML: Semantic markup with a token-driven stylesheet.
  • React: Component-based output with props.
  • Tailwind: Utility classes with mobile-first breakpoints.

Sketches can also be saved and reloaded through a JSON format.

I kept styling separate from structure using design tokens. This means switching themes doesn't require changing the underlying markup.

Tech stack and architecture

One thing worth mentioning is that the entire application is built using:

  • Vanilla JavaScript
  • HTML
  • CSS
  • Vercel for deployment

There are no external dependencies, no build step and no backend. Everything runs in the browser as static files.

The repository is structured around separate editor, engine, theme and landing-page files.

What I learned

A few things I found interesting while building this:

  • Geometry alone can communicate a surprising amount of layout intent.
  • Using a consistent coordinate system simplifies several seemingly unrelated problems.
  • Automatic classification needs a manual override mechanism. You can't expect heuristics to understand every possible layout.
  • Generating valid code is one thing; generating code that developers would actually want to maintain is another.

This is still an evolving project, and I'd particularly appreciate feedback from people who have worked on frontend tooling, visual editors or code generation.

A few things I'd love opinions on:

  1. Would you approach component recognition differently?
  2. Are there better ways to handle ambiguous spatial relationships?
  3. What would make the generated React output more useful in a real development workflow?

Demo: https://mirageui.vercel.app/
GitHub: https://github.com/Veer1778/Mirage

It's MIT licensed and free to use. Would love to hear your thoughts!

0 Upvotes

14 comments sorted by

8

u/hollowgram 1d ago

Looks as generic and ai sloppy as all the other repos claiming to help make better designs. 

-2

u/Humble_Possibility42 full-stack 1d ago

I think there is a little misunderstanding on the intended use case. Mirage is not about taking an existing design and making it look better, though you can do that with it too. The idea is to be able to experiment with layout entirely new, to test different arrangements of components, to try out ideas and generate working frontend code without having to go through a lengthy design process each time. It’s more about making the experimentation loop as fast as possible, with extra features to keep the process structured and editable. Having said that, I agree the visual output could be improved.

2

u/Odd-Crazy-9056 1d ago

What does this resolve tho?

I can draw rectangles in Figma or create an image with rectangles in any image editor, throw it to Claude and get the same results. And that workflow does barely anything, aside from throwing shit at a wall and see what sticks.

1

u/Humble_Possibility42 full-stack 1d ago

I get the comparison, and Figma + Claude is definitely a valid way to approach this. But Mirage isn't just about identifying rectangles. It's also about having a structured visual editor with grid snapping, collision-aware positioning, component classification and overrides, multiple themes, persistent sketches, and exports to different frontend targets. The idea is to have the layout remain editable and structured throughout the process, rather than treating it as an image that needs to be interpreted again every time. I'm not claiming it replaces Figma or Claude, but I think there's room for a different workflow here. Still figuring out where it provides the most value

1

u/Odd-Crazy-9056 1d ago

This sounds to me like a very specific workflow that you vibe code for yourself as a personal tool. I don't see it resolving any problems.

2

u/Glittering-Ice2984 1d ago

No prompt required" is a nice line but the conf. 0.88 badge is doing a lot of work for a rule that's basically "wide box at top = nav". Microsoft's sketch2code and teleportHQ have been at this for years and the hard part was never detection, it was what happens when the box is 60% of a nav. Nineteen components with fixed thresholds will hold up on your own demos and fall apart on the first real whiteboard photo.

-2

u/Humble_Possibility42 full-stack 1d ago

Fair criticism. I'm aware of Sketch2Code and TeleportHQ, not claiming to have invented sketch-to-code. The 0.88 badge represents classifier confidence, not guaranteed accuracy. Fixed heuristics definitely have edge cases. What I'm exploring is a fast, structured prototyping workflow around detection, editing, snapping, overrides, themes and code export. Testing against messy, real-world sketches is definitely something I need to do more of.

1

u/Intrepid_Camp_2843 1d ago

Nice that you didn't just wrap a vision model and ship it. The "flags the box instead of guessing" part is the right instinct, but I'd log the overrides somewhere, otherwise you never learn which of those four signals keeps misfiring and you're just tuning thresholds by vibes.

1

u/Humble_Possibility42 full-stack 1d ago

That's a really good point. Currently overrides are mainly there to let users correct the output, but logging them as feedback would make it possible to identify which heuristics are consistently misfiring instead of blindly tweaking thresholds. Definitely something worth implementing.

1

u/jaffparker 1d ago • Bravo

Thanks a lot, I will explore it! I think it's important to have non-LLM tools in the AI era. We're forgetting about the simple solutions and I'm glad you're bringing some forward

1

u/Humble_Possibility42 full-stack 1d ago

Absolutely! I think there's a lot of value in exploring deterministic approaches alongside AI, rather than reaching for an LLM for everything. Appreciate you giving it a try!

1

u/Outrageous-Chip-3961 1d ago

Cant you just take a picture of your wireframes and put it into claude like the rest of us?

1

u/Humble_Possibility42 full-stack 1d ago

You can. That's not what Mirage is trying to solve. It works with editable, structured layout data, with snapping, component overrides, themes and direct code export. A screenshot-to-prompt workflow isn't the same thing.

1

u/Curious_Cicada5605 1d ago

Calling it "geometric heuristics" while the page describes a classifier that outputs conf. 0.88 is a bit of a stretch. Heuristics don't usually come with a confidence score.