@beechcms/cms 0.4.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/bin/cli.mjs +70 -0
- package/bin/create.mjs +407 -0
- package/bin/templates/blog.ts +35 -0
- package/bin/templates/contact.ts +23 -0
- package/bin/templates/empty.ts +41 -0
- package/bin/templates/gallery.ts +16 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
**BeechCMS** is a precision-engineered, solo-developer headless CMS built for developers who deliver high-performance websites for clients with **zero infrastructure overhead**.
|
|
4
|
+
|
|
5
|
+
The pitch is simple: you build the site, you hand it over, and your client can manage their own content forever — with **zero hosting costs**. No monthly subscriptions, no server bills, no maintenance contract needed just to keep the lights on.
|
|
6
|
+
|
|
7
|
+
This is possible because BeechCMS runs entirely on **Cloudflare's free tier** — Workers for the API, D1 (SQLite at the edge) for the database, and R2 for media storage. A Cloudflare account is all the infrastructure a client ever needs.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why Beech?
|
|
12
|
+
|
|
13
|
+
### Zero running costs for your clients
|
|
14
|
+
|
|
15
|
+
Cloudflare's free tier covers D1, R2, and Workers for the vast majority of real-world content sites. You deliver a fully self-managed product — dashboard, API, media uploads — and the client pays nothing to keep it running. That's a compelling offer.
|
|
16
|
+
|
|
17
|
+
### Native SQL Performance
|
|
18
|
+
Unlike other "flexible" CMSs that store data in slow JSON blobs, Beech generates **dedicated SQL tables** for every content type. Enjoy native B-Tree indexing, `REAL` and `INTEGER` types for mathematical operations, and ultra-fast queries.
|
|
19
|
+
|
|
20
|
+
### Schema-as-Code
|
|
21
|
+
Define your content model once in TypeScript. The **Botanical Engine** compiles your definitions into deterministic SQL DDL. Run `beech seed:load` and your database schema is automatically synchronized. No manual migrations, no manual SQL, no schema drift.
|
|
22
|
+
|
|
23
|
+
### Works as a dependency, not a boilerplate
|
|
24
|
+
|
|
25
|
+
Your project is four files. The BeechCMS engine, dashboard, and API live inside `node_modules/@beechcms/api`. Update with `npm update @beechcms/api`.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx @beechcms/cms
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The interactive wizard scaffolds a ready-to-use project in seconds. For everything from configuration to deployment, see the **[Developer Guide](./docs/guide.md)**.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## The Botanical Engine
|
|
40
|
+
|
|
41
|
+
The heart of BeechCMS is the **Botanical Engine**, a high-performance **Schema Compiler** that bridges the gap between TypeScript definitions and SQL infrastructure.
|
|
42
|
+
|
|
43
|
+
Instead of generic document storage, the Engine analyzes your **Seeds** (content types) and compiles them into **dedicated SQL tables** within Cloudflare D1. Every field you define becomes a native, type-safe SQL column, allowing for:
|
|
44
|
+
|
|
45
|
+
- **Native Performance**: Real B-Tree indices and FTS5 virtual tables for ultra-fast filtering and full-text search.
|
|
46
|
+
- **Data Integrity**: Native SQL types (REAL, INTEGER, TEXT) with CHECK constraints for robust data handling.
|
|
47
|
+
- **Zero-Manual SQL**: Deterministic DDL generation—I define the schema in code, and the Engine handles the database synchronization.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Tech Stack
|
|
52
|
+
|
|
53
|
+
| Layer | Technology |
|
|
54
|
+
|---|---|
|
|
55
|
+
| Edge runtime | Cloudflare Workers (V8 Isolates) |
|
|
56
|
+
| API framework | Hono v4 |
|
|
57
|
+
| Database | Cloudflare D1 (SQLite at the edge) |
|
|
58
|
+
| Object storage | Cloudflare R2 (zero egress cost) |
|
|
59
|
+
| Shared logic | `@beechcms/core` — Botanical Engine, types, validation |
|
|
60
|
+
| Dashboard | React 19 + Vite 7 |
|
|
61
|
+
| UI | Tailwind CSS v4 + Shadcn/ui |
|
|
62
|
+
| Server state | TanStack Query v5 |
|
|
63
|
+
| Rich text | TipTap v3 + KaTeX |
|
|
64
|
+
| Auth | `jose` JWT + bcryptjs |
|
|
65
|
+
| Validation | Zod v4 |
|
|
66
|
+
| Testing | Vitest v3 |
|
|
67
|
+
| Build orchestration | Turborepo v2 |
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
## Documentation
|
|
72
|
+
|
|
73
|
+
| Document | Description |
|
|
74
|
+
|---|---|
|
|
75
|
+
| [Developer Guide](./docs/guide.md) | End-to-end guide: scaffolding, seeds, API consumption, deployment |
|
|
76
|
+
| [Architecture](./docs/nuovidocs/architecture.md) | Monorepo topology, Botanical Engine data flow, D1 model |
|
|
77
|
+
| [API Reference](./docs/nuovidocs/api-reference.md) | Auth, Content CRUD, Media Engine, Public API, rate limiting |
|
|
78
|
+
| [Frontend Guide](./docs/nuovidocs/frontend-guide.md) | FieldRenderer registry, TanStack Query patterns, adding field types |
|
|
79
|
+
| [System Map](./docs/SYSTEM_MAP.md) | Folder structure, conventions, and architectural constraints |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
# Faq about BeechCMS
|
|
83
|
+
## Why "Beech"?
|
|
84
|
+
|
|
85
|
+
One afternoon I was staring at half a CMS with no name. I'd spent weeks building my desk setup — monitors, peripherals, the works — and the last thing I added was a beech wood desktop. I cut it, shaped it, sanded it, finished it until it was exactly right.
|
|
86
|
+
|
|
87
|
+
I was sitting at that desk trying to think of a name, looked to the side, and saw the wood. Beech. And then it clicked — seeds, branches, the forest, the fruit. The whole metaphor was already there in the project: content types are seeds, fields are branches, the data that grows from them is the fruit. The name took about three seconds.
|
|
88
|
+
|
|
89
|
+
Sometimes the best names aren't invented. They're found.
|
|
90
|
+
|
|
91
|
+
## Why I Built This
|
|
92
|
+
|
|
93
|
+
In 2025 I lost a €2,000 contract for a React showcase site for a construction company. The client needed two things beyond a static site: a blog where they could post photos of new builds, and a contact form. Simple requests — but they turned the project into a problem.
|
|
94
|
+
|
|
95
|
+
The tools that existed were either too heavy (WordPress, which the client had already had a bad experience with), too expensive once you added hosting and a managed database, or simply not designed to work alongside a modern React frontend without standing up a dedicated backend. The monthly running costs pushed my quote above what a larger agency — one that already had its own internal tooling — could offer. I lost the contract.
|
|
96
|
+
|
|
97
|
+
That was the moment I understood the real gap. Small agencies and freelancers don't lose on talent or quality. They lose because they don't have the same leverage as larger competitors who've already amortized the cost of building their own CMS. I decided to build mine.
|
|
98
|
+
|
|
99
|
+
**Why Cloudflare?** I was already looking for an alternative to Vercel that didn't require a paid plan for commercial projects. When I discovered that Cloudflare's free tier included not just Workers but also D1 (a relational database at the edge) and R2 (S3-compatible object storage), the whole architecture became clear. A full CMS backend — API, database, media storage, auth — with zero monthly cost for the client.
|
|
100
|
+
|
|
101
|
+
**Why the Botanical Engine?** I built the Botanical Engine as a high-performance **Schema Compiler**. It bridges the gap between the flexibility of a CMS and the power of a relational database. Instead of storing data in generic blobs, it compiles TypeScript definitions into native SQL tables and columns. This ensures rigid data integrity (crucial for things like financial records) and unlocks massive performance gains by leveraging native D1 indexing. This true relational model maintains the simplicity of "Schema-as-Code" while allowing for advanced features like cross-seed relations and complex aggregations.
|
|
102
|
+
|
|
103
|
+
**What I learned building it.** BeechCMS is my first serious serverless project. I had no prior experience with Cloudflare Workers, edge computing, or D1. Everything I know about this stack I learned by building this — reading documentation, hitting limits, understanding why they exist, and finding the right abstractions. The project is currently in active development toward a public 1.0 release and is already available on npm.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
_BeechCMS — Precision-engineered content infrastructure for the edge._
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
import { execSync } from 'node:child_process'
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { resolve } from 'node:path'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const [,, command, ...args] = process.argv
|
|
10
|
+
|
|
11
|
+
const COMMANDS = {
|
|
12
|
+
build: cmdBuild,
|
|
13
|
+
'seed:load': cmdSeedLoad,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function help() {
|
|
17
|
+
console.log(`
|
|
18
|
+
beech <command> [options]
|
|
19
|
+
|
|
20
|
+
Commands:
|
|
21
|
+
build Rebuild @beechcms/core after editing seeds.ts
|
|
22
|
+
seed:load Create/update DB tables from SEED_REGISTRY
|
|
23
|
+
--dry-run Print SQL without executing
|
|
24
|
+
--diff Show schema differences vs current DB
|
|
25
|
+
--remote Execute against remote D1 (default: local)
|
|
26
|
+
--db <name> Override D1 database name
|
|
27
|
+
|
|
28
|
+
Run npx beech-cms to scaffold a new project.
|
|
29
|
+
`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cmdBuild() {
|
|
33
|
+
const corePath = resolve(process.cwd(), 'packages', 'core')
|
|
34
|
+
|
|
35
|
+
if (!existsSync(corePath)) {
|
|
36
|
+
console.error(
|
|
37
|
+
'\nError: packages/core not found.\n' +
|
|
38
|
+
'Make sure you are running this command from the root of a BeechCMS project.\n'
|
|
39
|
+
)
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log('\nBuilding @beechcms/core…\n')
|
|
44
|
+
try {
|
|
45
|
+
execSync('npm run build -w @beechcms/core', { stdio: 'inherit' })
|
|
46
|
+
console.log('\n✔ @beechcms/core built — your seed changes are now live.\n')
|
|
47
|
+
} catch {
|
|
48
|
+
console.error('\nBuild failed. Check the output above for errors.\n')
|
|
49
|
+
process.exit(1)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function cmdSeedLoad(args) {
|
|
54
|
+
const dryRun = args.includes('--dry-run')
|
|
55
|
+
const diff = args.includes('--diff')
|
|
56
|
+
const remote = args.includes('--remote')
|
|
57
|
+
const dbIdx = args.indexOf('--db')
|
|
58
|
+
const db = dbIdx !== -1 ? args[dbIdx + 1] : undefined
|
|
59
|
+
|
|
60
|
+
const { seedLoad } = await import('@beechcms/cli')
|
|
61
|
+
await seedLoad({ dryRun, diff, local: !remote, db })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const handler = COMMANDS[command]
|
|
65
|
+
if (!handler) {
|
|
66
|
+
help()
|
|
67
|
+
if (command) process.exit(1)
|
|
68
|
+
} else {
|
|
69
|
+
await handler(args)
|
|
70
|
+
}
|
package/bin/create.mjs
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
import * as p from '@clack/prompts'
|
|
5
|
+
import pc from 'picocolors'
|
|
6
|
+
import { execSync } from 'node:child_process'
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { resolve, join } from 'node:path'
|
|
9
|
+
import { randomBytes } from 'node:crypto'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
import { dirname } from 'node:path'
|
|
12
|
+
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
14
|
+
|
|
15
|
+
// ── Template registry ─────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
const TEMPLATES = {
|
|
18
|
+
blog: {
|
|
19
|
+
label: 'Blog',
|
|
20
|
+
hint: 'posts with rich text, cover image, tags and authors',
|
|
21
|
+
file: 'blog.ts',
|
|
22
|
+
registryEntries: ['posts: POST_SEED', 'authors: AUTHOR_SEED'],
|
|
23
|
+
},
|
|
24
|
+
gallery: {
|
|
25
|
+
label: 'Gallery',
|
|
26
|
+
hint: 'media items with image, tags and featured flag',
|
|
27
|
+
file: 'gallery.ts',
|
|
28
|
+
registryEntries: ['gallery: GALLERY_SEED'],
|
|
29
|
+
},
|
|
30
|
+
contact: {
|
|
31
|
+
label: 'Contact',
|
|
32
|
+
hint: 'public form submissions with masked email and read status',
|
|
33
|
+
file: 'contact.ts',
|
|
34
|
+
registryEntries: ['messages: MESSAGE_SEED'],
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function readTemplate(filename) {
|
|
39
|
+
return readFileSync(join(__dirname, 'templates', filename), 'utf8')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildSeedsFile(selectedKeys) {
|
|
43
|
+
const header = `import type { Seed } from '@beechcms/core'\n\n`
|
|
44
|
+
|
|
45
|
+
if (selectedKeys.length === 0) {
|
|
46
|
+
const example = readFileSync(join(__dirname, 'templates', 'empty.ts'), 'utf8')
|
|
47
|
+
return (
|
|
48
|
+
header +
|
|
49
|
+
example +
|
|
50
|
+
'\nexport const SEED_REGISTRY: Record<string, Seed> = {}\n\n' +
|
|
51
|
+
'export function getSeed(slug: string): Seed | null {\n' +
|
|
52
|
+
' return SEED_REGISTRY[slug] ?? null\n' +
|
|
53
|
+
'}\n'
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const blocks = selectedKeys.map((key) =>
|
|
58
|
+
readFileSync(join(__dirname, 'templates', TEMPLATES[key].file), 'utf8')
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const registryEntries = selectedKeys.flatMap((key) => TEMPLATES[key].registryEntries)
|
|
62
|
+
const registry =
|
|
63
|
+
'export const SEED_REGISTRY: Record<string, Seed> = {\n' +
|
|
64
|
+
registryEntries.map((e) => ` ${e},`).join('\n') +
|
|
65
|
+
'\n}\n'
|
|
66
|
+
|
|
67
|
+
const getSeed =
|
|
68
|
+
'\nexport function getSeed(slug: string): Seed | null {\n' +
|
|
69
|
+
' return SEED_REGISTRY[slug] ?? null\n' +
|
|
70
|
+
'}\n'
|
|
71
|
+
|
|
72
|
+
return header + blocks.join('\n') + '\n' + registry + getSeed
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
function generateSecret(bytes = 32) {
|
|
78
|
+
return randomBytes(bytes).toString('hex')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function writeFile(path, content) {
|
|
82
|
+
writeFileSync(path, content, 'utf8')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function buildWorkerTs() {
|
|
86
|
+
return `/// <reference types="@cloudflare/workers-types" />
|
|
87
|
+
import { createBeechApp } from '@beechcms/api'
|
|
88
|
+
import { seeds } from './seeds'
|
|
89
|
+
|
|
90
|
+
export default createBeechApp({ seeds })
|
|
91
|
+
`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function buildSeedsTs(selectedKeys) {
|
|
95
|
+
return buildSeedsFile(selectedKeys)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function buildPackageJson(name) {
|
|
99
|
+
return JSON.stringify({
|
|
100
|
+
name,
|
|
101
|
+
version: '0.1.0',
|
|
102
|
+
private: true,
|
|
103
|
+
type: 'module',
|
|
104
|
+
scripts: {
|
|
105
|
+
dev: 'wrangler dev --port 8789',
|
|
106
|
+
deploy: 'wrangler deploy --minify',
|
|
107
|
+
'db:migrate:local': 'wrangler d1 migrations apply ' + name + '-db --local',
|
|
108
|
+
'db:reset:local': 'node -e "require(\'fs\').rmSync(\'.wrangler/state\',{recursive:true,force:true})" && npm run db:migrate:local',
|
|
109
|
+
},
|
|
110
|
+
dependencies: {
|
|
111
|
+
'@beechcms/api': '^0.4.0-preview.1',
|
|
112
|
+
'@beechcms/core': '^0.4.0-preview.1',
|
|
113
|
+
},
|
|
114
|
+
devDependencies: {
|
|
115
|
+
'@cloudflare/workers-types': '^4.0.0',
|
|
116
|
+
wrangler: '^4.0.0',
|
|
117
|
+
typescript: '^5.0.0',
|
|
118
|
+
},
|
|
119
|
+
}, null, 2) + '\n'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function buildWranglerJsonc(cfg) {
|
|
123
|
+
return `{
|
|
124
|
+
"name": "${cfg.name}-api",
|
|
125
|
+
"main": "worker.ts",
|
|
126
|
+
"compatibility_date": "2025-01-01",
|
|
127
|
+
|
|
128
|
+
"vars": {
|
|
129
|
+
"JWT_SECRET": "${cfg.jwtSecret}",
|
|
130
|
+
"CORS_ORIGINS": "${cfg.corsOrigins}",
|
|
131
|
+
"PUBLIC_READ_API_KEY": "${cfg.publicReadKey}",
|
|
132
|
+
"PUBLIC_WRITE_API_KEY": "${cfg.publicWriteKey}",
|
|
133
|
+
"APP_URL": "${cfg.appUrl || 'http://localhost:5173'}"
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
"d1_databases": [
|
|
137
|
+
{
|
|
138
|
+
"binding": "DB",
|
|
139
|
+
"database_name": "${cfg.d1Name}",
|
|
140
|
+
"database_id": "${cfg.d1Id}",
|
|
141
|
+
"migrations_dir": "node_modules/@beechcms/api/migrations"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
|
|
145
|
+
"r2_buckets": [
|
|
146
|
+
{
|
|
147
|
+
"binding": "MEDIA_BUCKET",
|
|
148
|
+
"bucket_name": "${cfg.r2Bucket}"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
`
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function buildDevVars(cloudflare) {
|
|
156
|
+
if (cloudflare) {
|
|
157
|
+
return [
|
|
158
|
+
`R2_ACCESS_KEY_ID=${cloudflare.r2AccessKey}`,
|
|
159
|
+
`R2_SECRET_ACCESS_KEY=${cloudflare.r2SecretKey}`,
|
|
160
|
+
`R2_ENDPOINT=${cloudflare.r2Endpoint}`,
|
|
161
|
+
`R2_BUCKET_NAME=${cloudflare.r2Bucket}`,
|
|
162
|
+
].join('\n') + '\n'
|
|
163
|
+
}
|
|
164
|
+
return [
|
|
165
|
+
'# Fill these in before starting the dev server.',
|
|
166
|
+
'# Guide: https://developers.cloudflare.com/r2/api/s3/tokens/',
|
|
167
|
+
'R2_ACCESS_KEY_ID=',
|
|
168
|
+
'R2_SECRET_ACCESS_KEY=',
|
|
169
|
+
'R2_ENDPOINT=https://<YOUR_ACCOUNT_ID>.r2.cloudflarestorage.com',
|
|
170
|
+
'R2_BUCKET_NAME=',
|
|
171
|
+
].join('\n') + '\n'
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function buildTsConfig() {
|
|
175
|
+
return JSON.stringify({
|
|
176
|
+
compilerOptions: {
|
|
177
|
+
target: 'ES2022',
|
|
178
|
+
module: 'ES2022',
|
|
179
|
+
moduleResolution: 'bundler',
|
|
180
|
+
strict: true,
|
|
181
|
+
types: ['@cloudflare/workers-types'],
|
|
182
|
+
},
|
|
183
|
+
include: ['*.ts'],
|
|
184
|
+
}, null, 2) + '\n'
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ── Cloudflare prompts ────────────────────────────────────────────────────────
|
|
188
|
+
|
|
189
|
+
async function askCloudflareConfig(name) {
|
|
190
|
+
p.note(
|
|
191
|
+
[
|
|
192
|
+
'You will need a free Cloudflare account with:',
|
|
193
|
+
'',
|
|
194
|
+
` D1 database → ${pc.cyan('npx wrangler d1 create ' + name + '-db')}`,
|
|
195
|
+
` R2 bucket → ${pc.cyan('npx wrangler r2 bucket create ' + name + '-media')}`,
|
|
196
|
+
'',
|
|
197
|
+
'Docs: https://developers.cloudflare.com/d1/',
|
|
198
|
+
' https://developers.cloudflare.com/r2/',
|
|
199
|
+
].join('\n'),
|
|
200
|
+
'Prerequisites'
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
const accountId = await p.text({
|
|
204
|
+
message: 'Cloudflare Account ID',
|
|
205
|
+
hint: 'dash.cloudflare.com → right sidebar → "Account ID"',
|
|
206
|
+
validate: (v) => { if (!v.trim()) return 'Required' },
|
|
207
|
+
})
|
|
208
|
+
if (p.isCancel(accountId)) return null
|
|
209
|
+
|
|
210
|
+
const d1Name = await p.text({
|
|
211
|
+
message: 'D1 Database name',
|
|
212
|
+
initialValue: `${name}-db`,
|
|
213
|
+
validate: (v) => { if (!v.trim()) return 'Required' },
|
|
214
|
+
})
|
|
215
|
+
if (p.isCancel(d1Name)) return null
|
|
216
|
+
|
|
217
|
+
const d1Id = await p.text({
|
|
218
|
+
message: 'D1 Database ID',
|
|
219
|
+
placeholder: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
|
220
|
+
hint: `Run: npx wrangler d1 create ${d1Name} — copy the "database_id" from the output`,
|
|
221
|
+
validate: (v) => { if (!v.trim()) return 'Required — create the D1 database first and paste its ID here' },
|
|
222
|
+
})
|
|
223
|
+
if (p.isCancel(d1Id)) return null
|
|
224
|
+
|
|
225
|
+
const r2Bucket = await p.text({
|
|
226
|
+
message: 'R2 Bucket name',
|
|
227
|
+
initialValue: `${name}-media`,
|
|
228
|
+
validate: (v) => { if (!v.trim()) return 'Required' },
|
|
229
|
+
})
|
|
230
|
+
if (p.isCancel(r2Bucket)) return null
|
|
231
|
+
|
|
232
|
+
p.note(
|
|
233
|
+
[
|
|
234
|
+
'Create an R2 API token:',
|
|
235
|
+
' Cloudflare Dashboard → R2 → "Manage R2 API Tokens"',
|
|
236
|
+
` → Create Token → Object Read & Write → bucket: ${r2Bucket}`,
|
|
237
|
+
].join('\n'),
|
|
238
|
+
'R2 credentials'
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
const r2AccessKey = await p.text({
|
|
242
|
+
message: 'R2 Access Key ID',
|
|
243
|
+
validate: (v) => { if (!v.trim()) return 'Required' },
|
|
244
|
+
})
|
|
245
|
+
if (p.isCancel(r2AccessKey)) return null
|
|
246
|
+
|
|
247
|
+
const r2SecretKey = await p.password({
|
|
248
|
+
message: 'R2 Secret Access Key',
|
|
249
|
+
validate: (v) => { if (!v.trim()) return 'Required' },
|
|
250
|
+
})
|
|
251
|
+
if (p.isCancel(r2SecretKey)) return null
|
|
252
|
+
|
|
253
|
+
const appUrl = await p.text({
|
|
254
|
+
message: 'Production dashboard URL (for CORS)',
|
|
255
|
+
placeholder: `https://cms.${name}.com`,
|
|
256
|
+
hint: 'Leave empty to configure later in wrangler.jsonc',
|
|
257
|
+
})
|
|
258
|
+
if (p.isCancel(appUrl)) return null
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
accountId: accountId.trim(),
|
|
262
|
+
d1Name: d1Name.trim(),
|
|
263
|
+
d1Id: d1Id.trim(),
|
|
264
|
+
r2Bucket: r2Bucket.trim(),
|
|
265
|
+
r2AccessKey: r2AccessKey.trim(),
|
|
266
|
+
r2SecretKey: r2SecretKey.trim(),
|
|
267
|
+
r2Endpoint: `https://${accountId.trim()}.r2.cloudflarestorage.com`,
|
|
268
|
+
appUrl: appUrl?.trim() ?? '',
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ── Main ──────────────────────────────────────────────────────────────────────
|
|
273
|
+
|
|
274
|
+
async function main() {
|
|
275
|
+
console.log()
|
|
276
|
+
p.intro(pc.bgGreen(pc.black(' beech-cms ')))
|
|
277
|
+
|
|
278
|
+
// Project name
|
|
279
|
+
const projectName = await p.text({
|
|
280
|
+
message: 'Project name',
|
|
281
|
+
placeholder: 'my-website',
|
|
282
|
+
validate: (v) => {
|
|
283
|
+
if (!v.trim()) return 'Required'
|
|
284
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(v.trim())) return 'Lowercase letters, numbers and hyphens only'
|
|
285
|
+
},
|
|
286
|
+
})
|
|
287
|
+
if (p.isCancel(projectName)) { p.cancel('Cancelled'); process.exit(0) }
|
|
288
|
+
const name = projectName.trim()
|
|
289
|
+
const targetDir = resolve(process.cwd(), name)
|
|
290
|
+
|
|
291
|
+
if (existsSync(targetDir)) {
|
|
292
|
+
p.cancel(`Directory '${name}' already exists. Choose a different name or delete the folder.`)
|
|
293
|
+
process.exit(1)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Content types
|
|
297
|
+
const selectedTemplates = await p.multiselect({
|
|
298
|
+
message: 'Which content types do you need?',
|
|
299
|
+
hint: 'Space to select, Enter to confirm. You can add more later in seeds.ts',
|
|
300
|
+
options: [
|
|
301
|
+
{ value: 'blog', label: 'Blog', hint: 'posts with rich text, cover image, tags and authors' },
|
|
302
|
+
{ value: 'gallery', label: 'Gallery', hint: 'media items with image, tags and featured flag' },
|
|
303
|
+
{ value: 'contact', label: 'Contact', hint: 'public form submissions with masked email and read status' },
|
|
304
|
+
],
|
|
305
|
+
required: false,
|
|
306
|
+
})
|
|
307
|
+
if (p.isCancel(selectedTemplates)) { p.cancel('Cancelled'); process.exit(0) }
|
|
308
|
+
|
|
309
|
+
// Cloudflare now or later?
|
|
310
|
+
const configureNow = await p.confirm({
|
|
311
|
+
message: 'Configure Cloudflare credentials now?',
|
|
312
|
+
hint: 'Choose "No" to scaffold the project and fill in the values later',
|
|
313
|
+
initialValue: true,
|
|
314
|
+
})
|
|
315
|
+
if (p.isCancel(configureNow)) { p.cancel('Cancelled'); process.exit(0) }
|
|
316
|
+
|
|
317
|
+
let cloudflare = null
|
|
318
|
+
if (configureNow) {
|
|
319
|
+
cloudflare = await askCloudflareConfig(name)
|
|
320
|
+
if (!cloudflare) { p.cancel('Cancelled'); process.exit(0) }
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const jwtSecret = generateSecret(32)
|
|
324
|
+
const publicReadKey = generateSecret(16)
|
|
325
|
+
const publicWriteKey = generateSecret(16)
|
|
326
|
+
|
|
327
|
+
const corsOrigins = cloudflare
|
|
328
|
+
? ['http://localhost:5173', 'http://localhost:5174', cloudflare.appUrl]
|
|
329
|
+
.filter(Boolean).join(',')
|
|
330
|
+
: 'http://localhost:5173,http://localhost:5174'
|
|
331
|
+
|
|
332
|
+
// Scaffold
|
|
333
|
+
const s = p.spinner()
|
|
334
|
+
s.start('Scaffolding project…')
|
|
335
|
+
|
|
336
|
+
mkdirSync(targetDir, { recursive: true })
|
|
337
|
+
|
|
338
|
+
writeFile(join(targetDir, 'seeds.ts'), buildSeedsTs(selectedTemplates))
|
|
339
|
+
writeFile(join(targetDir, 'worker.ts'), buildWorkerTs())
|
|
340
|
+
writeFile(join(targetDir, 'package.json'), buildPackageJson(name))
|
|
341
|
+
writeFile(join(targetDir, 'tsconfig.json'), buildTsConfig())
|
|
342
|
+
writeFile(join(targetDir, 'wrangler.jsonc'), buildWranglerJsonc({
|
|
343
|
+
name,
|
|
344
|
+
d1Name: cloudflare?.d1Name ?? `${name}-db`,
|
|
345
|
+
d1Id: cloudflare?.d1Id ?? 'FILL_IN_YOUR_D1_DATABASE_ID',
|
|
346
|
+
r2Bucket: cloudflare?.r2Bucket ?? `${name}-media`,
|
|
347
|
+
jwtSecret,
|
|
348
|
+
corsOrigins,
|
|
349
|
+
publicReadKey,
|
|
350
|
+
publicWriteKey,
|
|
351
|
+
appUrl: cloudflare?.appUrl ?? '',
|
|
352
|
+
}))
|
|
353
|
+
writeFile(join(targetDir, '.dev.vars'), buildDevVars(cloudflare))
|
|
354
|
+
writeFile(join(targetDir, '.gitignore'), '.wrangler\nnode_modules\n.dev.vars\ndist\n')
|
|
355
|
+
|
|
356
|
+
s.stop('Project scaffolded')
|
|
357
|
+
|
|
358
|
+
// Init git
|
|
359
|
+
s.start('Initialising git repository…')
|
|
360
|
+
try {
|
|
361
|
+
execSync(`git -C "${targetDir}" init -q`, { stdio: 'pipe' })
|
|
362
|
+
execSync(`git -C "${targetDir}" add -A`, { stdio: 'pipe' })
|
|
363
|
+
execSync(`git -C "${targetDir}" commit -q -m "feat: initialise BeechCMS project"`, { stdio: 'pipe' })
|
|
364
|
+
s.stop('Git initialised')
|
|
365
|
+
} catch {
|
|
366
|
+
s.stop('Git skipped (not available)')
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const pendingConfig = !cloudflare
|
|
370
|
+
const step = (n) => pc.bold(String(n + (pendingConfig ? 1 : 0)))
|
|
371
|
+
console.log()
|
|
372
|
+
p.note(
|
|
373
|
+
[
|
|
374
|
+
`${pc.bold('1. Enter the project')}`,
|
|
375
|
+
` ${pc.cyan('cd ' + name)}`,
|
|
376
|
+
'',
|
|
377
|
+
`${pc.bold('2. Install dependencies')}`,
|
|
378
|
+
` ${pc.cyan('npm install')}`,
|
|
379
|
+
'',
|
|
380
|
+
...(pendingConfig ? [
|
|
381
|
+
`${pc.bold('3. Complete Cloudflare configuration')} ${pc.yellow('← pending')}`,
|
|
382
|
+
` Edit ${pc.underline('wrangler.jsonc')} → fill in ${pc.yellow('database_id')} and R2 bucket`,
|
|
383
|
+
` Edit ${pc.underline('.dev.vars')} → fill in R2 credentials`,
|
|
384
|
+
` Guide: https://developers.cloudflare.com/d1/`,
|
|
385
|
+
'',
|
|
386
|
+
] : []),
|
|
387
|
+
`${step(3)}. Run local migrations`,
|
|
388
|
+
` ${pc.cyan('npm run db:migrate:local')}`,
|
|
389
|
+
'',
|
|
390
|
+
`${step(4)}. Start the dev server`,
|
|
391
|
+
` ${pc.cyan('npx wrangler dev')}`,
|
|
392
|
+
'',
|
|
393
|
+
`${step(5)}. Deploy to production`,
|
|
394
|
+
` ${pc.cyan('npm run deploy')}`,
|
|
395
|
+
'',
|
|
396
|
+
`${pc.dim('Your content types are defined in seeds.ts')}`,
|
|
397
|
+
`${pc.dim('JWT secret and API keys have been auto-generated.')}`,
|
|
398
|
+
].join('\n'),
|
|
399
|
+
'Next steps'
|
|
400
|
+
)
|
|
401
|
+
p.outro(pc.green(`✔ BeechCMS project ready — ${name}/`))
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
main().catch((err) => {
|
|
405
|
+
console.error(err)
|
|
406
|
+
process.exit(1)
|
|
407
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Post: blog article with rich text, cover image, tags and SEO */
|
|
2
|
+
export const POST_SEED: Seed = {
|
|
3
|
+
slug: 'posts',
|
|
4
|
+
label: 'Post',
|
|
5
|
+
labelPlural: 'Posts',
|
|
6
|
+
displayNameAlias: 'title',
|
|
7
|
+
allowPublicRead: true,
|
|
8
|
+
allowDrafts: true,
|
|
9
|
+
branches: [
|
|
10
|
+
{ id: 'pst_01', alias: 'title', label: 'Title', type: 'text', requiredOnCreate: true },
|
|
11
|
+
{ id: 'pst_02', alias: 'publishedAt', label: 'Published at', type: 'date' },
|
|
12
|
+
{ id: 'pst_03', alias: 'coverImage', label: 'Cover image', type: 'file' },
|
|
13
|
+
{ id: 'pst_04', alias: 'excerpt', label: 'Excerpt', type: 'text' },
|
|
14
|
+
{ id: 'pst_05', alias: 'tags', label: 'Tags', type: 'json', options: ['news', 'tutorial', 'release', 'guide', 'opinion'] },
|
|
15
|
+
{ id: 'pst_06', alias: 'body', label: 'Body', type: 'richtext' },
|
|
16
|
+
{ id: 'pst_07', alias: 'metaTitle', label: 'Meta title (SEO)', type: 'text' },
|
|
17
|
+
{ id: 'pst_08', alias: 'metaDescription', label: 'Meta description (SEO)', type: 'text' },
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Author: content creator profile with photo and social link */
|
|
22
|
+
export const AUTHOR_SEED: Seed = {
|
|
23
|
+
slug: 'authors',
|
|
24
|
+
label: 'Author',
|
|
25
|
+
labelPlural: 'Authors',
|
|
26
|
+
displayNameAlias: 'name',
|
|
27
|
+
allowPublicRead: true,
|
|
28
|
+
branches: [
|
|
29
|
+
{ id: 'aut_01', alias: 'name', label: 'Name', type: 'text', requiredOnCreate: true },
|
|
30
|
+
{ id: 'aut_02', alias: 'bio', label: 'Bio', type: 'text' },
|
|
31
|
+
{ id: 'aut_03', alias: 'photo', label: 'Photo', type: 'file' },
|
|
32
|
+
{ id: 'aut_04', alias: 'website', label: 'Website URL', type: 'text' },
|
|
33
|
+
{ id: 'aut_05', alias: 'active', label: 'Active', type: 'boolean' },
|
|
34
|
+
],
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message: public contact form submission.
|
|
3
|
+
*
|
|
4
|
+
* allowPublicPost: true — the Public API accepts POST requests without authentication,
|
|
5
|
+
* so any frontend form can submit directly to this seed.
|
|
6
|
+
* email visibility:masked — the email is stored in full but returned partially
|
|
7
|
+
* redacted in API responses (e.g. "jo**@example.com").
|
|
8
|
+
* email public:false — the email is never exposed through the Public API.
|
|
9
|
+
*/
|
|
10
|
+
export const MESSAGE_SEED: Seed = {
|
|
11
|
+
slug: 'messages',
|
|
12
|
+
label: 'Message',
|
|
13
|
+
labelPlural: 'Messages',
|
|
14
|
+
displayNameAlias: 'name',
|
|
15
|
+
allowPublicPost: true,
|
|
16
|
+
branches: [
|
|
17
|
+
{ id: 'msg_01', alias: 'name', label: 'Name', type: 'text', requiredOnCreate: true },
|
|
18
|
+
{ id: 'msg_02', alias: 'email', label: 'Email', type: 'text', requiredOnCreate: true, policies: { visibility: 'masked', public: false } },
|
|
19
|
+
{ id: 'msg_03', alias: 'subject', label: 'Subject', type: 'text', requiredOnCreate: true },
|
|
20
|
+
{ id: 'msg_04', alias: 'message', label: 'Message', type: 'richtext', requiredOnCreate: true },
|
|
21
|
+
{ id: 'msg_05', alias: 'read', label: 'Read', type: 'boolean' },
|
|
22
|
+
],
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Your seeds go here.
|
|
3
|
+
*
|
|
4
|
+
* A Seed defines a content type: its slug (used in API URLs), its display labels,
|
|
5
|
+
* and its branches (fields).
|
|
6
|
+
*
|
|
7
|
+
* Each Branch has:
|
|
8
|
+
* id — immutable database key (e.g. 'abc_01'). Never change this after
|
|
9
|
+
* the first migration or stored data will break.
|
|
10
|
+
* alias — the name used in API payloads (e.g. 'title'). Safe to rename.
|
|
11
|
+
* label — human-readable label shown in the dashboard.
|
|
12
|
+
* type — 'text' | 'number' | 'boolean' | 'date' | 'richtext' | 'file' | 'json'
|
|
13
|
+
*
|
|
14
|
+
* Seed-level flags:
|
|
15
|
+
* allowPublicRead — expose entries via the unauthenticated Public API (GET).
|
|
16
|
+
* allowPublicPost — accept submissions via the Public API (POST). Useful for forms.
|
|
17
|
+
* allowDrafts — enable a pending-draft workflow for this content type.
|
|
18
|
+
* displayNameAlias — which branch alias is used as the entry title in the dashboard.
|
|
19
|
+
*
|
|
20
|
+
* Branch policies (all optional):
|
|
21
|
+
* policies.visibility — 'full' (default) | 'masked' | 'hidden'
|
|
22
|
+
* policies.public — false to exclude the field from Public API responses
|
|
23
|
+
* policies.search — false to exclude the field from full-text search
|
|
24
|
+
*
|
|
25
|
+
* Example — uncomment and adapt to define your first content type:
|
|
26
|
+
*
|
|
27
|
+
* export const PROJECT_SEED: Seed = {
|
|
28
|
+
* slug: 'projects',
|
|
29
|
+
* label: 'Project',
|
|
30
|
+
* labelPlural: 'Projects',
|
|
31
|
+
* displayNameAlias: 'title',
|
|
32
|
+
* allowPublicRead: true,
|
|
33
|
+
* branches: [
|
|
34
|
+
* { id: 'prj_01', alias: 'title', label: 'Title', type: 'text', requiredOnCreate: true },
|
|
35
|
+
* { id: 'prj_02', alias: 'description', label: 'Description', type: 'text' },
|
|
36
|
+
* { id: 'prj_03', alias: 'coverImage', label: 'Cover image', type: 'file' },
|
|
37
|
+
* { id: 'prj_04', alias: 'tags', label: 'Tags', type: 'json' },
|
|
38
|
+
* { id: 'prj_05', alias: 'published', label: 'Published', type: 'boolean' },
|
|
39
|
+
* ],
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Gallery item: image or media asset with title, tags and featured flag */
|
|
2
|
+
export const GALLERY_SEED: Seed = {
|
|
3
|
+
slug: 'gallery',
|
|
4
|
+
label: 'Item',
|
|
5
|
+
labelPlural: 'Gallery',
|
|
6
|
+
displayNameAlias: 'title',
|
|
7
|
+
allowPublicRead: true,
|
|
8
|
+
branches: [
|
|
9
|
+
{ id: 'gal_01', alias: 'title', label: 'Title', type: 'text', requiredOnCreate: true },
|
|
10
|
+
{ id: 'gal_02', alias: 'description', label: 'Description', type: 'text' },
|
|
11
|
+
{ id: 'gal_03', alias: 'image', label: 'Image', type: 'file', requiredOnCreate: true },
|
|
12
|
+
{ id: 'gal_04', alias: 'tags', label: 'Tags', type: 'json' },
|
|
13
|
+
{ id: 'gal_05', alias: 'date', label: 'Date', type: 'date' },
|
|
14
|
+
{ id: 'gal_06', alias: 'featured', label: 'Featured', type: 'boolean' },
|
|
15
|
+
],
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@beechcms/cms",
|
|
3
|
+
"version": "0.4.0-preview.1",
|
|
4
|
+
"packageManager": "npm@11.9.0",
|
|
5
|
+
"description": "Edge-Native, Schema-Driven Headless CMS built on Cloudflare Workers, D1, and R2. Features the Botanical Engine for alias-stable field management, a modular widget layer, and a React + Vite admin dashboard.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"cms",
|
|
8
|
+
"headless-cms",
|
|
9
|
+
"cloudflare",
|
|
10
|
+
"cloudflare-workers",
|
|
11
|
+
"d1",
|
|
12
|
+
"edge",
|
|
13
|
+
"schema-driven",
|
|
14
|
+
"api-first",
|
|
15
|
+
"hono",
|
|
16
|
+
"react",
|
|
17
|
+
"turborepo"
|
|
18
|
+
],
|
|
19
|
+
"author": "Flavio De Musso",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/fdemusso/BeechCMS#readme",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/fdemusso/BeechCMS.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/fdemusso/BeechCMS/issues"
|
|
28
|
+
},
|
|
29
|
+
"workspaces": [
|
|
30
|
+
"apps/*",
|
|
31
|
+
"packages/*"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"bin/",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"bin": {
|
|
41
|
+
"beech-cms": "bin/create.mjs",
|
|
42
|
+
"beech": "bin/cli.mjs"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "turbo run dev --parallel",
|
|
46
|
+
"build": "turbo run build",
|
|
47
|
+
"test": "turbo run test",
|
|
48
|
+
"test:coverage": "turbo run test:coverage"
|
|
49
|
+
},
|
|
50
|
+
"type": "module",
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"shadcn": "^4.4.0",
|
|
53
|
+
"turbo": "^2.8.7",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@beechcms/cli": "^0.4.0-preview.1",
|
|
58
|
+
"@clack/prompts": "^0.9.1",
|
|
59
|
+
"picocolors": "^1.1.1"
|
|
60
|
+
}
|
|
61
|
+
}
|