blog.dopana

Back

WordPress is aging. There’s a modern CMS alternative built for the edge. EmDash is an open-source full-stack CMS designed for Astro, combining Cloudflare D1 (SQLite-compatible serverless DB) and R2 (object storage). This article explains the complete database architecture.

1. Architecture Overview#

EmDash architecture has four pillars:

Edge RuntimeFirst RequestAstro FrameworkEmDash CMS LayerCloudflare D1SQLite Serverless DBCloudflare R2Object Storageseed/seed.jsonSchema Source of Truthwrangler.jsoncBinding Config
ComponentRole
AstroFramework, SSR/SSG, Live Collections
EmDash CMSAdmin UI, content model, REST API, plugins
Cloudflare D1SQL DB for content, settings, taxonomies, users, media metadata
Cloudflare R2Object storage for media files (images, uploads)

2. Cloudflare D1: SQLite Serverless Database#

D1 is Cloudflare’s managed serverless database. SQLite SQL semantics with built-in disaster recovery and Worker/HTTP API access.

Key Specs#

ItemDetails
EngineSQLite
Free Tier5M rows read/day, 100K rows written/day, up to 5GB
Paid Plan1DB up to 10GB, account up to 50,000DB (1TB total)
Time TravelPoint-in-time recovery to any minute in last 30 days
Global Read ReplicaBeta: cross-region read replicas

Why D1?#

  • SQLite compatible : Existing SQLite knowledge works out of the box
  • Serverless : No idle charges, pay only for queries and storage
  • Edge delivery : Cloudflare’s global network for low latency
  • EmDash official support : emdash/db provides d1() adapter

3. Binding Configuration: wrangler.jsonc#

D1 and R2 bindings are configured in wrangler.jsonc:

Binding Flow#

"wrangler d1 create emdash-db""Create D1 database"database_id (UUID)Record UUID in wrangler.jsoncwrangler dev startConnect to D1 via env.DBDeveloperWrangler CLICloudflareAstro/EmDashDeveloperWrangler CLICloudflareAstro/EmDash

[!NOTE] The binding name is used in code as env.DB, env.MEDIA. If you rename it, update the code too.

4. EmDash DB Adapter#

EmDash specifies the DB adapter in astro.config.mjs:

astro.config.mjs
import emdash from "emdash/astro";
import { d1 } from "emdash/db";

export default defineConfig({
  integrations: [
    emdash({
      database: d1(),  // Cloudflare D1 adapter
    }),
  ],
});
js

Available adapters:

AdapterUse Case
d1()Cloudflare D1 (serverless)
sqlite()Local SQLite (development)
libsql()LibSQL/Turso
postgresql()PostgreSQL

5. seed.json: Schema Source of Truth#

seed/seed.json is the bootstrap document for an EmDash site. Defines collections, fields, taxonomies, menus, redirects, widget areas, and site settings.

seed.json Structure#

Application Rules#

OperationBehavior
Collections, Settingsupsert — update if exists, create if not
Menus, Widgetsreplace — overwrite completely with seed
Content entriesskip — skip if slug already exists

How to Apply#

# Apply via CLI
npx emdash seed seed/seed.json

# Export existing schema
npx emdash export-seed > .emdash/seed.json

# Export with content
npx emdash export-seed --with-content > .emdash/seed.json
bash

[!TIP] seed.json auto-applies on “first request” when the database is empty. During development, applying explicitly via CLI is safer.

6. Local Development: Miniflare + SQLite#

Local development uses Miniflare (Cloudflare’s local simulator).

Storage Path#

.wrangler/state/v3/d1/miniflare-D1DatabaseObject/<hash>.sqlite
text
ItemDescription
<hash>Hex hash derived from database_id
File formatSQLite compatible (connect directly with better-sqlite3)
PersistenceData persists between wrangler dev sessions
Local/RemoteFully separated with --local / --remote flags

Local Dev Flow#

# Apply seed to local D1
npx emdash seed seed/seed.json --local

# Start dev server
wrangler dev

# Check local DB
ls .wrangler/state/v3/d1/miniflare-D1DatabaseObject/
bash

[!NOTE] Local DB and remote DB are fully separated. Use --local and --remote to distinguish.

7. Complete Data Flow#

Page requestgetEmDashCollection()SQL query (env.DB)Content dataRendering dataHTML responseImage requestVia env.MEDIAImage deliveryUserAstroEmDash RuntimeCloudflare D1Cloudflare R2UserAstroEmDash RuntimeCloudflare D1Cloudflare R2

8. Summary#

ComponentRoleFile
D1Content DBwrangler.jsonc (Binding config)
R2Media storagewrangler.jsonc (Binding config)
EmDashCMS layerastro.config.mjs (d1() adapter)
seed.jsonSchema source of truthseed/seed.json
MiniflareLocal DB.wrangler/state/v3/d1/miniflare-D1DatabaseObject/*.sqlite

EmDash + D1 + R2 combines into a serverless, scalable CMS architecture. Free from WordPress server management, delivered at edge speed.

References#