About Emberstack
What is Emberstack?
Emberstack is a starter template for building a SaaS application with Astro on Cloudflare Workers. It comes with authentication and teams, Stripe billing, a CMS-driven marketing site and blog, and a dashboard for logged-in users. It all runs on Cloudflare: D1, R2, KV, Workers AI and Email Sending.
Features
- Marketing site and blog managed in EmDash at
/_emdash/admin, built from editable blocks (hero, features, pricing, FAQ, testimonials, CTA, contact and more) - Pricing page wired to Stripe Checkout, plus subscription management in the Stripe Customer Portal
- Email/password authentication with Better Auth
- Teams with Owner, Admin and Member roles, invitations and a team switcher. Every signup gets its own team.
- Dashboard under
/appwith an example Notes app - Server-rendered pages that Datastar updates in place (forms still work without JavaScript)
- Activity logging for user events
- Transactional email through Cloudflare Email Sending, or Resend, Postmark, SendGrid, Mailgun or AutoSend
- Workers AI binding ready to use
Tech Stack
- Framework: Astro 7 on Cloudflare Workers
- Database: Cloudflare D1 with Drizzle ORM
- CMS: EmDash, with its own D1 database and media in R2
- Auth: Better Auth with the organization plugin
- Payments: Stripe
- Email: Cloudflare Email Sending
- Frontend: Datastar
- Styling: Tailwind CSS 4 and daisyUI 5
- Tooling: Bun, Wrangler and Biome
Getting Started
You need Bun, a Cloudflare account and a Stripe account.
git clone https://github.com/freekrai/emberstack
cd emberstack
bun install
bunx wrangler loginRunning Locally
Copy the example secrets file, then fill in BETTER_AUTH_SECRET (openssl rand -hex 32), STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET:
cp .dev.vars.example .dev.varsSet up the local database and seed a default user and team:
bun run db:migrate:local
bun run db:seedThis creates a user you can sign in with:
- Email:
test@test.com - Password:
admin123
You can also create new accounts at /signup. Then start the dev server:
bun run devOpen http://localhost:3000. The CMS is at http://localhost:3000/_emdash/admin. On your first visit, EmDash sets up its database and asks you to create the admin account. CMS editors are separate from app users.
To handle subscription events locally, forward Stripe webhooks in another terminal:
bun run stripe:webhookTesting Payments
To test Stripe payments, use the following test card details:
- Card Number:
4242 4242 4242 4242 - Expiration: Any future date
- CVC: Any 3-digit number
Going to Production
Emberstack runs on Cloudflare Workers. Everything it needs is on Cloudflare: D1 for data, R2 for media, KV for sessions and Email Sending for mail.
1. Create your Cloudflare resources
The IDs in wrangler.jsonc belong to the demo account. Create your own, then put the new names and IDs into wrangler.jsonc:
bunx wrangler login
bunx wrangler d1 create my-app-db # app database (DB)
bunx wrangler d1 create my-app-cms # CMS database (CMS_DB)
bunx wrangler r2 bucket create my-app-media # CMS media (MEDIA)
bunx wrangler kv namespace create SESSION # sessions (SESSION)
bun run cf-typegenIn wrangler.jsonc, also set your domain in routes, and set PUBLIC_URL and EMAIL_FROM in vars. Then update PUBLIC_URL= in the deploy script in package.json.
2. Set your secrets
bunx wrangler secret put BETTER_AUTH_SECRET # openssl rand -hex 32
bunx wrangler secret put STRIPE_SECRET_KEY
bunx wrangler secret put STRIPE_WEBHOOK_SECRETTo send email from your own domain, onboard it for Email Sending:
bunx wrangler email sending enable yourdomain.com3. Migrate and deploy
bun run db:migrate
bun run deployThe CMS database migrates itself on the first request.
4. Set up the CMS
Open https://yourdomain.com/_emdash/admin and create the admin account. Then set the Site URL, title and logo in settings.
5. Set up a production Stripe webhook
In the Stripe Dashboard, create a webhook pointing at https://yourdomain.com/api/stripe/webhook. Subscribe it to these events:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deleted
Use its signing secret as STRIPE_WEBHOOK_SECRET.
Other Templates
While this template is intentionally minimal and to be used as a learning resource, there are other paid versions in the community which are more full-featured:
- https://achromatic.dev
- https://shipfa.st
- https://makerkit.dev