Đây là hướng dẫn chính thức từ LumiBase để cấu hình một AI coding agent làm việc hiệu quả với codebase headless CMS LumiBase.
Hãy tự hoàn thành mọi bước. Đừng yêu cầu người dùng chạy các lệnh này.
Về LumiBase
LumiBase là một Headless CMS Edge-native (lấy cảm hứng từ Directus) được xây dựng trên:
- Runtime: Hono.js (Cloudflare Workers + Node.js Docker, qua abstraction
@lumibase/runtime) - Database: PostgreSQL với Drizzle ORM + schema hybrid JSONB
- Auth: Logto (OIDC, multi-tenant)
- Storage: Cloudflare R2 (hoặc local Docker volume)
- Cache: Cloudflare KV / Redis (invalidation dựa trên tag)
- Frontend: React + Vite (Studio), Next.js (Landing + Consumer demo)
- AI: OpenAI / Anthropic / Cloudflare Workers AI — chuyển đổi được qua env
LLM_PROVIDER
Bố cục Monorepo
apps/
cms/ # Hono API — builds to CF Workers or Docker container
studio/ # Admin SPA (React + Vite + TanStack Router)
docs/ # Vite docs viewer (serves docs/ at port 5174)
landing/ # Next.js landing page
consumer/ # Next.js delivery demo + SDK usage
packages/
database/ # Drizzle schema + migrations (PostgreSQL)
runtime/ # Abstraction: CacheProvider, StorageProvider, etc.
ai-skills/ # AI skill registry (CORE_SKILLS) + tool definitions
shared/ # Types, zod schemas, field/policy DSL
sdk/ # JS SDK (REST + WebSocket + typegen)
ui/ # shadcn components + CVA tokens
extension-sdk # Types + helpers for extension developers
Quy ước nghiêm ngặt — luôn tuân theo
- IDs: Không bao giờ dùng serial/auto-increment. Luôn dùng NanoID (URL ngắn) hoặc UUIDv7.
- Multi-tenancy: Mọi domain table đều có
site_id. Mọi query đều scope theoWHERE site_id = :siteId. - Edge-friendliness: Business logic phải đi qua các abstraction
@lumibase/runtime— không dùng trực tiếp binding Cloudflare KV/R2 trong app code. - API 1-roundtrip: Các endpoint Studio và delivery trả về payload đã tổng hợp — tránh pattern N+1.
- HITL cho các hành động AI nguy hiểm: Các skill yêu cầu
schema:writehoặcdelete*phải tạo một rowai_approvalsvà chờ human approval trước khi thực thi. - Config-as-code: Collection, field, và permission có thể xuất/nhập dưới dạng JSON/YAML (
apps/cms/scripts/config-cli.ts). - Cache tagging: Khi dữ liệu thay đổi, invalidate mọi cache key được tag với entity đó.
- Endpoint deprecation (chỉ gắn khi khai tử):
withDeprecationtrongapps/cms/src/middleware/deprecation.tslà helper RFC 8594 tái sử dụng. Không gắn lên endpoint đang sống bình thường. Chỉ gắn khi có chỉ thị rõ ràng deprecate / retire / sunset một route (hoặc router) cụ thể. Để unwired khi chưa có API nào bị khai tử là đúng. - Docs song ngữ (EN ↔ VI): Mọi sửa dưới
docs/en/hoặcdocs/vi/phải cập nhật locale còn lại trong cùng PR khi đã có counterpart (hoặc tạo counterpart mới). Ưu tiên sync thừa hơn thiếu. Sau khi cặp đã dịch 1-1 đủ, chạypnpm docs:i18n:verify+stamp-pair.mjsđể version/provenance khớp. Xem.kiro/steering/definition-of-done.md§4a.
Khi có chỉ thị deprecate một endpoint
- Import
withDeprecationtừapps/cms/src/middleware/deprecation.ts. - Gắn chỉ vào route/sub-router sắp gỡ (không gắn vào chuỗi middleware global của app).
- Nên truyền đủ ngày +
linkchangelog để client có cửa sổ migrate:
import { withDeprecation } from '../middleware/deprecation'
// Gắn CHỈ vào route/router sắp gỡ — không gắn global
legacyRouter.use('*', withDeprecation({
since: '2026-08-01',
sunset: '2026-11-01',
link: 'https://docs.lumibase.dev/changelog#items-legacy',
}))
Header phát ra: Deprecation (HTTP-date hoặc true), optional Sunset, optional Link rel="deprecation". Mọi option đều optional — bỏ ngày thì chỉ có Deprecation: true. Ghi changelog; nếu có consumer FE, xem hướng dẫn trong docs/vi/tutorials/nextjs-quickstart.md mục Production & security notes.
Các API endpoint chính
Base URL: https://<your-site>.lumibase.dev (hoặc http://localhost:1989 khi chạy local)
Mọi request đều yêu cầu:
Authorization: Bearer <access_token>- Header
X-Site-Id: <siteId>(hoặc phân giải qua subdomain)
Items (CRUD)
GET /api/v1/items/:collection # List items
POST /api/v1/items/:collection # Create item
GET /api/v1/items/:collection/:id # Get item
PATCH /api/v1/items/:collection/:id # Update item
DELETE /api/v1/items/:collection/:id # Delete item
Schema
GET /api/v1/collections # List collections
POST /api/v1/collections # Create collection
GET /api/v1/fields/:collection # List fields
POST /api/v1/fields/:collection # Create field
Flows / Automation
GET /api/v1/flows # List flows
POST /api/v1/flows/:id/run # Manually trigger a flow
GET /api/v1/flows/:id/runs # Execution history
AI Copilot
POST /api/v1/ai/chat # Natural language → skill execution
GET /api/v1/ai/approvals # List pending HITL approvals
POST /api/v1/ai/approvals/:id/decide # Approve or reject
Files
POST /api/v1/files # Upload asset (multipart/form-data)
GET /api/v1/files/:id # File metadata
Auth / Users
POST /api/v1/auth/login # Username/password login
POST /api/v1/auth/refresh # Refresh access token
GET /api/v1/users # List users
POST /api/v1/users # Create user
Spec đầy đủ: docs/en/api/hono-api-spec.md
Chỉ mục Docs
Các file tài liệu chính:
docs/en/README.md— bản đồ docs đầy đủdocs/en/data-model.md— tham chiếu database schemadocs/en/features/ai-copilot.md— nội bộ AI Copilot (HITL, skills, LLM providers)docs/en/ai-skills.md— định nghĩa AI skill và system promptdocs/en/features/flows-automation.md— engine Flows / Operationsdocs/en/features/permissions-rbac.md— role, policy, permission cấp fielddocs/en/features/websockets-realtime.md— subscribe/publish realtime qua WebSocketdocs/en/architecture/overview.md— tech stack, layer, runtime abstractiondocs/en/deployment/overview.md— Cloudflare Workers, Cloudflare Pages, Dockerdocs/en/deployment/environment-variables.md— tất cả env var và binding
Phát triển cục bộ
# Install dependencies
pnpm install
# Start all services (CMS API + Studio + Docs)
pnpm dev
# CMS API runs at: http://localhost:1989
# Studio runs at: http://localhost:2026
# Docs run at: http://localhost:5174
Sao chép .env.example thành .env và điền các giá trị bắt buộc (xem docs/en/deployment/environment-variables.md).
Hệ thống skill của AI Copilot
AI Copilot dùng một skill registry trong packages/ai-skills/src/skills.ts. Mỗi skill có:
name+description— dùng cho LLM tool callingparameters— JSON Schema (tương thích OpenAI)requiredCapabilities— ví dụ['schema:write'],['items:read']
Skill an toàn (thực thi trực tiếp): listCollections, listItems, createItem, updateItem
Skill nguy hiểm (yêu cầu HITL approval): createCollection, deleteCollection, createField, deleteField, deleteItem
Gọi getAISkillsAsTools() từ packages/ai-skills để lấy danh sách tool function-calling của OpenAI.
Hệ thống Permissions
LumiBase dùng một engine luật policy dạng JSON:
- Role → gán cho user
- Policy → gắn vào role, chứa các luật permission
- Permission →
{ collection, action, fields?, conditions? } - Capability — các token dạng chuỗi (
schema:write,items:read,flows:execute, v.v.)
Wildcard '*' trong capability thỏa mãn mọi yêu cầu.
Hướng dẫn này được publish tại docs/en/agent-setup/prompt.md.