{"id":13362677,"url":"https://github.com/Dhravya/cloudflare-saas-stack","last_synced_at":"2025-03-12T15:30:57.704Z","repository":{"id":249726284,"uuid":"830102284","full_name":"Dhravya/cloudflare-saas-stack","owner":"Dhravya","description":"Quickly make and deploy full-stack apps with database, auth, styling, storage etc. figured out for you. Add all primitives you want.","archived":false,"fork":false,"pushed_at":"2025-02-15T07:08:55.000Z","size":480,"stargazers_count":3396,"open_issues_count":1,"forks_count":270,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-03-09T19:36:46.482Z","etag":null,"topics":["cloudflare","cloudflare-saas-stack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dhravya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-17T15:37:20.000Z","updated_at":"2025-03-09T19:24:28.000Z","dependencies_parsed_at":"2024-09-06T08:35:00.065Z","dependency_job_id":"6c168432-bc6a-45c7-986d-38eff402a4f6","html_url":"https://github.com/Dhravya/cloudflare-saas-stack","commit_stats":{"total_commits":45,"total_committers":10,"mean_commits":4.5,"dds":"0.33333333333333337","last_synced_commit":"a134bddc987637bf02ea06f9bd7e6e467b617903"},"previous_names":["dhravya/cloudflare-saas-stack"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhravya%2Fcloudflare-saas-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhravya%2Fcloudflare-saas-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhravya%2Fcloudflare-saas-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhravya%2Fcloudflare-saas-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dhravya","download_url":"https://codeload.github.com/Dhravya/cloudflare-saas-stack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243242715,"owners_count":20259807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-saas-stack"],"created_at":"2024-07-29T23:00:59.627Z","updated_at":"2025-03-12T15:30:57.696Z","avatar_url":"https://github.com/Dhravya.png","language":"TypeScript","readme":"# 🚀 Full-Stack Cloudflare SaaS Kit\n\n**_Build and deploy scalable products on Cloudflare with ease._**\n\nAn opinionated, batteries-included starter kit for quickly building and deploying SaaS products on Cloudflare. This is a [Next.js](https://nextjs.org/) project bootstrapped with [`c3`](https://developers.cloudflare.com/pages/get-started/c3).\n\nThis is the same stack used to build [Supermemory.ai](https://Supermemory.ai) which is open source at [git.new/memory](https://git.new/memory)\n\nSupermemory now has 20k+ users and it runs on $5/month. safe to say, it's _very_ effective.\n\n## The stack includes:\n\n- [Next.js](https://nextjs.org/) for frontend\n- [TailwindCSS](https://tailwindcss.com/) for styling\n- [Drizzle ORM](https://orm.drizzle.team/) for database access\n- [NextAuth](https://next-auth.js.org/) for authentication\n- [Cloudflare D1](https://www.cloudflare.com/developer-platform/d1/) for serverless databases\n- [Cloudflare Pages](https://pages.cloudflare.com/) for hosting\n- [ShadcnUI](https://shadcn.com/) as the component library\n\n## Getting Started\n\n1. Make sure that you have [Wrangler](https://developers.cloudflare.com/workers/wrangler/install-and-update/#installupdate-wrangler) installed. And also that you have logged in with `wrangler login` (You'll need a Cloudflare account)\n\n2. Clone the repository and install dependencies:\n   ```bash\n   git clone https://github.com/Dhravya/cloudflare-saas-stack\n   cd cloudflare-saas-stack\n   npm i -g bun\n   bun install\n   bun run setup\n   ```\n\n3. Run the development server:\n   ```bash\n   bun run dev\n   ```\n\nOpen [http://localhost:3000](http://localhost:3000) with your browser to see the result.\n\n## Cloudflare Integration\n\nBesides the `dev` script, `c3` has added extra scripts for Cloudflare Pages integration:\n- `pages:build`: Build the application for Pages using [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages) CLI\n- `preview`: Locally preview your Pages application using [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI\n- `deploy`: Deploy your Pages application using Wrangler CLI\n- `cf-typegen`: Generate typescript types for Cloudflare env.\n\n\u003e __Note:__ While the `dev` script is optimal for local development, you should preview your Pages application periodically to ensure it works properly in the Pages environment.\n\n## Bindings\n\nCloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) allow you to interact with Cloudflare Platform resources. You can use bindings during development, local preview, and in the deployed application.\n\nFor detailed instructions on setting up bindings, refer to the Cloudflare documentation.\n\n## Database Migrations\nQuick explaination of D1 set up:\n- D1 is a serverless database that follows SQLite convention.\n- Within Cloudflare pages and workers, you can directly query d1 with [client api](https://developers.cloudflare.com/d1/build-with-d1/d1-client-api/) exposed by bindings (eg. `env.BINDING`)\n- You can also query d1 via [rest api](https://developers.cloudflare.com/api/operations/cloudflare-d1-create-database)\n- Locally, wrangler auto generates sqlite files at `.wrangler/state/v3/d1` after `bun run dev`.\n- Local dev environment (`bun run dev`) interact with [local d1 session](https://developers.cloudflare.com/d1/build-with-d1/local-development/#start-a-local-development-session), which is based on some SQlite files located at `.wrangler/state/v3/d1`.\n- In dev mode (`bun run db:\u003cmigrate or studio\u003e:dev`), Drizzle-kit (migrate and studio) directly modifies these files as regular SQlite db. While `bun run db:\u003cmigrate or studio\u003e:prod` use d1-http driver to interact with remote d1 via rest api. Therefore we need to set env var at `.env.example`\n\nTo generate migrations files:\n- `bun run db:generate`\n\nTo apply database migrations:\n- For development: `bun run db:migrate:dev`\n- For production: `bun run db:migrate:prd`\n\nTo inspect database:\n- For local database `bun run db:studio:dev`\n- For remote database `bun run db:studio:prod`\n\n## Cloudflare R2 Bucket CORS / File Upload\n\nDon't forget to add the CORS policy to the R2 bucket. The CORS policy should look like this:\n\n```json\n[\n  {\n    \"AllowedOrigins\": [\n      \"http://localhost:3000\",\n      \"https://your-domain.com\"\n    ],\n    \"AllowedMethods\": [\n      \"GET\",\n      \"PUT\"\n    ],\n    \"AllowedHeaders\": [\n      \"Content-Type\"\n    ],\n    \"ExposeHeaders\": [\n      \"ETag\"\n    ]\n  }\n]\n```\n\nYou can now even set up object upload.\n\n## Manual Setup\n\nIf you prefer manual setup:\n\n1. Create a Cloudflare account and install Wrangler CLI.\n2. Create a D1 database: `bunx wrangler d1 create ${dbName}`\n3. Create a `.dev.vars` file in the project root with your Google OAuth credentials and NextAuth secret.\n   1. `AUTH_SECRET`, generate by command `openssl rand -base64 32` or `bunx auth secret`\n   2. `AUTH_GOOGLE_ID` and `AUTH_GOOGLE_SECRET` for google oauth.\n      1. First create [OAuth consent screen](https://console.cloud.google.com/apis/credentials/consent). Tips: no wait time if you skip logo upload.\n      2. Create [credential](https://console.cloud.google.com/apis/credentials). Put `https://your-domain` and `http://localhost:3000` at \"Authorized JavaScript origins\". Put `https://your-domain/api/auth/callback/google` and `http://localhost:3000/api/auth/callback/google` at \"Authorized redirect URIs\".\n4. Generate db migration files: `bun run db:generate`\n5. Run local migration: `bunx wrangler d1 execute ${dbName} --local --file=migrations/0000_setup.sql` or using drizzle `bun run db:migrate:dev`\n6. Run remote migration: `bunx wrangler d1 execute ${dbName} --remote --file=migrations/0000_setup.sql` or using drizzle `bun run db:migrate:prod`\n7. Start development server: `bun run dev`\n8. Deploy: `bun run deploy`\n\n## The Beauty of This Stack\n\n- Fully scalable and composable\n- No environment variables needed (use `env.DB`, `env.KV`, `env.Queue`, `env.AI`, etc.)\n- Powerful tools like Wrangler for database management and migrations\n- Cost-effective scaling (e.g., $5/month for multiple high-traffic projects)\n\nJust change your Cloudflare account ID in the project settings, and you're good to go!\n\n","funding_links":[],"categories":["TypeScript","SaaS","Boilerplates / Templates","Saas","Boilerplates \u0026 Starters"],"sub_categories":["Portfolios"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDhravya%2Fcloudflare-saas-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDhravya%2Fcloudflare-saas-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDhravya%2Fcloudflare-saas-stack/lists"}