Skip to content

Setup Guide

Rahil Pirani edited this page May 15, 2026 · 4 revisions

Setup Guide

One-click deploy (recommended)

Deploy to Cloudflare

Click the Deploy to Cloudflare button in the README. Cloudflare will fork the repo into your GitHub account, provision a D1 database and Vectorize index, and deploy the Worker automatically.

After deploying, find your Worker URL in Cloudflare Dashboard → Workers & Pages → second-brain. It looks like https://second-brain.<your-subdomain>.workers.dev.

Step 1 — Run the schema

In Cloudflare Dashboard → D1 → second-brain-db → Console, paste and run:

CREATE TABLE IF NOT EXISTS entries (
  id          TEXT PRIMARY KEY,
  content     TEXT NOT NULL,
  tags        TEXT NOT NULL DEFAULT '[]',
  source      TEXT NOT NULL DEFAULT 'api',
  created_at  INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_entries_created_at ON entries(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_entries_source ON entries(source);

Step 2 — Set your auth token

openssl rand -base64 32   # generate a secure token — save this somewhere
wrangler secret put AUTH_TOKEN

Step 3 — Test it

curl -X POST https://<your-worker-url>/capture \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content": "second brain is working", "source": "test"}'
# → {"ok":true,"id":"..."}

Then open https://<your-worker-url>/ to access the dashboard.


Manual setup

If you prefer to deploy from a local clone:

Prerequisites

  • Node.js 18+
  • A Cloudflare account (free tier works)
  • Wrangler CLI (installed via npm install)

Steps

# 1. Clone and install
git clone https://github.com/rahilp/second-brain-cloudflare.git
cd second-brain-cloudflare
npm install

# 2. Authenticate with Cloudflare
npx wrangler login

# 3. Create the D1 database
npm run db:create
# Copy the database_id from the output and paste it into wrangler.toml

# 4. Create the Vectorize index
npm run vectors:create

# 5. Run the schema
npm run db:migrate:remote

# 6. Set your auth token
openssl rand -base64 32
npx wrangler secret put AUTH_TOKEN

# 7. Deploy
npm run deploy

Useful scripts

Script Description
npm run dev Start local dev server
npm run deploy Deploy to Cloudflare
npm run db:create Create the D1 database
npm run db:migrate Run schema against local D1
npm run db:migrate:remote Run schema against remote D1
npm run vectors:create Create the Vectorize index

Local development

npm run dev

Vectorize and Workers AI are only available remotely. Embedding calls will fail gracefully during local development — entries will still be stored in D1 without vectors.

To test against your live remote resources:

npx wrangler dev --remote

Clone this wiki locally