Create new @sonicjs/core npm package with extracted core functionality: Package Structure: - packages/core/ - New core package directory - Modular exports: index, middleware, plugins, routes, services, templates, types, utils - Built with tsup for dual ESM/CJS output - TypeScript declarations included Documentation: - BREAKING_CHANGES.md - Breaking changes and migration guide - CODEBASE_AUDIT.md - Complete codebase analysis - DEPENDENCY_MAP.md - Dependency mapping and organization - PHASE_1_COMPLETE.md - Phase 1 completion summary - phase-1-core-extraction.md - Detailed extraction plan - phase-2-core-migration.md - Next phase migration plan Core Package Features: - Database schema and migrations - Authentication and permissions middleware - Plugin system infrastructure - API routes foundation - Core services (collections, content, media, cache) - Template rendering utilities - Type definitions for plugins and collections Next Steps (Phase 2): - Update main app to import from @sonicjs/core - Remove duplicated code from main app - Update all import paths - Verify build and tests ๐ค Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
SonicJS AI
A modern, TypeScript-first headless CMS built for Cloudflare's edge platform with Hono.js.
๐ Features
Core Platform
- โก Edge-First: Built specifically for Cloudflare Workers with global performance
- ๐ง Developer-Centric: Configuration over UI, TypeScript-first approach
- ๐ค AI-Friendly: Structured codebase designed for AI-assisted development
- ๐ Plugin System: Extensible architecture without core modifications
- ๐ฑ Modern Stack: Hono.js, TypeScript, D1, R2, and HTMX
Advanced Content Management (Stage 5)
- ๐ Rich Text Editor: TinyMCE integration with customizable toolbars
- ๐๏ธ Dynamic Fields: Custom field types (text, number, date, boolean, select, media)
- ๐ Content Versioning: Complete revision history with restore functionality
- โฐ Content Scheduling: Publish/unpublish automation with date controls
- ๐ Workflow System: Draft โ Review โ Published โ Archived with role-based permissions
- ๐พ Auto-Save: Automatic content saving every 30 seconds
- ๐๏ธ Live Preview: Real-time content preview before publishing
- ๐ Content Duplication: One-click content copying and templates
- ๐ก๏ธ XSS Protection: Comprehensive input validation and HTML escaping
๐ Technology Stack
Core Framework
- Hono.js - Ultrafast web framework for Cloudflare Workers
- TypeScript - Strict type safety throughout
- HTMX - Enhanced HTML for dynamic interfaces
Cloudflare Services
- D1 - SQLite database at the edge
- R2 - Object storage for media
- Workers - Serverless compute runtime
- KV - Key-value storage for caching
- Images API - Image optimization and transformation
Development Tools
- Vitest - Fast unit testing
- Playwright - End-to-end testing
- Wrangler - Local development and deployment
- Drizzle ORM - Type-safe database queries
๐ Quick Start
Prerequisites
- Node.js 20+
- Cloudflare account
- Wrangler CLI
Installation
# Clone the repository
git clone https://github.com/lane711/sonicjs-ai.git
cd sonicjs-ai
# Install dependencies
npm install
# Set up local development database
npm run db:migrate
# Start development server
npm run dev
Development Commands
# Start development server
npm run dev
# Run tests
npm test
# Run E2E tests
npm run test:e2e
# Build for production
npm run build
# Deploy to Cloudflare
npm run deploy
# Database operations
npm run db:generate # Generate migrations
npm run db:migrate # Apply migrations
npm run db:studio # Open database studio
๐ Project Structure
src/
โโโ routes/ # Hono.js route handlers
โ โโโ admin*.ts # Admin interface routes
โ โโโ api*.ts # REST API endpoints
โ โโโ auth.ts # Authentication routes
โโโ templates/ # HTML templates & components
โ โโโ layouts/ # Page layouts (admin, public)
โ โโโ pages/ # Full page templates
โ โโโ components/ # Reusable UI components
โโโ middleware/ # Hono.js middleware
โ โโโ auth.ts # Authentication & authorization
โโโ utils/ # Utility functions
โโโ scripts/ # Database & deployment scripts
โโโ migrations/ # Database migration files
โโโ tests/ # Unit & integration tests
โโโ e2e/ # End-to-end test suites
๐ง Content Management
Creating Collections
SonicJS uses a dynamic field system. Create collections through the admin interface or define them in the database:
-- Example: Blog Posts collection with custom fields
INSERT INTO collections (id, name, display_name, description, schema) VALUES (
'blog-posts', 'blog_posts', 'Blog Posts', 'Article content collection',
'{"type":"object","properties":{"title":{"type":"string","required":true}}}'
);
-- Add dynamic fields
INSERT INTO content_fields (collection_id, field_name, field_type, field_label, field_options) VALUES
('blog-posts', 'title', 'text', 'Title', '{"maxLength": 200, "required": true}'),
('blog-posts', 'content', 'richtext', 'Content', '{"toolbar": "full", "height": 400}'),
('blog-posts', 'excerpt', 'text', 'Excerpt', '{"maxLength": 500, "rows": 3}'),
('blog-posts', 'featured_image', 'media', 'Featured Image', '{"accept": "image/*"}'),
('blog-posts', 'publish_date', 'date', 'Publish Date', '{"defaultToday": true}'),
('blog-posts', 'is_featured', 'boolean', 'Featured Post', '{"default": false}');
Field Types
- text: Single-line text with validation
- richtext: WYSIWYG editor with TinyMCE
- number: Numeric input with min/max constraints
- boolean: Checkbox with custom labels
- date: Date picker with format options
- select: Dropdown with single/multi-select
- media: File picker with preview
๐ API Endpoints
Content Management
GET /admin/content/new?collection=id- Create new content formGET /admin/content/:id/edit- Edit content formPOST /admin/content/- Create content with validationPUT /admin/content/:id- Update content with versioningDELETE /admin/content/:id- Delete content
Advanced Features
POST /admin/content/preview- Preview content before publishingPOST /admin/content/duplicate- Duplicate existing contentGET /admin/content/:id/versions- Get version historyPOST /admin/content/:id/restore/:version- Restore specific versionGET /admin/content/:id/version/:version/preview- Preview historical version
Public API
GET /api/content- Get published content (paginated)GET /api/collections/:collection/content- Get content by collectionGET /api/collections- List all collections
๐ Deployment
Development Setup
# Run database migrations (includes Stage 5 enhancements)
npm run db:migrate
# Apply Stage 5 schema updates
wrangler d1 migrations apply sonicjs-ai --local
Production Deployment
# Deploy to production
npm run deploy
# Deploy with custom environment
wrangler deploy --env production
# Apply migrations to production database
wrangler d1 migrations apply sonicjs-ai --remote
๐งช Testing
# Run unit tests
npm test
# Run tests in watch mode
npm run test:watch
# Run E2E tests
npm run test:e2e
# Run E2E tests with UI
npm run test:e2e:ui
๐ Documentation
- Project Plan - Development roadmap and stages
- AI Instructions - Comprehensive development guidelines
- Development Guidelines - Development workflow and principles
๐ Plugin Development
Create plugins for extending SonicJS functionality:
// src/plugins/my-plugin/index.ts
import { Plugin } from '@sonicjs/core'
export default {
name: 'my-plugin',
hooks: {
'content:beforeCreate': async (content) => {
// Plugin logic here
return content
}
}
} as Plugin
๐ Why SonicJS AI?
Edge Performance
- Global distribution via Cloudflare's network
- Sub-100ms response times worldwide
- Automatic scaling and DDoS protection
Developer Experience
- TypeScript-first with full type safety
- Hot reload development environment
- Comprehensive CLI tools and generators
AI-Friendly Architecture
- Clean, structured codebase
- Comprehensive documentation
- Clear conventions and patterns
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
We welcome contributions! Please see our contributing guidelines for more details.
๐ Support
Built with โค๏ธ for the Cloudflare ecosystem
Languages
TypeScript
75.8%
MDX
15.3%
HTML
6.6%
JavaScript
2.2%