An opinionated monorepo initializer for applications deployed to Cloudflare. Scaffolds a complete full-stack project with SvelteKit, Hono, and comprehensive tooling.
⨠Modern Tech Stack
šÆ Batteries Included
š Developer Experience
npm create @idoru/cloudflare-monorepo@latest my-project
Or with other package managers:
pnpm create @idoru/cloudflare-monorepo@latest my-project
yarn create @idoru/cloudflare-monorepo my-project
The initializer will prompt you for:
my-project/
āāā web/ # SvelteKit frontend (Cloudflare Pages)
ā āāā src/
ā ā āāā routes/
ā ā ā āāā +page.svelte # Demo page with API integration
ā ā āāā lib/
ā ā ā āāā components/ # Shadcn UI components
ā ā āāā app.d.ts # Cloudflare types
ā āāā vite.config.ts # Vite config with API proxy
ā āāā svelte.config.js # Cloudflare adapter
ā
āāā api/ # Hono backend (Cloudflare Workers)
ā āāā src/
ā ā āāā index.ts # OpenAPI routes
ā ā āāā index.test.ts # Unit tests
ā āāā wrangler.jsonc # Cloudflare config (D1 + KV)
ā āāā scripts/
ā āāā generate-openapi.js
ā
āāā tests/ # Playwright E2E tests
ā āāā e2e/
ā ā āāā echo.spec.ts # Sample E2E test
ā āāā playwright.config.ts
ā
āāā scripts/ # Deployment scripts
ā āāā deploy-all.js
ā āāā setup-cloudflare.js
ā
āāā package.json # Root workspace config
āāā pnpm-workspace.yaml # Workspace definition (if using pnpm)
āāā eslint.config.js # Shared ESLint config
āāā .prettierrc # Shared Prettier config
āāā README.md # Project documentation
cd api
npx wrangler d1 create my-project-db
Copy the database_id and update api/wrangler.jsonc.
npx wrangler kv:namespace create my-project-kv
Copy the namespace id and update api/wrangler.jsonc.
cd my-project
npm run dev
This starts:
The Vite dev server proxies /api/* requests to the Hono backend.
# E2E tests
npm test
# Unit tests
npm run test:unit
# UI mode (interactive)
npm run test:ui
# Development
npm run dev # Start both web and API dev servers
npm run build # Build all workspaces
npm run preview # Preview production build
# Testing
npm test # Run E2E tests
npm run test:unit # Run API unit tests
npm run test:ui # Run tests in UI mode
# Code Quality
npm run lint # Lint all code
npm run format # Format all code
# Documentation
npm run apidocs # Generate OpenAPI specification
# Deployment
npm run deploy:web # Deploy web app to Cloudflare Pages
npm run deploy:api # Deploy API to Cloudflare Workers
web/)api/)tests/)api/src/index.ts:const myRoute = createRoute({
method: 'get',
path: '/api/myroute',
responses: {
200: {
content: {
'application/json': {
schema: z.object({
message: z.string(),
}),
},
},
description: 'Success',
},
},
});
app.openapi(myRoute, (c) => {
return c.json({ message: 'Hello!' });
});
npm run apidocs
<script lang="ts">
async function fetchData() {
const res = await fetch('/api/myroute');
const data = await res.json();
console.log(data.message);
}
</script>
Add Shadcn components:
cd web
npx shadcn-svelte@latest add dialog
Use in your pages:
<script>
import { Dialog } from '$lib/components/ui/dialog';
</script>
app.get('/api/users', async (c) => {
const result = await c.env.D1.prepare('SELECT * FROM users').all();
return c.json(result);
});
app.get('/api/cache/:key', async (c) => {
const key = c.req.param('key');
const value = await c.env.KV.get(key);
return c.json({ key, value });
});
npm run build --workspace webweb/.svelte-kit/cloudflarecd web
npm run build
npm run deploy
cd api
npm run deploy
Or deploy everything:
node scripts/deploy-all.js
Create .dev.vars in the api/ directory:
MY_SECRET=my-dev-secret
Use Wrangler to set secrets:
cd api
npx wrangler secret put MY_SECRET
Change ports in:
web/vite.config.ts - Web app portapi/wrangler.jsonc - API port (under "dev")Reinstall Husky:
npm run prepare
Install browsers:
cd tests
npx playwright install
Clear build caches:
rm -rf web/.svelte-kit api/.wrangler tests/test-results
npm run build
git clone https://github.com/yourusername/create-cloudflare-monorepo.git
cd create-cloudflare-monorepo
npm install
npm run build
npm link
cd /tmp
@idoru/create-cloudflare-monorepo test-project
src/
āāā index.ts # Main CLI entry point
āāā cli.ts # Interactive prompts
āāā types.ts # TypeScript types
āāā generators/ # Workspace generators
ā āāā root.ts # Root workspace
ā āāā web.ts # SvelteKit app
ā āāā api.ts # Hono app
ā āāā tests.ts # Playwright tests
ā āāā scripts.ts # Utility scripts
āāā utils/ # Helper functions
ā āāā exec.ts # Command execution
ā āāā files.ts # File operations
ā āāā git.ts # Git operations
āāā templates/ # Template files
āāā root/
āāā web/
āāā api/
āāā tests/
āāā scripts/
MIT
Created with ā¤ļø for the Cloudflare developer community.