r/webdev • u/Humble_Possibility42 full-stack • 1d ago
Showoff Saturday I built MirageUI – a wireframe-to-code tool that uses geometric heuristics instead of LLMs for layout detection
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:
- Position: A full-width rectangle at the top is likely a navbar; the same rectangle at the bottom is likely a footer.
- Aspect ratio: Tall and narrow shapes can indicate rails, while wider shapes suggest horizontal sections.
- Spatial relationships: Multiple similarly sized rectangles sharing a row can indicate a card grid.
- 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:
- Would you approach component recognition differently?
- Are there better ways to handle ambiguous spatial relationships?
- 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!
8
u/hollowgram 1d ago
Looks as generic and ai sloppy as all the other repos claiming to help make better designs.
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.
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.
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/jaffparker 1d ago •
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/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/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.