Flare Stack Blog

April 2, 2026 · View on GitHub

中文 | English

Flare Stack Blog

A full-stack modern blog CMS based on Cloudflare Workers
Deeply integrated with D1, R2, KV, Workflows, and other Serverless services.

License GitHub stars GitHub forks React TanStack Start Tailwind CSS

Demo Site · Deployment Guide · Local Development · Development Guidelines


Note: This project is designed exclusively for the Cloudflare ecosystem and only supports deployment on Cloudflare Workers.

Previews

Home Preview Admin Preview

Core Features

  • Post Management — Rich text editor supporting syntax highlighting, image uploads, and draft/publish workflows.
  • Version History — Automatic editor snapshots and post version history for safer recovery.
  • Tagging System — Flexible post categorization.
  • Comment System — Supports nested replies, email notifications, AI-assisted moderation, and richer moderation context.
  • Friend Links — User applications, admin moderation, and email notifications.
  • Notification System — Supports email and webhook notifications with event-based subscriptions.
  • Full-Text Search — High-performance search powered by Orama.
  • Media Library — R2 object storage for image management and optimization.
  • Authentication — GitHub OAuth login with role-based access control.
  • MCP Server — Connect AI clients through OAuth to manage posts, comments, tags, friend links, media, and analytics.
  • Analytics — Umami integration for visitor metrics and top posts.
  • SEO Enhancements — Canonical URLs, Schema.org structured data, RSS, Sitemap, and Robots support.
  • AI Integration — Cloudflare Workers AI integration.
  • Theme System — Extensible theme templates, fully supporting replacement of all pages and layouts.
  • Import / Export — Supports Markdown import and export, preserving images and frontmatter.

Tech Stack

Cloudflare Ecosystem

ServicePurpose
WorkersEdge computing and hosting
D1SQLite database
R2Object storage (media files)
KVCaching layer
Durable ObjectsDistributed rate limiting
WorkflowsAsynchronous tasks (content moderation, scheduled publishing)
QueuesMessage queues (email notifications)
Workers AIAI capabilities
ImagesImage optimization

Frontend

  • Framework: React 19 + TanStack Router/Query
  • Styling: TailwindCSS 4
  • Forms: React Hook Form + Zod
  • Charts: Recharts

Backend

  • Gateway Layer: Hono (auth routes, media services, cache control)
  • Business Layer: TanStack Start (SSR, Server Functions)
  • Database: Drizzle ORM + drizzle-zod
  • Authentication: Better Auth (GitHub OAuth)

Editor

TipTap Rich Text + Shiki Syntax Highlighting

Directory Structure

src/
├── features/
│   ├── posts/                  # Post management (other modules share similar structure)
│   │   ├── api/                # Server Functions (Public APIs)
│   │   ├── data/               # Data access layer (Drizzle queries)
│   │   ├── posts.service.ts    # Business logic
│   │   ├── posts.schema.ts     # Zod Schemas + Cache Key Factories
│   │   ├── components/         # Feature-specific components
│   │   ├── queries/            # TanStack Query Hooks
│   │   └── workflows/          # Cloudflare Workflows
│   ├── comments/    # Comments, nested replies, moderation
│   ├── tags/        # Tag management
│   ├── media/       # Media uploads, R2 storage
│   ├── search/      # Orama full-text search
│   ├── auth/        # Authentication, permission control
│   ├── dashboard/   # Admin dashboard statistics
│   ├── email/       # Email notifications (Resend)
│   ├── cache/       # KV caching services
│   ├── config/      # Blog configurations
│   ├── friend-links/# Friend links (applications, moderation)
│   ├── import-export/# Markdown importing/exporting
│   ├── version/     # Version update checker
│   ├── theme/       # Theme system (Contracts, registry, theme implementations)
│   └── ai/          # Workers AI integration
├── routes/
│   ├── _public/     # Public pages (Home, post lists/details, search)
│   ├── _auth/       # Login/Registration related pages
│   ├── _user/       # User specific pages
│   ├── admin/       # Management backend (posts, comments, media, tags, settings)
│   ├── rss[.]xml.ts     # RSS Feed
│   ├── sitemap[.]xml.ts # Sitemap
│   └── robots[.]txt.ts  # Robots.txt
├── components/      # UI components (ui/, common/, layout/, tiptap-editor/)
├── lib/             # Infrastructure (db/, auth/, hono/, middlewares)
└── hooks/           # Custom React Hooks

Theme System

All user-facing pages and layouts in Flare Stack Blog are decoupled from business logic via a Theme Contract. You can completely replace the visual presentation layer of the blog without modifying any routing or data logic.

Theme Development Guide — Learn how to build your first custom theme from scratch.

Available Themes

Site personalization such as title, description, social links, favicon, and default-theme background assets is now managed from the admin Settings page. src/blog.config.ts mainly serves as seeded defaults and runtime fallback values; see the Theme Development Guide for how themes should consume runtime siteConfig.

Theme Preview
default Default theme preview
fuwari Fuwari theme preview

Contributions are highly welcome! Built a custom theme following the Theme Development Guide? Feel free to submit a PR to list your theme here.

Request Flow

