Skip to main content
Before running or deploying Gitflare, you need to configure environment variables and set up Cloudflare services.

Environment variables

Gitflare uses environment variables to configure authentication, database connections, and deployment settings.
1

Create environment file

Navigate to the web application directory and create a .env file based on the example:
cd apps/web
cp .env.example .env
2

Configure Better Auth

Set the Better Auth secret for handling authentication:
.env
BETTER_AUTH_SECRET=your-secret-key-here
Generate a secure random string for production. You can use openssl rand -base64 32 to generate a secure secret.
The application automatically sets VITE_BETTER_AUTH_URL based on your deployment environment:
  • Local: http://localhost:3000
  • Preview: Cloudflare Workers preview URL
  • Production: Your custom domain
3

Configure Cloudflare credentials

For database migrations and remote operations, set your Cloudflare credentials:
.env
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_DATABASE_ID=your-d1-database-id
CLOUDFLARE_D1_TOKEN=your-api-token
To find these values:
  1. Account ID: Found in the Cloudflare dashboard URL or Workers page
  2. Database ID: Created when you set up your D1 database (see below)
  3. D1 Token: Generate an API token with D1 permissions in Cloudflare dashboard → API Tokens

Cloudflare services setup

Gitflare uses several Cloudflare services that need to be configured.

D1 Database

Gitflare uses Cloudflare D1 for storing user data, repository metadata, and issues.
1

Authenticate with Cloudflare

Authenticate the Wrangler CLI with your Cloudflare account:
pnpm wrangler login
This opens your browser to authorize Wrangler.
2

Create D1 database

Create a new D1 database for Gitflare:
pnpm wrangler d1 create gitflare-db
This command outputs your database ID. Copy this ID to your .env file as CLOUDFLARE_DATABASE_ID.
3

Run database migrations

Apply the database schema migrations:
pnpm db:migrate:local
Use db:migrate:local for your local development database and db:migrate:remote for your production database.

Durable Objects

Gitflare uses Durable Objects to store Git repository data. These are automatically configured through the alchemy.run.ts file:
alchemy.run.ts
const repoDO = DurableObjectNamespace("repos", {
  className: "Repo",
  sqlite: true,
});
Each repository gets its own Durable Object instance with SQLite-backed storage.
Durable Objects are automatically deployed when you deploy your Worker. No manual setup is required.

Alchemy configuration

Gitflare uses Alchemy for deployment and infrastructure management. The configuration is in apps/web/alchemy.run.ts.

Key configuration options

const app = await alchemy("gitflare", {
  stateStore: (scope) => new CloudflareStateStore(scope),
});
Bindings: The TanStack Start application receives these environment bindings:
  • REPO: Durable Object namespace for repositories
  • DB: D1 database connection
  • LOG_LEVEL: Logging level (debug for dev, warn for prod)
  • SITE_URL: Current deployment URL
  • VITE_BETTER_AUTH_URL: Better Auth endpoint URL
  • BETTER_AUTH_SECRET: Authentication secret

Custom domain

To use a custom domain in production, update the PROD_DOMAIN constant in alchemy.run.ts:
alchemy.run.ts
const PROD_DOMAIN = "gitflare.yourdomain.com";
Make sure to configure the domain in your Cloudflare dashboard and update your DNS records.

Database schema management

Gitflare uses Drizzle ORM for type-safe database operations.

Generate migrations

After modifying database schemas in apps/web/src/db/schema/, generate new migrations:
pnpm db:generate
This creates migration files in the migrations/ directory.

Configuration

Drizzle is configured in drizzle.config.ts:
drizzle.config.ts
export default defineConfig({
  schema: "./src/db/schema/**.ts",
  out: "./migrations",
  dialect: "sqlite",
  driver: "d1-http",
  dbCredentials: {
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID ?? "",
    databaseId: process.env.CLOUDFLARE_DATABASE_ID ?? "",
    token: process.env.CLOUDFLARE_D1_TOKEN ?? "",
  },
});

Verify configuration

Before starting development or deploying, verify your configuration:
1

Check type definitions

Generate TypeScript types for Cloudflare Workers:
pnpm cf-typegen
2

Run type checking

Ensure all types are correct:
pnpm typecheck
3

Start local development

Start the development server to verify everything works:
pnpm dev
Your application should be available at http://localhost:3000.

Next steps

Deployment

Deploy your configured Gitflare instance to Cloudflare Workers

Development

Learn about the development workflow and available commands

Build docs developers (and LLMs) love