[{"data":1,"prerenderedAt":381},["ShallowReactive",2],{"blog-\u002Fblogs\u002Fwidget-library-dsl":3},{"id":4,"title":5,"author":6,"body":7,"date":372,"description":373,"extension":374,"meta":375,"navigation":376,"path":377,"seo":378,"stem":379,"__hash__":380},"content\u002Fblogs\u002Fwidget-library-dsl.md","A widget library as a DSL","James Orson",{"type":8,"value":9,"toc":358},"minimark",[10,22,25,30,33,46,49,52,67,70,73,76,80,83,86,92,95,99,102,120,123,126,133,141,144,153,156,162,165,194,198,205,239,247,251,254,257,261,272,279,290,297,301,324,328,331,334,337,340,343,350],[11,12,13,14,21],"p",{},"Hello friends! This is the fourth post in our series on how ",[15,16,20],"a",{"href":17,"rel":18},"https:\u002F\u002Fquark.autobutler.org",[19],"nofollow","Quark"," gets built by AI\nagents. In the first post I said the frontend was the exception, and that the agents screwed up frontend changes often\nuntil we built a widget library. So now you will learn what I meant with regards to the library.",[11,23,24],{},"If you don't like vibe coded UIs (myself included), this is the post I most want you to read.",[26,27,29],"h2",{"id":28},"wrong-and-bad","Wrong and bad",[11,31,32],{},"The backend responded well to automated rules and static analysis.",[34,35,36,40,43],"ul",{},[37,38,39],"li",{},"Tell an agent that SQL only goes through sqlc",[37,41,42],{},"Tell an agent that file access only goes through our vfs layer",[37,44,45],{},"Back those prose rules with linters and a script that asserts project structure",[11,47,48],{},"Sadly, the frontend does not work that way, as it matters how it looks to a human.",[11,50,51],{},"Some things that were \"wrong and bad\" in our initial Flutter implementation:",[53,54,55,58,61,64],"ol",{},[37,56,57],{},"inconsistent and broken layouts",[37,59,60],{},"inconsistent styling between screens, including basic things like the color pallette",[37,62,63],{},"many...many...many overflow bugs, which in Flutter will flood your console with warnings as you work on the app",[37,65,66],{},"small style changes to a component meant scanning and editing the whole codebase because it was a component in name alone",[11,68,69],{},"That fourth item though was the root of evil. Nothing was properly componentized, and therefore the agent would always\nassume a fix in one spot was a fix for the whole application.",[11,71,72],{},"How could the agent maintain a consistent design look and feel if the code was distributed all over the codebase?",[11,74,75],{},"How could the agent be confident that the change it was making was not going to break the whole layout of the page?",[26,77,79],{"id":78},"we-had-tests-just-not-the-right-ones","We had tests, just not the right ones",[11,81,82],{},"When I first described this, I said we had no frontend tests before the widget library. That was not quite\nright, but was functionally true. The tests we had only covered application logic. Nothing about layout, user flows, verifying\ncomponent visibility on a page, etc.",[11,84,85],{},"This fits a pattern we have been following on purpose:",[87,88,89],"blockquote",{},[11,90,91],{},"The first really early versions of our apps go out untested, then we later come back and encode our expectations in tests\nbefore we make it generally available, and then we strictly enforce testing moving forward. That way we avoid early churn\nin our testing while we trial new features and ideas.",[11,93,94],{},"The frontend had just gone through a rewrite from Vue into Flutter, so it was still in the fast, untested stage. The backend\nwent through the same arc: no tests at all for its first year of life, plus some change.\nThe widget library was part of us asserting that we wanted to consider the frontend \"mature\" and settle on our design. Settling\non a design did not necessarily mean it would be \"pretty\" just yet, but it had to stay functional and allow us to test the\nviability of our coming features.",[26,96,98],{"id":97},"what-the-library-changed","What the library changed",[11,100,101],{},"So, I cracked my knuckles, and got to prompting!",[11,103,104,105,110,111,119],{},"I had the agents trawl the codebase for shared functionality, and create a catalog of what were the widgets to be pulled\nout into a ",[15,106,109],{"href":107,"rel":108},"https:\u002F\u002Fwww.uxpin.com\u002Fstudio\u002Fblog\u002Fui-component-library\u002F",[19],"component library",", which we will call a \"widget library\"\ndue to Flutter's chosen nomenclature of \"widget\" over \"component\". Once that initial catalog was created, the agent created\na package called ",[15,112,115],{"href":113,"rel":114},"https:\u002F\u002Fgithub.com\u002Fautobutler-org\u002Fquark\u002Ftree\u002Ff2d69bb7f988f9442cdcb2a0f84e851ebd963850\u002Fpackages\u002Fquark_widgets",[19],[116,117,118],"code",{},"quark_widgets",".",[11,121,122],{},"Importantly, the widget package is not just the widget code, but it also contained a suite of tests to assert expected behaviors\nof all of the widgets.",[11,124,125],{},"Most importantly, the widget library came with a runnable \"gallery\" which allows you to browse every available widget, along\nwith the documentation, and some theme pickers to allow you to play with different color pallettes. This is pretty standard\nfor more mature component libraries, but provided a great way for myself and the agents to verify that the widget was sensible\non its own.",[11,127,128],{},[129,130],"img",{"alt":131,"src":132},"Widget gallery","\u002Fblogs\u002Fwidget-library-dsl\u002Fwidget-gallery.png",[11,134,135,136],{},"This practice of creating your own component library has been pretty standards for a while now for UI developers, but in\nthe agentic era it provides another benefit: ",[15,137,140],{"href":138,"rel":139},"https:\u002F\u002Fmartinfowler.com\u002Fdsl.html",[19],"a Domain Specific Language (DSL)",[11,142,143],{},"An internal DSL in this case. See, when an agent is working on something like Vue or Flutter, they have the specific tags\nor widgets of that framework to construct the UI with, but these are super generalized components with loads of hooks and\nextensions that can both flood the agent's context and do not guide the agent to what you specifically need for your app.",[11,145,146,147,152],{},"Again, humans have suffered from the same fate when working with these frameworks in the past. Hence, why developers would\noften reach for something like the ",[15,148,151],{"href":149,"rel":150},"https:\u002F\u002Fm3.material.io\u002F",[19],"Material Design Library from Google",".\nThis provided you a set of fully constructed components that were guaranteed to function for you, made up of those small\ntag primitives, with expected behaviors, and a consistent look and feel that would behave properly in a common layout. An\napp's code that was written with Material Design in mind looks dramatically different from one using the primitives they\nare built from, but was also generally more concise and easier to understand.",[11,154,155],{},"So by doing the same thing with Flutter widgets, we have given the agent the same benefits. That design library makes it\nmore concise and easy to understand what UI tools are available for it to build with, while also front-loading that context\nfor the agent by having it in-repo. Now the agent can know, by default, that new UI elements and layouts need to be written\nas a library, but only if an existing widget does not satisfy the use case.",[11,157,158,159,161],{},"So, instead of using Flutter's widget primitives as the language of the UI, the agent uses ",[116,160,118],{}," as the language\nof the UI, only reaching for Flutter's layout primitives occasionally to piece the widgets together. On top of that, the\nwidgets are all stateless by default. They do not make API calls themselves, but simply accept data in to render, and provide\nhooks for the actions that can be taken with them. This appropriately separates the business logic from the rendering of\nour application, across the entire website.",[11,163,164],{},"To summarize the benefits:",[34,166,167,170,173,176,179,182,185,188,191],{},[37,168,169],{},"The agent now has a small vocabulary to work from.",[37,171,172],{},"A browseable gallery makes the widgets discoverable by humans and agents alike.",[37,174,175],{},"The agent now has standardized layout examples in the widget gallery.",[37,177,178],{},"Every widget in the package is tested in isolation.",[37,180,181],{},"Every widget can now be rendered and tested without the corresponding business logic.",[37,183,184],{},"Page-level context shrinks because the details live inside the components.",[37,186,187],{},"A screen's code gets short enough that a human can feasibly read it, and short enough that the agent can read it without.\nburning loads of context.",[37,189,190],{},"A style change for a widget that is present across the whole app is now an update to one code location.",[37,192,193],{},"Unused widgets become obvious now that you can cross-check the library with the application code.",[26,195,197],{"id":196},"the-rules-that-make-it-a-language","The rules that make it a language",[11,199,200,201,204],{},"A vocabulary alone isn't a language though, for you also need grammar, and ours lives in ",[116,202,203],{},"AGENTS.md",":",[34,206,207,210,213,220,223,230,233,236],{},[37,208,209],{},"One widget class per file.",[37,211,212],{},"No private widgets, even if a widget is only used once.",[37,214,215,216,219],{},"No ",[116,217,218],{},"Widget _build*()"," helper methods.",[37,221,222],{},"Package widgets are data in, callbacks out.",[37,224,225,226,229],{},"A page's domain state lives in a ChangeNotifier controller under ",[116,227,228],{},"lib\u002Fcontrollers\u002F",", and every service call goes through\nit. Fat pages and service-coupled widgets that haven't been migrated yet are not violations.",[37,231,232],{},"Colors come from QuarkTokens through the theme. Top-bar icons come from QuarkIcons, never Icons.",[37,234,235],{},"Pages are compositions: no sizing math, no breakpoints, and no LayoutBuilder branching in a page.",[37,237,238],{},"Every package widget gets a gallery registry entry and a regenerated docs.g.dart. Layout tests run at narrow and wide\nviewports, and callback or state tests run once.",[11,240,241,242,119],{},"The initial rules and the agent definitions landed on 2026-09-04 in\n",[15,243,246],{"href":244,"rel":245},"https:\u002F\u002Fgithub.com\u002Fautobutler-org\u002Fquark\u002Fpull\u002F1733",[19],"PR #1733",[26,248,250],{"id":249},"one-massive-pr-on-purpose","One massive PR, on purpose",[11,252,253],{},"Everywhere else in this series you'll see us push for small, stacked PRs. The migration was the exception. We moved\nall of the existing pages in one massive PR, including all the tests.",[11,255,256],{},"Then I went through the whole app as a human and tested everything by hand. That's still my rule today: if a change is\nvisual, I run it and look before approving. Otherwise I generally don't read the code anymore.",[26,258,260],{"id":259},"agents-reviewing-agents","Agents reviewing agents",[11,262,263,264,267,268,271],{},"We wrote two agent definitions for this, not one: ",[116,265,266],{},".claude\u002Fagents\u002Fwidget-engineer.md"," writes widgets, and\n",[116,269,270],{},".claude\u002Fagents\u002Fwidget-reviewer.md"," checks them. The engineer applies the reviewer's checklist to its own work before it\nopens a PR.",[11,273,274,275,278],{},"The reviewer has earned its keep. In one session it flagged a test where a drawer tap at ",[116,276,277],{},"360×640"," landed \"roughly 3px\"\ninside the screen, and noted that \"one more row will break it.\"",[11,280,281,282,285,286,289],{},"It also missed something a person did catch. After the widget move passed the reviewer's checklist, I asked: \"So I am\nasking because I want the quark_widgets package to be used by the main application. Are we using it AT ALL?\" It turned\nout ",[116,283,284],{},"LiveBadge"," had been copied into the package, but neither original was deleted and no call site was switched. And\n",[116,287,288],{},"FileActionsBar"," was dead code that got moved anyway. We fixed the code, and then we fixed the reviewer subagent's instructions.",[11,291,292,293,296],{},"One more, because it shows the library's failure mode. A commit \"fixed\" the breadcrumb home glyph in the package's\n",[116,294,295],{},"FileBreadcrumbBar",", but the Files page doesn't use that widget. I told it: \"The home is clearly still tappable when I\nam at the root, and provides a cursor: pointer to me on web.\" The fix went into the widget the page actually renders,\nwith a regression test. A library only helps if the pages use it, which is why the zero-callers rule matters.",[26,298,300],{"id":299},"copy-this","Copy this",[34,302,303,306,309,312,315,321],{},[37,304,305],{},"Put your design system in its own package, with data passed in, and all the necessary hooks\u002Fcallbacks.",[37,307,308],{},"Give yourself and your agents a browseable gallery with a generated registry.",[37,310,311],{},"Test every component at a narrow and a wide viewport. Our first batch of narrow tests found multiple overflow bugs.",[37,313,314],{},"Write subagents for component work, an engineer and a reviewer at least, and have the engineer run the reviewer's checklist\non its own work before it opens a PR.",[37,316,317,318,119],{},"Ship package-level skills inside the package. Ours live in ",[116,319,320],{},"packages\u002Fquark_widgets\u002Fskills\u002F",[37,322,323],{},"After any move, grep for callers. Zero callers is a finding and says either the app is still writing its own components\ninline or the component in the library is dead code.",[26,325,327],{"id":326},"whats-next","What's next",[11,329,330],{},"The next post, \"Three tabs,\nthree clones, a pile of worktrees\", is about what parallel agent work looks like on one laptop, and what it costs.",[11,332,333],{},"As always, we love you all and we want to build stuff for you. Feel free to reach out anytime.",[11,335,336],{},"Grace and peace,\nJames",[338,339],"hr",{},[11,341,342],{},"This is part 4 of 8 in our series on how we build Quark with AI agents.",[11,344,345,346],{},"← Previous: ",[15,347,349],{"href":348},"\u002Fblogs\u002Fzero-approvals","Zero approvals, a wall of checks",[11,351,352,353,357],{},"Next: ",[15,354,356],{"href":355},"\u002Fblogs\u002Fthree-tabs-three-clones","Three tabs, three clones, a pile of worktrees"," →",{"title":359,"searchDepth":360,"depth":361,"links":362},"",6,5,[363,365,366,367,368,369,370,371],{"id":28,"depth":364,"text":29},2,{"id":78,"depth":364,"text":79},{"id":97,"depth":364,"text":98},{"id":196,"depth":364,"text":197},{"id":249,"depth":364,"text":250},{"id":259,"depth":364,"text":260},{"id":299,"depth":364,"text":300},{"id":326,"depth":364,"text":327},"2026-11-10","Our agents kept shipping ugly, with broken Flutter screens, until we shrank the vocabulary they write into a tested set of widgets.","md",{},true,"\u002Fblogs\u002Fwidget-library-dsl",{"title":5,"description":373},"blogs\u002Fwidget-library-dsl","mDBmUymRZd0wM4kSO8MbD61btHpzsJki1wn5Y0jKB-c",1794533415512]