create-k2-saas
v1.0.2
Published
A modern, self-documenting SaaS template using React, TypeScript, and Cloudflare Workers.
Maintainers
Readme
K2-SaaS Template
A modern, self-documenting SaaS template using React, TypeScript, and Cloudflare Workers.
Features
- 🚀 Full-stack TypeScript development
- 📦 Monorepo structure with pnpm workspaces
- ⚡ Fast builds with Turborepo
- 🎨 Beautiful UI with ShadcnUI and TailwindCSS
- 🔍 End-to-end type safety with Zod
- 🗄️ SQLite database with Drizzle ORM
- 🌩️ Serverless API with Cloudflare Workers
- 📝 Self-documenting API and components
Stack
Frontend
- React 19 with TypeScript
- ShadcnUI Components
- Zustand for State Management
- React Router for Navigation
- TailwindCSS for Styling
Backend
- Cloudflare Workers
- D1 Database (SQLite)
- Drizzle ORM
- Hono for API Routing
Shared
- pnpm Workspace
- Turborepo
- Zod Schema Validation
- Shared TypeScript Types
Getting Started
Bootstrap your application using this template:
npm create k2-saas my-saas-app cd my-saas-appInstall dependencies:
pnpm installCreate a D1 database:
cd apps/api pnpm wrangler d1 create k2-sass-dbUpdate
wrangler.tomlwith your D1 database IDPush the database schema:
pnpm db:pushStart the development servers:
# In the root directory pnpm dev
Project Structure
k2-sass/
├── apps/
│ ├── api/ # Cloudflare Worker API
│ │ ├── src/
│ │ │ ├── db/ # Database schema and config
│ │ │ └── index.ts # API routes
│ │ └── wrangler.toml
│ │
│ └── web/ # React frontend
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── store/
│ │ └── utils/
│ └── index.html
│
└── packages/
└── shared-types/ # Shared TypeScript types
└── src/
└── schemas.tsDevelopment Workflow
- Database Schema: Define your database schema in
apps/api/src/db/schema.ts - API Types: Add Zod schemas in
packages/shared-types/src/schemas.ts - API Routes: Implement routes in
apps/api/src/index.ts - Frontend State: Add Zustand stores in
apps/web/src/store - UI Components: Create pages and components in
apps/web/src/pagesandcomponents
API Endpoints in the example project
Users
GET /users- List all usersPOST /users- Create a new user
Posts
GET /posts- List all posts with authorsPOST /posts- Create a new postGET /posts/:id- Get post by IDPATCH /posts/:id- Update post by IDDELETE /posts/:id- Delete post by ID
Type Safety
The template ensures end-to-end type safety through:
- Zod schemas for API payloads and responses
- Shared TypeScript types between frontend and backend
- Drizzle ORM for type-safe database queries
- React Hook Form with Zod validation
License
MIT
