| 1 |
--- |
| 2 |
title: "A Real World wasm to htmx Port" |
| 3 |
description: "In this article, Joe Fioti describes their journey of simplifying their web application architecture by moving from a complex WebAssembly-based system to a streamlined htmx solution, resulting in significantly reduced code complexity and improved development efficiency." |
| 4 |
created: 2025-01-10 |
| 5 |
modified: 2025-01-10 |
| 6 |
authors: ["Joe Fioti"] |
| 7 |
tags: ["case-studies"] |
| 8 |
--- |
| 9 |
|
| 10 |
import { Image } from 'astro:assets'; |
| 11 |
import sidekickPortLoc from '../../assets/img/sidekick-port-loc.jpg'; |
| 12 |
|
| 13 |
When I was in college, I wrote some customer service software that tied together some custom AI models I trained, the |
| 14 |
OpenAI API, a database, and some social media APIs to make the first version of [Sidekick](https://sidekickai.co). |
| 15 |
|
| 16 |
## Led astray |
| 17 |
|
| 18 |
Over the next couple years I worked on adding more features and growing the user base. As a solo founder, I should have |
| 19 |
been focused on sales, marketing, and market discovery. Instead, as an engineer, I wanted to hand-craft the perfect web |
| 20 |
stack. I was firmly of the belief that the network gap between the frontend and the backend could be abstracted away, |
| 21 |
and I could make writing web apps as simple as writing native apps. Did this have anything to do with my business, |
| 22 |
product, or customers? Absolutely not, but as many technical founders do, I believed if I perfected the tech, the |
| 23 |
customers would materialize. |
| 24 |
|
| 25 |
My design decisions were naive, but also reminiscent to what's seen in industry today: I wanted the backend and frontend |
| 26 |
to share a language (Rust), I wanted compile-time checks across the network boundary, I wanted to write frontend code |
| 27 |
like it was an app (reactive), and I wanted nearly instant reload times. What I got out of it was a buggy mess. |
| 28 |
|
| 29 |
I had invented a system where simple rust functions can be tagged with a macro to generate a backend route and a |
| 30 |
frontend request function, so you can call the function like it was a standard function, and it would run on the |
| 31 |
backend. A true poor-mans GraphQL. My desire to write Rust on the frontend required I compile a WASM bundle. My desire |
| 32 |
for instant load times required isomorphic SSR. All of this complexity, for what was essentially a simple CRUD site. |
| 33 |
|
| 34 |
## A better way |
| 35 |
|
| 36 |
At this point Sidekick has grown and it now has a codebase which is responsible for not-insignificant volumes of traffic |
| 37 |
each day. There was this point where I looked into HTMX, multi-page websites, and HATEOAS, and realized the Sidekick |
| 38 |
codebase, which had grown into ~36k lines spread over 8 different crates, could be folded into a single crate, a single |
| 39 |
binary that ran the backend, which generated the frontend on demand through templating, and that HTMX could suffice for |
| 40 |
all the interactivity we required. |
| 41 |
|
| 42 |
Large refactors typically have a bad track record so we wrote a quick and dirty simplified version of part of the site |
| 43 |
to convince ourselves it could work. After sufficient convincing, we undertook a full rewrite. All said and done, the |
| 44 |
rewrite took approximately 3 weeks of intense work. The results were dramatic: |
| 45 |
|
| 46 |
- **36k LOC -> 8k LOC** |
| 47 |
- **8 crates -> 1 crate** |
| 48 |
- **~5 bug reports / week -> ~1 bug report / week** |
| 49 |
- **More full nights of sleep** |
| 50 |
|
| 51 |
<Image src={sidekickPortLoc} alt="sidekick port lines of code comparison" /> |
| 52 |
|
| 53 |
The rewrite went far better than I could have imagined. It definitely won't be representative of every experience, our |
| 54 |
app was definitely uniquely suited to HTMX. Axum and some custom middleware also went a long way for sharing common |
| 55 |
infrastructure across the site. Though we don't have proper metrics, we've anecdotally noticed significantly improved |
| 56 |
load times. |
| 57 |
|
| 58 |
## Reflection |
| 59 |
|
| 60 |
I'll finish by touching on the biggest benefit in my eyes: it's tremendously easier to add new features as our customers |
| 61 |
request them. A feature that would have taken 2 weeks to fully implement, test and ship, now takes a day or two. As a |
| 62 |
small startup with a large number of customer demands, this is table stakes. |
| 63 |
|
| 64 |
Sidekick hasn't raised VC funding so I can't afford to hire lots of devs. With HTMX we don't need to. |