Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ This is the same stack used to build [Supermemory.ai](https://Supermemory.ai) wh

Supermemory now has 20k+ users and it runs on $5/month. safe to say, it's _very_ effective.

## The stack includes:
## The stack includes

- [Next.js](https://nextjs.org/) for frontend
- [TailwindCSS](https://tailwindcss.com/) for styling
- [Drizzle ORM](https://orm.drizzle.team/) for database access
- [NextAuth](https://next-auth.js.org/) for authentication
- [Cloudflare D1](https://www.cloudflare.com/developer-platform/d1/) for serverless databases
- [Cloudflare Pages](https://pages.cloudflare.com/) for hosting
- [ShadcnUI](https://shadcn.com/) as the component library
- [ShadcnUI](https://ui.shadcn.com/) as the component library

## Getting Started

1. 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)

2. Clone the repository and install dependencies:

```bash
git clone https://github.com/Dhravya/cloudflare-saas-stack
cd cloudflare-saas-stack
Expand All @@ -32,6 +33,7 @@ Supermemory now has 20k+ users and it runs on $5/month. safe to say, it's _very_
```

3. Run the development server:

```bash
bun run dev
```
Expand All @@ -41,12 +43,13 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the
## Cloudflare Integration

Besides the `dev` script, `c3` has added extra scripts for Cloudflare Pages integration:

- `pages:build`: Build the application for Pages using [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages) CLI
- `preview`: Locally preview your Pages application using [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
- `deploy`: Deploy your Pages application using Wrangler CLI
- `cf-typegen`: Generate typescript types for Cloudflare env.

> __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.
> **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.

## Bindings

Expand All @@ -55,7 +58,9 @@ Cloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings
For detailed instructions on setting up bindings, refer to the Cloudflare documentation.

## Database Migrations

Quick explaination of D1 set up:

- D1 is a serverless database that follows SQLite convention.
- 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`)
- You can also query d1 via [rest api](https://developers.cloudflare.com/api/operations/cloudflare-d1-create-database)
Expand All @@ -64,13 +69,16 @@ Quick explaination of D1 set up:
- In dev mode (`bun run db:<migrate or studio>:dev`), Drizzle-kit (migrate and studio) directly modifies these files as regular SQlite db. While `bun run db:<migrate or studio>:prod` use d1-http driver to interact with remote d1 via rest api. Therefore we need to set env var at `.env.example`

To generate migrations files:

- `bun run db:generate`

To apply database migrations:

- For development: `bun run db:migrate:dev`
- For production: `bun run db:migrate:prd`

To inspect database:

- For local database `bun run db:studio:dev`
- For remote database `bun run db:studio:prod`

Expand All @@ -81,20 +89,10 @@ Don't forget to add the CORS policy to the R2 bucket. The CORS policy should loo
```json
[
{
"AllowedOrigins": [
"http://localhost:3000",
"https://your-domain.com"
],
"AllowedMethods": [
"GET",
"PUT"
],
"AllowedHeaders": [
"Content-Type"
],
"ExposeHeaders": [
"ETag"
]
"AllowedOrigins": ["http://localhost:3000", "https://your-domain.com"],
"AllowedMethods": ["GET", "PUT"],
"AllowedHeaders": ["Content-Type"],
"ExposeHeaders": ["ETag"]
}
]
```
Expand Down Expand Up @@ -126,4 +124,3 @@ If you prefer manual setup:
- Cost-effective scaling (e.g., $5/month for multiple high-traffic projects)

Just change your Cloudflare account ID in the project settings, and you're good to go!