🍡 mochi

SSR framework for Svelte 5 + Bun with islands-based selective hydration

On this page

Why Bun?

Mochi was built to be performant and simple. We do this by “outsourcing” subsystem complexity to the Bun runtime. Instead of writing or managing a bundler, an HTML parser, a router, database drivers, compression, and hashing as separate npm packages, the framework delegates to Bun’s standard library. Bun maintains those components; Mochi just calls them.

Mochi is backed by just ~10 runtime dependencies. We don’t minimize dependencies for the sake of it — external depenendencies are fine when they earn their place and genuinely improve the developer experience. The point is to use Buns extensive standard library and provide an opinionated toolkit that makes it possible to build complex web apps with “batteries included” out of the box.

What does Mochi actually use from Bun?

  • Bun.build() and Bun.Transpiler — Mochi’s bundler. Replaces Vite and other build tools.
  • Bun.plugin() — backs the virtual mochi module (isServer, isBrowser, isDev) injected at build time. Replaces @rollup/plugin-virtual or a custom esbuild plugin.
  • HTMLRewriter — Mochi uses it for islands discovery and HTML rewriting. Replaces htmlparser2, cheerio, and similar libraries.
  • Bun.serve() — backs the HTTP and WebSocket server in Mochi.serve(). Replaces express, fastify, or hono.
  • Bun.Glob — discovers routes, docs, and raw CSS files. Replaces fast-glob or globby.
  • Bun.deflateSync / Bun.inflateSync — pack encrypted server-island prop payloads into URLs. Replaces node:zlib.
  • bun:sqlite and bun:sql — zero-dep SQLite and PostgreSQL for app data. Replaces better-sqlite3 and pg.
  • bun:test — runs Mochi’s own test suite, with per-file process isolation. Replaces Vitest or Jest.
  • Native .ts execution and auto-loaded .env — TypeScript runs directly under bun run. Replaces ts-node and dotenv.

Batteries included

Leaning on Bun’s standard library is what lets Mochi ship so much out of the box. Here’s how that batteries-included surface compares to SvelteKit:

FeatureMochiSvelteKit
Server islands & selective hydration Yes - mochi:defer No - full page hydration only
Built-in SQLite database Yes - bun:sqlite Partial - node:sqlite via adapter-node on Node or Deno
Built-in Postgres & MySQL support Yes - Bun.sql() No - bring your own cloud database
Background job queues Yes - Mochi.queue() No
Minimal client-side JavaScript Yes - zero JS unless hydrated; tuned for first load Partial - tuned for repeat navigations; no zero-JS pages (CSR opt-out breaks interactivity)
Deployment targets No - Bun only Yes - Node, Vercel, Bun and other cloud providers
Prerendering / SSG Partial - route warmup supported Yes
Build as static HTML No - SSR only Yes - adapter-static
Form actions + progressively enhanced forms Yes Yes
Form captcha Yes - MochiCaptcha No - third-party service
Rate limiting Yes No - third-party package only
Middleware Yes Yes
Hooks & extension filters Yes - eventHooks & filters No
Top-level await Yes Partial - experimental
Real-time WebSockets Yes - Mochi.ws() No - custom server with external package
Server-Sent Events Yes - Mochi.sse() No - manual setup, limited provider support
Built-in caching library Yes - MochiCache No
Cookie helpers Yes Yes
AI development support Yes - Skill, MCP & llms.txt Yes - Skill, MCP & llms.txt
Client-side router No Yes
Type-safe routes & params Planned Yes - generated ./$types & $app/types
Remote functions (type-safe RPC) No Yes - experimental
View Transitions Yes - built-in component Partial - manual wiring
Highly interactive apps Yes - WS, SSE & View Transitions Yes - SPA mode & remote functions
Tailwind Yes - Tailwind v4 Yes
Built-in Markdown (mdsvex) Yes - mdsvex built-in Yes - via integration (sv add mdsvex)
Centralized logging system Yes - mochiEvents No - experimental OpenTelemetry only
Image resizing Yes - named sizes, runtime transforms Partial - build-time only; runtime at extra cost
Link preloading Planned Yes
Service worker integration Planned Yes
Snapshots Partial - browser-native restoration Yes - manual setup

On the horizon

As Bun gets new features, we get new abilities to extend Mochi — for example Bun.Image() for on-the-fly image resizing (like next/image without pulling in sharp).