Request → Cloudflare CDN (Edge Cache)
             ↓ Miss
          server.ts (Hono Entry)
             ├── /api/auth/* → Better Auth
             ├── /images/*   → R2 Media Service
             └── Others      → TanStack Start

                             Middleware Injection (db, auth, session)

                             Route Matching + Loader Execution

                      KV Cache ←→ Service Layer ←→ D1 Database

                             SSR Rendering (with cache headers)

Deployment Guide

Please refer to the Flare Stack Blog Deployment Guide for comprehensive structural steps, addressing Cloudflare resource orchestration, credentials procurement, GitHub OAuth configurations, and detailed visual and written setups for both automated deployment approaches along with troubleshooting.


Environment Variables Reference

FilePurpose
.envClient-side variables (VITE_*), read by Vite
.dev.varsServer-side variables, injected into Worker env by Wrangler

Required

VariableScopeDescription
CLOUDFLARE_API_TOKENCI/CDCloudflare API Token (Worker deployment + D1 read/write permissions)
CLOUDFLARE_ACCOUNT_IDCI/CDCloudflare Account ID
D1_DATABASE_IDCI/CDD1 Database ID
KV_NAMESPACE_IDCI/CDKV Namespace ID
BUCKET_NAMECI/CDR2 Bucket Name
BETTER_AUTH_SECRETRuntimeSession encryption key. Generate using openssl rand -hex 32
BETTER_AUTH_URLRuntimeApplication URL (e.g., https://blog.example.com)
ADMIN_EMAILRuntimeAdministrator's email address
GITHUB_CLIENT_IDRuntimeGitHub OAuth Client ID
GITHUB_CLIENT_SECRETRuntimeGitHub OAuth Client Secret
CLOUDFLARE_ZONE_IDRuntimeCloudflare Zone ID
CLOUDFLARE_PURGE_API_TOKENRuntimeAPI token with Purge CDN permissions
DOMAINRuntimeBlog's domain (e.g., blog.example.com)

Optional

VariableScopeDescription
THEMEBuild-timeTheme name, defaults to default. Refer to Available Themes.
TURNSTILE_SECRET_KEYRuntimeCloudflare Turnstile Secret Key for CAPTCHA.
VITE_TURNSTILE_SITE_KEYBuild-timeCloudflare Turnstile Site Key.
GITHUB_TOKENRuntimeGitHub API Token (for version updates checking to avoid rate limits).
LOCALERuntimeDefault language: zh or en. Default: zh. Used for emails, webhooks, and background task messaging.
CDN_DOMAINRuntimeStandalone CDN domain (e.g., cdn.example.com), preferentially used during purge.
PAGEVIEW_SALTRuntimeSalt for anonymizing pageview visitor hashes. Generate with openssl rand -hex 16.
UMAMI_SRCRuntimeUmami client-side tracking proxy URL (e.g., https://cloud.umami.is).
VITE_UMAMI_WEBSITE_IDBuild-timeUmami Website ID (client-side tracking).

Local Development

Prerequisites

  • Bun >= 1.3
  • A Cloudflare account (For remote D1/R2/KV resource simulations)

Quick Start

# Install dependencies
bun install

# Configure environment variables
cp .env.example .env            # Client-side variables
cp .dev.vars.example .dev.vars  # Server-side variables

# Configure Wrangler
cp wrangler.example.jsonc wrangler.jsonc
# Edit wrangler.jsonc to insert your Cloudflare resource IDs

# Start development server
bun dev

Logging into the Admin Backend

Method 1: Email and Password Registration (No third-party service required)

  1. Visit http://localhost:3000's registration page and register using the ADMIN_EMAIL configured in .dev.vars.
  2. In the development environment, the verification email won't actually be sent. A link will be printed directly in the terminal console — copy and visit it to complete verification.
  3. Post-verification involves automatic login, with the system granting admin privileges matched by ADMIN_EMAIL.

Method 2: GitHub OAuth

  1. Navigate to GitHub Developer Settings to generate a new OAuth App.
  2. Homepage URL: http://localhost:3000, Authorization callback URL: http://localhost:3000/api/auth/callback/github.
  3. Input Client ID and Client Secret configurations into .dev.vars.

Common Commands

CommandDefinition
bun devStarts local dev server (default port 3000)
bun run buildBuilds the production bundle
bun run testRuns the test suites
bun lintRuns the ESLint checker
bun checkInitiates Type checking + Lint + Code formatting

Database Commands

CommandDefinition
bun db:studioInvokes the Drizzle Studio visual database interface
bun db:generateGenerates schema migration files
bun db:migrateSafely applies remote D1 migrations and auto-rolls back on failure
bun db:migrate:localSafely applies local D1 migrations and auto-restores local state
bun db:migrate:unsafeApplies remote D1 migrations directly without verification

bun db:migrate and bun db:migrate:local reuse the schema-defined status constants and verify these counts before and after migration:

  • posts: total post count and the count for each post status
  • comments: total comments, root comments, reply comments, and the count for each comment status

The safety script also adds these safeguards:

  • Remote mode: records a D1 Time Travel bookmark by default and automatically restores on verification failure
  • Remote mode: if you also want a SQL snapshot for manual incident analysis, run bun scripts/safe-d1-migrate/main.ts --remote --with-export
  • Local mode: snapshots .wrangler/state (or your custom --persist-to path) and restores it automatically on verification failure

Simulating Cloudflare Resources Locally

The default workspace connects to remote D1/R2/KV resources. If an entirely local ecosystem is needed, simply remove remote: true from wrangler.jsonc entries, allowing Miniflare to simulate these interfaces natively:

{
  "d1_databases": [{ "binding": "DB", ... }],  // remove "remote": true
  "r2_buckets": [{ "binding": "R2", ... }],    // remove "remote": true
  "kv_namespaces": [{ "binding": "KV", ... }]  // remove "remote": true
}

Note: Locally simulated data is not synced remotely to Cloudflare, rendering it safe for exploratory setups. For local database migrations, prefer:

bun db:migrate:local

Contributing

We enthusiastically welcome all code contributions, issues, and feature suggestions! Please examine CONTRIBUTING.en.md to gather deeper contextualization around development patterns.

Prior to modifying fundamental layers, we warmly advise reading Error Handling Quickstart.