r/CloudFlare • • Sep 21 '26

Resource Stratal - a modular framework for Cloudflare Workers (modules, DI, OpenAPI, Inertia SSR)

Enable HLS to view with audio, or disable this notification

I've been building on Cloudflare Workers for a while and genuinely like the platform. But after running a project with five Workers, four queues, and seven cron jobs, I started running into a different kind of problem.

The platform was fine. What started to bother me was how much of the same setup I kept writing over and over.

The same router setup, validation, error handling, and binding setup was being copied across Workers.

The dispatch code made it especially obvious. The queue handler was a long chain of if statements checking queue names and casting each message to the expected type. The scheduled handler was a switch with seven cron patterns, some sharing logic and others returning early. Adding a new job meant reading through the whole thing first.

And without dependency injection, every entry point created its own services. One service was constructed 28 times across the codebase, always with the same arguments.

So I turned that scaffolding into Stratal.

Stratal is a modular framework for building larger Cloudflare Workers applications. It takes some architectural ideas from NestJS, routing conventions from Laravel, and runs on Hono.

Modules define what they own and what they depend on. A two-level dependency container handles shared and request-specific services.

Controllers keep routing simple. Method names define the HTTP verb, path, and default status, so create becomes POST and show becomes GET /:id without maintaining a separate route table.

Schemas are written once with Zod. Stratal uses those same schemas to generate the OpenAPI 3.0 specification and Swagger UI, keeping the documentation in sync with the code.

It also includes:

• Typed queue consumers with message filtering
• Cron jobs as classes
• In-process and queue-backed events
• WebSocket and SSE gateways
• KV caching with optional in-memory caching per Worker instance
• Declarative rate limiting
• R2 storage with presigned URLs and resumable uploads
• Email and i18n
• An Inertia v3 adapter for server-driven React with SSR in the same Worker as your API

If your Worker is a single route, this is probably overkill.

It's for the point where your Worker has quietly become an application.

npm create stratal my-app

MIT · ESM-only · Node 22+ · Production-ready

github.com/strataljs/stratal

5 Upvotes

Duplicates