Splitting SvelteKit into a Monorepo
Why we moved from a SvelteKit monolith to an npm monorepo with Hono and Durable Objects on Cloudflare Workers.
When building modern full-stack web applications, the initial pitch of modern meta-frameworks like SvelteKit, Next.js, and Nuxt sounds like paradise:
One repo, one framework. Write your UI components, handle server-side rendering, define your API routes (
+server.ts), and manage database connections in one unified codebase.
And for standard CRUD apps, blogs, or internal dashboards, SvelteKit delivers on that promise better than almost anything else. With Svelte 5 runes and @sveltejs/adapter-cloudflare, you get blazingly fast full-stack edge deployments with near-zero latency.
Yet, as isitfun grew from a simple dashboard into a real-time game playtesting platform with telemetry ingestion, file uploads, and team workspaces, we hit a wall.
We ultimately dismantled our SvelteKit monolith and transitioned to a monorepo architecture:
apps/web: SvelteKit frontend (UI, SSR, client routing)apps/api: Dedicated Cloudflare Worker running Hono + Durable Objectspackages/db: Drizzle ORM schema, client, and migrationspackages/shared: Shared Valibot contracts, DTO types, and tier limits
Here is an honest breakdown of the constraints that forced our hand, how the architecture works, and the real trade-offs we accepted along the way.
The Constraints: Why SvelteKit Couldn’t Do It All
1. Cloudflare Workers Bundle Size and Cold Starts
When deploying SvelteKit to Cloudflare with @sveltejs/adapter-cloudflare, the entire application—every page component, SSR render tree, API endpoint, and third-party library—is bundled by Vite/esbuild into a single Worker script.
In our case, the backend needed:
- Better Auth with session management
- Drizzle ORM for Cloudflare D1
- Zip streaming and compression via
fflate - R2 multipart upload handling
- Creem billing checkout and webhook processors
Combining all of that server logic into the same bundle as the SvelteKit frontend SSR meant our worker bundle grew substantially. On Cloudflare Workers, larger bundles mean slower cold starts and risk colliding with the 1MB / 10MB worker script size ceilings.
2. Stateful Durable Objects & Real-Time Telemetry
isitfun captures real-time telemetry from game engines (Godot, Unity, WebGL). When playtesters try a game, the client connects over WebSockets to stream fps metrics, errors, and system events.
Cloudflare Durable Objects provide the perfect primitive for this: stateful edge actors that coordinate in-memory session queues and periodically flush compacted JSON to R2 buckets.
However, running custom Durable Object classes (TelemetrySessionDO) with alarm handlers, WebSocket hibernation, and export classes inside @sveltejs/adapter-cloudflare is awkward. SvelteKit’s request/response pipeline is fundamentally designed around stateless HTTP requests (Request -> Response), not long-lived actor lifecycles.
3. Traffic Segregation & Independent Scaling
Game engines and playtester clients don’t browse websites. They shoot HTTP POST telemetry beacons every few seconds or stream binary frames.
When both the public developer portal (https://isitfun.frstudios.co.ke/portal) and high-frequency game engine telemetry hit the same SvelteKit worker, any spike in telemetry traffic would contend for CPU time slices and request limits with the user dashboard.
Decoupling the API into an independent worker gives us isolated compute, dedicated log streams, and granular rate limiting.
The Monorepo Architecture
Our monorepo is organized using standard npm workspaces:
isitfun/
├── apps/
│ ├── web/ # SvelteKit 5 (UI, SSR, Auth hooks, Hono RPC client)
│ └── api/ # Cloudflare Worker (Hono, Durable Objects, D1, R2)
└── packages/
├── db/ # Drizzle schema (D1/SQLite), migrations, client
└── shared/ # Valibot schemas, TypeScript DTOs, tier limits End-to-End Type Safety Without Code Generation
The killer feature of this setup is Hono RPC. Instead of maintaining OpenAPI specs or generating client SDKs with heavy tooling, SvelteKit imports the backend router type directly:
// apps/web/src/lib/api/client.ts
import { hc } from 'hono/client';
import type { ApiRouter } from '@isitfun/api';
export function createApiClient(baseUrl: string, fetchFn: typeof fetch = fetch) {
return hc<ApiRouter>(baseUrl, { fetch: fetchFn });
} In SvelteKit’s +page.server.ts or remote functions:
// apps/web/src/routes/(app)/portal/dashboard/+page.server.ts
const client = createApiClient(apiBaseUrl, event.fetch);
const res = await client.v1.dashboard.$get({
headers: { cookie: event.request.headers.get('cookie') ?? '' }
});
if (!res.ok) throw error(res.status, 'Failed to load dashboard');
const data = await res.json(); // Fully typed response! The Trade-offs: The Good and the Bad
Every architectural decision is a trade-off. Splitting SvelteKit into a monorepo solved our technical bottlenecks, but it didn’t come for free.
The Advantages
- Zero SvelteKit Bloat: The frontend bundle only contains what SvelteKit actually needs to render the UI. SSR is instantaneous.
- Native Cloudflare Primitives: The API worker has a clean
wrangler.jsoncthat directly exports Durable Objects (TelemetrySessionDO), binds D1 and R2, and handles CORS effortlessly. - Independent Deployment Lifecycles: Backend API fixes, database migrations, and schema updates can be deployed without triggering a full frontend rebuild.
- Shared Source of Truth: Schema definitions (
@isitfun/db) and validation contracts (@isitfun/shared) are shared between frontend and backend with zero duplication.
The Hidden Friction
- Local Dev Orchestration: Instead of simply running
npm run dev, we now runconcurrentlyto spin up both Wrangler forapps/api(port 8787) and Vite forapps/web(port 5173). - Service Binding & Cookie Proxying: When developing locally, SvelteKit needs to proxy session cookies across ports. In production on Cloudflare, we use Service Bindings (
event.platform.env.API), but in local Node/Vite development, we have to fall back to HTTP fetch. - Monorepo Tooling Tax: TypeScript project references (
tsconfig.json), npm workspace hoisting quirks, and ESLint configs across multiple package roots require ongoing maintenance. - Cognitive Overhead: Developers have to think about which layer code belongs to (is this route a SvelteKit page action or a Hono API endpoint?).
When Should You Do This?
- Keep SvelteKit as a monolith if: You are building a content site, SaaS MVP, or standard CRUD app where data operations fit neatly into
+page.server.tsand form actions. SvelteKit’s developer velocity is unmatched when you don’t fight its boundaries. - Split into a monorepo if:
- You need stateful primitives like Cloudflare Durable Objects, WebSockets, or background cron workers.
- You have external clients (mobile apps, game engines, public APIs) that consume your backend independently of your web UI.
- Your server-side dependencies (image processing, zip streaming, auth pipelines) begin bloating your edge SSR worker bundle.
For isitfun, moving to a monorepo gave us the scalability and architectural clarity we needed to power real-time game telemetry, while keeping Svelte 5 at the center of a world-class developer portal.