diff --git a/AGENTS.md b/AGENTS.md index 23748a1..e41691c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,11 +1,13 @@ # AGENTS.md - Developer Guide for Insertr ## Build/Test Commands -- `just dev` - Full-stack development (recommended) +- `just dev` - Full-stack development with auto-enhanced demo sites (recommended) +- `just serve` - API server only with multi-site hosting - `just build` - Build entire project (Go binary + JS library) - `just build-lib` - Build JS library only +- `just enhance` - CLI enhancement of static sites -For running and testing our application read our justfile. +For complete command reference, see the justfile. ## Code Style Guidelines @@ -22,8 +24,34 @@ For running and testing our application read our justfile. - Use `const`/`let`, avoid `var` - Prefer template literals over string concatenation - Export classes/functions explicitly, avoid default exports when multiple exports exist +- NO COMMENTS unless explicitly asked - keep code clean and self-documenting +- HTML-first approach: preserve element attributes and styling perfectly ### Database - Use `sqlc` for Go database code generation -- SQL files in `db/queries/`, schemas in `db/{sqlite,postgresql}/schema.sql` +- SQL files in `db/queries/`, schemas in `db/{sqlite,postgresql}/setup.sql` +- Version history implemented with full rollback capabilities - Run `just sqlc` after schema changes +- Multi-database support: SQLite for development, PostgreSQL for production + +## Current Architecture + +### Frontend (Library) +- **StyleAware Editor**: Rich text editing with automatic style detection +- **HTML Preservation**: Perfect fidelity editing that maintains all element attributes +- **Style Detection Engine**: Automatically generates formatting options from detected CSS +- **Link Management**: Popup-based configuration for complex multi-property elements +- **Zero Dependencies**: No markdown libraries - HTML-first approach + +### Backend (Go Binary) +- **Multi-Site Server**: Hosts and auto-enhances multiple static sites +- **Real-Time Enhancement**: Content changes trigger immediate file updates +- **Full REST API**: Complete CRUD operations with version control +- **Authentication**: Mock (dev) + Authentik OIDC (production) +- **Database Layer**: SQLite/PostgreSQL with full version history + +### Key Principles +- **HTML-First**: No lossy markdown conversion - perfect attribute preservation +- **Zero Configuration**: Just add `class="insertr"` to any element +- **Style-Aware**: Automatically detect and offer CSS-based formatting options +- **Performance**: Regular visitors get pure static HTML with zero CMS overhead diff --git a/README.md b/README.md index 23ff3d6..2979c41 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,11 @@ Containers with `class="insertr"` automatically make their viable children edita - No runtime overhead ### 2. **Content Editors** (Authenticated users) -- Rich editing interface loads on demand -- Click-to-edit any marked element -- Smart input types: text, textarea, link editor, markdown -- Changes saved to database +- Style-aware editing interface loads on demand +- Click-to-edit any marked element +- Rich text editor with style preservation and formatting toolbar +- Link editor with popup configuration for complex elements +- Changes saved to database with version history ### 3. **Developers** (You) - Add `class="insertr"` to any element @@ -136,19 +137,23 @@ auth: ## π Current Status **β Complete Full-Stack CMS** -- **Professional Editor**: Modal forms, markdown support, authentication system -- **Enterprise Authentication**: Production-ready OIDC integration with Authentik, PKCE security -- **Content Persistence**: SQLite database with REST API, version control +- **Style-Aware Editor**: Rich text editor with automatic style detection and formatting toolbar +- **HTML Preservation**: Perfect fidelity editing that maintains all element attributes and styling +- **Enterprise Authentication**: Production-ready OIDC integration with Authentik, PKCE security +- **Content Persistence**: SQLite/PostgreSQL database with REST API, complete version control - **Version History**: Complete edit history with user attribution and one-click rollback - **Build Enhancement**: Parse HTML, inject database content, build-time optimization -- **Smart Detection**: Auto-detects content types (text/markdown/link) -- **Deterministic IDs**: Content-based ID generation for consistent developer experience +- **Smart Detection**: Auto-detects content types and generates style-based formatting options +- **Link Management**: Popup-based link configuration for complex multi-property elements - **Full Integration**: Seamless development workflow with hot reload **π Production Ready** -- Deploy to cloud infrastructure -- Configure CDN for library assets -- Scale with PostgreSQL database +- β Full HTTP API server with authentication and version control +- β Build-time enhancement for static site generators +- β PostgreSQL and SQLite database support +- β Authentik OIDC integration for enterprise authentication +- Deploy enhanced static files to any CDN or host +- Run content API server on separate infrastructure ## π οΈ Quick Start @@ -166,8 +171,8 @@ just dev ``` This starts: -- **Demo site**: http://localhost:3000 (with live reload) -- **API server**: http://localhost:8080 (with content persistence) +- **Demo sites**: http://localhost:8080/sites/demo/ (auto-enhanced for testing) +- **API server**: http://localhost:8080/api/* (with content persistence and version control) ### **Using NPM** ```bash @@ -202,10 +207,11 @@ just clean # Clean build artifacts Running `just dev` gives you the **complete Insertr CMS**: -- β **Professional Editor** - Modal forms, markdown support, authentication -- β **Real-Time Persistence** - SQLite database with REST API +- β **Style-Aware Editor** - Rich text editing with automatic style detection and formatting +- β **HTML Preservation** - Perfect fidelity editing that maintains all styling and attributes +- β **Real-Time Persistence** - SQLite database with REST API and authentication - β **Version Control** - Complete edit history with user attribution and rollback -- β **Content Management** - Create, read, update content via browser +- β **Content Management** - Create, read, update content via browser with popup-based link editing - β **Build Integration** - Binary enhances HTML with database content - β **Hot Reload** - Changes reflected immediately @@ -309,18 +315,18 @@ just enhance input="src" output="public" # Custom paths ### **Runtime API Server** ```bash +# Development server with automatic site enhancement +./insertr serve --dev-mode --port 8080 + # Production server with PostgreSQL -./insertr serve --db "postgresql://user:pass@host:5432/dbname" +./insertr serve --db "postgresql://user:pass@host:5432/dbname" --config production.yaml -# Development server with SQLite -./insertr serve --dev-mode --port 8080 --db ./dev.db - -# Production server with custom config +# Production server with custom config and Authentik ./insertr --config ./production.yaml serve # Use justfile shortcuts -just serve # Development server on :8080 -just serve-prod port="443" # Production server +just serve # Development server on :8080 with auto-enhanced demo sites +just dev # Full development stack (recommended) ``` ### **Configuration Options** @@ -380,10 +386,10 @@ export INSERTR_SITE_ID="production" ``` ### **Content Type Detection** -- **Headlines** (`h1-h6`) β Text input with character limits -- **Paragraphs** (`p`) β Markdown textarea for rich content -- **Links/Buttons** (`a`, `button`) β Text + URL fields -- **Containers** (`div`, `section`) β Expand to viable children +- **Headlines** (`h1-h6`) β Rich text editor with style-aware formatting +- **Paragraphs** (`p`) β Rich text editor with detected style options from CSS +- **Links/Buttons** (`a`, `button`) β Popup-based link editor with text + URL configuration +- **Containers** (`div`, `section`) β Expand to viable children with automatic style detection ## π API Reference @@ -512,81 +518,89 @@ mock_content: false # Use mock content instead of real data - Works with any framework or generator - Developer experience focused -## ποΈ **Server-Hosted Static Sites** (NEW) +## π **Production Deployment Workflow** -**Real-time content updates for server-hosted static sites with immediate deployment.** +**Build-time enhancement + Runtime API for content management.** -### **Overview** -Insertr now supports hosting and enhancing static sites directly on the server. When content changes through the editor, static files are automatically updated in-place without requiring rebuilds or redeployment. +### **Production Architecture** +The production workflow separates content management from site hosting: -### **Key Benefits** -- β **Immediate Updates**: Content changes are live instantly -- β **Database Source of Truth**: Content stored in database, not files -- β **No Rebuilds Required**: Only content updates, templates stay the same -- β **Multi-Site Support**: Host multiple enhanced sites on one server -- β **Automatic Backups**: Original files backed up before enhancement - -### **Workflow** ``` -1. Developer deploys static site β Server directory (e.g., /var/www/mysite) -2. Insertr enhances files β Adds editing capabilities + injects content -3. Editor makes changes β API updates database + triggers file enhancement -4. Changes immediately live β Visitors see updated content instantly +1. Static Site Build β `insertr enhance` β Enhanced Static Files β Deploy to CDN/Host +2. Content Editing β `insertr serve` API β Database β Triggers rebuild ``` -### **Configuration Example** -```yaml -# insertr.yaml -server: - port: 8080 - sites: - - site_id: "mysite" - path: "/var/www/mysite" - domain: "mysite.example.com" - auto_enhance: true - - - site_id: "blog" - path: "/var/www/blog" - domain: "blog.example.com" - auto_enhance: true -``` +### **Two-Server Architecture** +- **Content API Server**: Runs `insertr serve` for content management and authentication +- **Static Site Host**: Serves enhanced static files (CDN, GitHub Pages, Netlify, etc.) -### **Quick Start** +### **Production Workflow** ```bash -# 1. Configure sites in insertr.yaml -# 2. Start the server -./insertr serve --dev-mode +# 1. Build-time enhancement +./insertr enhance ./src --output ./dist --api https://cms.example.com -# 3. Your sites are automatically registered and enhanced -# 4. Content changes via editor immediately update static files +# 2. Deploy enhanced static files +rsync ./dist/ user@cdn:/var/www/site/ + +# 3. Run content API server (separate infrastructure) +./insertr serve --config production.yaml --db "postgresql://..." ``` +### **Benefits** +- β **Performance**: Static files served from CDN with zero CMS overhead +- β **Scalability**: Content API and static hosting scale independently +- β **Reliability**: Static site works even if CMS server is down +- β **Security**: Content editing isolated from public site hosting +- β **Framework Agnostic**: Works with any static site generator or CDN + +### **Development Server** (Current Multi-Site Feature) +For development convenience, `insertr serve --dev-mode` can host multiple demo sites: + +```yaml +# insertr.yaml (development only) +server: + sites: + - site_id: "demo" + path: "./demos/demo_enhanced" + source_path: "./demos/demo" + auto_enhance: true +``` + +This serves sites at `http://localhost:8080/sites/demo/` for testing the editor interface. + ## βοΈ Configuration ### **YAML Configuration (insertr.yaml)** ```yaml +# Global settings +dev_mode: false # Development mode features + # Database configuration database: - path: "./insertr.db" # SQLite file path or PostgreSQL connection string + path: "./insertr.db" # SQLite file or PostgreSQL connection string -# Server configuration (with site hosting) +# Server configuration (multi-site hosting) server: port: 8080 # HTTP server port sites: # Server-hosted static sites - - site_id: "demo" - path: "./demo-site" - domain: "localhost:3000" - auto_enhance: true + - site_id: "mysite" + path: "/var/www/mysite_enhanced" # Enhanced site output directory + source_path: "/var/www/mysite" # Original static site files + auto_enhance: true # Auto-enhance on startup and content changes + discovery: + enabled: false # Use explicit class="insertr" markings (true = auto-discover) + aggressive: false # Aggressive element discovery -# API configuration (for remote content API) -api: - url: "" # Content API URL (leave empty to use local database) - key: "" # API authentication key - -# Build configuration (for CLI enhancement) -build: - input: "./src" # Default input directory for enhancement +# CLI enhancement configuration +cli: + site_id: "default" # Default site ID for CLI operations output: "./dist" # Default output directory for enhanced files + inject_demo_gate: true # Inject demo editing gate if none exist + +# API configuration (for CLI remote mode) +api: + url: "" # Content API URL (empty = use local database) + key: "" # API authentication key # Authentication configuration auth: @@ -594,13 +608,9 @@ auth: jwt_secret: "" # JWT signing secret (auto-generated in dev mode) # Authentik OIDC configuration (production) oidc: - endpoint: "https://auth.example.com/application/o/insertr/" # OIDC provider endpoint - client_id: "insertr-client" # OAuth2 client ID - client_secret: "your-secret" # Use AUTHENTIK_CLIENT_SECRET env var - -# Global settings -site_id: "demo" # Default site ID for content lookup -mock_content: false # Use mock content instead of real data + endpoint: "" # https://auth.example.com/application/o/insertr/ + client_id: "" # insertr-client (OAuth2 client ID) + client_secret: "" # OAuth2 client secret (or use AUTHENTIK_CLIENT_SECRET env var) ``` ### **Environment Variables** diff --git a/TODO.md b/TODO.md index ee18325..832fc62 100644 --- a/TODO.md +++ b/TODO.md @@ -1,497 +1,134 @@ -# Insertr Development TODO +# Insertr Development Roadmap -## π Architecture Analysis Complete (Dec 2024) +## π― **Current Status** (September 2025) -**Key Discovery**: The architecture is already 90% complete and brilliantly designed! The missing piece is not LocalStorage persistence, but the **HTTP server application** that implements the API contract both clients expect. +### **β Complete Full-Stack CMS** +- **Style-Aware Editor**: Rich text editing with automatic style detection and formatting toolbar +- **HTML Preservation**: Perfect fidelity editing that maintains all element attributes and styling +- **HTTP API Server**: Full REST API with authentication, version control, and rollback +- **Multi-Database Support**: SQLite (development) + PostgreSQL (production) +- **Authentication System**: Mock (development) + Authentik OIDC (production) +- **Build-Time Enhancement**: Content injection from database to static HTML +- **Development Workflow**: Hot reload, auto-enhanced demo sites, seamless testing -## β What's Already Built & Working - -### **Complete Foundation** -- β **Go Content Client** - Full REST API client with all CRUD operations (`internal/content/client.go`) -- β **JavaScript API Client** - Browser client with same API endpoints (`lib/src/core/api-client.js`) -- β **Content Types** - Well-defined data structures (`ContentItem`, `ContentResponse`) -- β **Mock Backend** - Working development server with realistic test data -- β **Build-Time Enhancement** - Content injection from database β HTML during builds -- β **Authentication System** - Complete auth flow ready for server integration -- β **Professional Editor** - Modal forms, validation, smart field detection - -### **Architecture Philosophy Preserved** -- β **"Tailwind of CMS"** - Zero configuration, build-time optimization -- β **Framework Agnostic** - Works with any static site generator -- β **Performance First** - Regular visitors get pure static HTML -- β **Editor Progressive Enhancement** - Editing assets only load when needed - -## π¨ **CRITICAL MISSING PIECE** - -### **HTTP Server Application** (90% of work remaining) -The CLI client and JavaScript client both expect a server at `/api/content/*`, but **no server exists**! - -**Required API Endpoints**: -``` -GET /api/content/{id}?site_id={site} # Get single content -GET /api/content?site_id={site} # Get all content for site -GET /api/content/bulk?site_id={site}&ids[]=... # Bulk get content -PUT /api/content/{id} # Update existing content -POST /api/content # Create new content -``` - -**Current State**: Both clients make HTTP calls to these endpoints, but they 404 because no server implements them. - -## π― **Immediate Implementation Plan** - -### **π΄ Phase 1: HTTP Server (CRITICAL)** -**Goal**: Build the missing server application that implements the API contract - -#### 1.1 **Go HTTP Server** β **HIGHEST PRIORITY** -- [ ] **REST API Server** - Implement all 5 required endpoints -- [ ] **Database Layer** - SQLite for development, PostgreSQL for production -- [ ] **Authentication Middleware** - JWT/OAuth integration -- [ ] **CORS & Security** - Proper headers for browser integration -- [ ] **Content Validation** - Input sanitization and type checking - -#### 1.2 **Integration Testing** -- [ ] **CLI Client Integration** - Test all CLI commands work with real server -- [ ] **JavaScript Client Integration** - Test browser editor saves to real server -- [ ] **End-to-End Workflow** - Edit β Save β Build β Deploy cycle - -### **π‘ Phase 2: Production Polish (IMPORTANT)** - -#### 2.1 **Client-Side Enhancements** -- [ ] **Editor-Server Integration** - Wire up `handleSave` to use `ApiClient` -- [ ] **Optimistic Updates** - Show immediate feedback, sync in background -- [ ] **Offline Support** - LocalStorage cache + sync when online -- [ ] **Loading States** - Professional feedback during saves - -#### 2.2 **Deployment Pipeline** -- [ ] **Build Triggers** - Auto-rebuild sites when content changes -- [ ] **Multi-Site Support** - Handle multiple domains/site IDs -- [ ] **CDN Integration** - Host insertr.js library on CDN -- [ ] **Database Migrations** - Schema versioning and updates - -### **π’ Phase 3: Advanced Features (NICE-TO-HAVE)** - -#### 3.1 **Content Management Enhancements** -- [ ] **Content Versioning** - Track edit history and allow rollbacks -- [ ] **Content Validation** - Advanced validation rules per content type -- [ ] **Markdown Enhancements** - Live preview, toolbar, syntax highlighting -- [ ] **Media Management** - Image upload and asset management - -#### 3.2 **Developer Experience** -- [ ] **Development Tools** - Better debugging and development workflow -- [ ] **Configuration API** - Extensible field type system -- [ ] **Testing Suite** - Comprehensive test coverage -- [ ] **Documentation** - API reference and integration guides - -## π‘ **Key Architectural Insights** - -### **Why This Architecture is Brilliant** -1. **Performance First**: Regular visitors get pure static HTML with zero CMS overhead -2. **Separation of Concerns**: Content editing completely separate from site performance -3. **Build-Time Optimization**: Database content gets "baked into" static HTML during builds -4. **Progressive Enhancement**: Sites work without JavaScript, editing enhances with JavaScript -5. **Framework Agnostic**: Works with Hugo, Next.js, Jekyll, Gatsby, vanilla HTML, etc. - -### **Production Flow** -``` -Content Edits β HTTP API Server β Database - β -Static Site Build β CLI Enhancement β Database Content - β - Enhanced HTML β CDN/Deploy -``` - -### **Current Working Flow** -``` -β Browser Editor β (404) Missing Server β β -β CLI Enhancement β Mock Data β β -β Static HTML Generation β β -``` - -**Gap**: The HTTP server that connects editor saves to database storage. - -## ποΈ **Next Steps: Server Implementation** - -### **β Implemented - Unified Binary Architecture** -``` -β COMPLETED: All server functionality integrated into unified binary -cmd/ -βββ serve.go # Runtime API server command -βββ enhance.go # Build-time enhancement command -internal/ -βββ api/ # HTTP handlers and middleware -βββ db/ # Multi-database layer with sqlc -βββ content/ # Content management logic -``` - -### **Files to Modify** -- `lib/src/core/editor.js:91` - Wire up `ApiClient` to `handleSave` method -- `README.md` - Add server setup instructions -- `docker-compose.yml` - Add server for development stack - -## π― **Success Criteria** - -### **Phase 1 Complete When**: -- β HTTP server running on `localhost:8080` (or configurable port) -- β All 5 API endpoints returning proper JSON responses -- β JavaScript editor successfully saves edits to database -- β CLI enhancement pulls latest content from database -- β Full edit β save β build β view cycle working end-to-end - -### **Production Ready When**: -- β Multi-site support with proper site isolation -- β Authentication and authorization working -- β Database migrations strategy -- β CDN hosting for insertr.js library -- β Deployment documentation and examples - -## Current Architecture Status - -### β **What's Working Well** -- **CLI Parser**: Detects 41+ elements across demo site, generates stable IDs -- **Authentication System**: Professional login/edit mode toggle with visual states -- **Form System**: Dynamic modal forms with smart field detection -- **Build Pipeline**: Automated library building and copying to demo site -- **Development Experience**: Hot reload with Air integration - -### π **Investigation Results** -- **File Analysis**: All legacy code removed, clean single implementation -- **Integration Testing**: CLI β Library integration works seamlessly -- **Demo Site**: Both index.html and about.html use modern library correctly -- **Content Detection**: CLI successfully identifies text/markdown/link content types - -## Immediate Next Steps - -### π― **Priority 1: Content Persistence** -**Goal**: Make edits survive page reload -- Create `lib/src/core/content-manager.js` for LocalStorage operations -- Integrate with existing form system for automatic save/restore -- Add change tracking and storage management - -### π― **Priority 2: Server Application** -**Goal**: Backend API for real content storage -- Design REST API for content CRUD operations -- Add authentication integration (OAuth/JWT) -- Consider database choice (SQLite for simplicity vs PostgreSQL for production) +### **ποΈ Architecture Achievements** +- **Zero Configuration**: Just add `class="insertr"` to any element +- **Framework Agnostic**: Works with any static site generator +- **Performance First**: Regular visitors get pure static HTML with zero CMS overhead +- **HTML-First**: No lossy markdown conversion - perfect attribute preservation --- -## π **Ready to Build** +## π **Priority Roadmap** -The analysis is complete. The architecture is sound and 90% implemented. +### **π΄ Phase 1: Editor Integration Polish** (High Priority) -**Next Action**: Create the HTTP server application that implements the API contract both clients expect. +#### **Frontend-Backend Integration** +- [ ] **Editor-API Connection**: Wire up StyleAware editor saves to actual HTTP API +- [ ] **Error Handling**: Proper error states, loading indicators, offline handling +- [ ] **Content Validation**: Client-side validation before API calls +- [ ] **Save Feedback**: Professional save/error feedback in editor interface -This will immediately unlock: -- β Real content persistence (not just LocalStorage) -- β Multi-user editing capabilities -- β Production-ready content management -- β Full integration between browser editor and CLI enhancement +#### **User Experience Enhancements** +- [ ] **Draft Auto-Save**: LocalStorage drafts during editing with recovery +- [ ] **Optimistic Updates**: Immediate UI feedback, background sync +- [ ] **Conflict Resolution**: Handle concurrent editing scenarios +- [ ] **Editor Performance**: Optimize style detection for large pages -*Let's build the missing server!* +### **π‘ Phase 2: Production Deployment** (Medium Priority) -## ποΈ **Database Schema Architecture Decision** (Sept 2025) +#### **Production Workflows** +- [ ] **CI/CD Integration**: GitHub Actions templates for static site generators +- [ ] **Deployment Examples**: Netlify, Vercel, CloudFlare Pages integration guides +- [ ] **CDN Configuration**: Library asset hosting and optimization +- [ ] **Database Migrations**: Schema versioning and update strategies -**Issue**: Inlined SQLite schema in `database.go` creates multiple sources of truth, same problem we just solved with model duplication. +#### **Enterprise Features** +- [ ] **Multi-Site API**: Single server managing multiple site content +- [ ] **User Management**: Role-based access control and permissions +- [ ] **Content Approval**: Editorial workflows and publishing controls +- [ ] **Performance Monitoring**: Analytics and optimization tools -### **Recommended Solutions** (in order of preference): +### **π’ Phase 3: Advanced CMS Features** (Low Priority) -#### **π― Option 1: Schema-as-Query Pattern** β **RECOMMENDED** -``` -db/queries/ -βββ content.sql # CRUD queries -βββ versions.sql # Version control queries -βββ schema_setup.sql # Schema initialization as named query -βββ indexes_setup.sql # Index creation as named query +#### **Content Management Enhancements** +- [ ] **Media Management**: Image upload, asset management, optimization +- [ ] **Content Templates**: Reusable content blocks and page templates +- [ ] **Search and Filtering**: Content discovery and organization tools +- [ ] **Import/Export**: Bulk content operations and migration tools + +#### **Developer Experience** +- [ ] **Plugin System**: Extensible content types and field configurations +- [ ] **Testing Framework**: Automated testing for content workflows +- [ ] **Documentation Site**: Interactive documentation with live examples +- [ ] **Performance Profiling**: Development tools and optimization guides + +--- + +## π **Future Features** (Planned) + +### **Production Static Site Hosting** +**Goal**: Extend current development multi-site server to production static site hosting + +**Current State**: Development server hosts enhanced demo sites at `/sites/{site_id}/` for testing convenience. + +**Future Enhancement**: Production-ready static site hosting with content management. + +#### **Proposed Production Static Site Server** +- **Use Case**: Small to medium sites that want unified hosting + content management +- **Alternative to**: Netlify CMS + hosting, Forestry + Vercel, etc. +- **Benefit**: Single server handles both static hosting AND content API + +#### **Architecture**: Static file serving WITHOUT enhancement +- **Static Serving**: Serve pre-enhanced files efficiently (like nginx/Apache) +- **Content API**: Separate `/api/*` endpoints for content management +- **Build Triggers**: Content changes trigger static site rebuilds +- **Multi-Tenant**: Multiple sites with custom domains + +#### **Configuration Example** +```yaml +# insertr.yaml (future production mode) +server: + mode: "production" + sites: + - site_id: "mysite" + domain: "mysite.com" + path: "/var/www/mysite" # Pre-enhanced static files + ssl_cert: "/etc/ssl/mysite.pem" + rebuild_command: "hugo && insertr enhance ./public --output /var/www/mysite" + + - site_id: "blog" + domain: "blog.example.com" + path: "/var/www/blog" + rebuild_command: "npm run build" ``` -**Benefits**: -- β Single source of truth (schema files) -- β sqlc generates type-safe setup functions -- β Consistent with existing sqlc workflow -- β Database-agnostic parameter syntax (`sqlc.arg()`) +#### **Implementation Plan** +- [ ] **Static File Server**: Efficient static file serving (no enhancement) +- [ ] **Domain Routing**: Route custom domains to appropriate site directories +- [ ] **SSL/TLS Support**: Automatic certificate management (Let's Encrypt) +- [ ] **Build Triggers**: Webhook system to trigger site rebuilds after content changes +- [ ] **Performance**: CDN integration, compression, caching headers +- [ ] **Monitoring**: Site uptime, performance metrics, error logging -**Implementation**: -```sql --- name: InitializeSchema :exec -CREATE TABLE IF NOT EXISTS content (...); -CREATE TABLE IF NOT EXISTS content_versions (...); +**Priority**: Low - implement after core content management features are stable --- name: CreateIndexes :exec -CREATE INDEX IF NOT EXISTS idx_content_site_id ON content(site_id); -``` +### **Advanced Style Preview System** -#### **π§ Option 2: Migration Tool Integration** -- Use `goose`, `golang-migrate`, or `dbmate` -- sqlc natively supports parsing migration directories -- Professional database management with up/down migrations -- **Trade-off**: Additional dependency and complexity +**Current State**: Basic style button previews using `getComputedStyle()` to show formatting effects. -#### **ποΈ Option 3: Embedded Schema Files** -- Use `go:embed` to read schema files at compile time -- Keep schema in separate `.sql` files -- **Trade-off**: Not processed by sqlc, less type safety +#### **Future Style Preview Enhancements** +- [ ] **Enhanced Style Support**: Background colors, borders, typography with safety constraints +- [ ] **Interactive Previews**: Hover effects, animations, responsive previews +- [ ] **Custom Style Creation**: Visual style picker with live preview +- [ ] **Style Inheritance Display**: Show which properties come from which CSS classes +- [ ] **Accessibility Validation**: Ensure previews meet contrast and readability standards -**β COMPLETED**: Implemented Option 1 (Schema-as-Query) with important discovery: +### **Advanced Access Control** -**sqlc Limitations Discovered**: -- β sqlc generates functions for `CREATE TABLE` and `ALTER TABLE` statements -- β sqlc does **NOT** generate functions for `CREATE INDEX` or `CREATE TRIGGER` statements -- π§ **Solution**: Handle table creation via sqlc-generated functions, handle indexes/triggers manually in Go initialization code +**Current State**: Simple boolean authentication gate for page-level editing access. -**Final Implementation**: -- `db/*/setup.sql` - Contains table creation queries (sqlc generates type-safe functions) -- `internal/db/database.go` - Manual index/trigger creation using raw SQL -- **Best Practice**: Use sqlc for what it supports, manual SQL for what it doesn't - -## π **Editor Cache Architecture & Content State Management** (Dec 2024) - -### **Current Architecture Issues Identified** - -**Problem**: Conflict between preview system and content persistence after save operations. - -**Root Cause**: The unified Editor system was designed with preview-first architecture: -- `originalContent` stores DOM state when editing begins -- `clearPreview()` always restores to `originalContent` -- This creates race condition: `applyContent()` β `clearPreview()` β content reverted - -### **β Implemented Solution: Post-Save Baseline Update** - -**Strategy**: After successful save, update the stored `originalContent` to match the new saved state. - -**Implementation** (`lib/src/ui/Editor.js`): -```js -// In save handler: -context.applyContent(content); // Apply new content to DOM -context.updateOriginalContent(); // Update baseline to match current DOM -this.previewer.clearPreview(); // Clear preview (won't revert since baseline matches) -``` - -**Benefits**: -- β Content persists after save operations -- β Future cancellations restore to saved state, not pre-edit state -- β Maintains clean preview functionality -- β No breaking changes to existing architecture - -### **Future Considerations: Draft System Architecture** - -**Current State Management**: -- **Browser Cache**: DOM elements store current content state -- **Server Cache**: Database stores persisted content -- **No Intermediate Cache**: Edits are either preview (temporary) or saved (permanent) - -**Potential Draft System Design**: - -#### **Option 1: LocalStorage Drafts** -```js -// Auto-save drafts locally during editing -const draftKey = `insertr_draft_${contentId}_${siteId}`; -localStorage.setItem(draftKey, JSON.stringify({ - content: currentContent, - timestamp: Date.now(), - originalContent: baseline -})); -``` - -**Benefits**: Offline support, immediate feedback, no server load -**Drawbacks**: Per-browser, no cross-device sync, storage limits - -#### **Option 2: Server-Side Drafts** -```js -// Auto-save drafts to server with special draft flag -PUT /api/content/{id}/draft -{ - "value": "Draft content...", - "type": "markdown", - "is_draft": true -} -``` - -**Benefits**: Cross-device sync, unlimited storage, collaborative editing potential -**Drawbacks**: Server complexity, authentication requirements, network dependency - -#### **Option 3: Hybrid Draft System** -- **LocalStorage**: Immediate draft saving during typing -- **Server Sync**: Periodic sync of drafts (every 30s or on significant changes) -- **Conflict Resolution**: Handle cases where server content changed while editing draft - -### **Cache Invalidation Strategy** - -**Current Behavior**: -- Content is cached in DOM until page reload -- No automatic refresh when content changes on server -- No awareness of multi-user editing scenarios - -**Recommended Enhancements**: - -#### **Option A: Manual Refresh Strategy** -- Add "Refresh Content" button to editor interface -- Check server content before editing (warn if changed) -- Simple conflict resolution (server wins vs local wins vs merge) - -#### **Option B: Polling Strategy** -- Poll server every N minutes for content changes -- Show notification if content was updated by others -- Allow user to choose: keep editing, reload, or merge - -#### **Option C: WebSocket Strategy** -- Real-time content change notifications -- Live collaborative editing indicators -- Automatic conflict resolution - -### **Implementation Priority** - -**Phase 1** (Immediate): β **COMPLETED** -- Fix content persistence after save (baseline update approach) - -**Phase 2** (Short-term): -- Add LocalStorage draft auto-save during editing -- Implement draft recovery on page reload -- Basic conflict detection (server timestamp vs local timestamp) - -**Phase 3** (Long-term): -- Server-side draft support -- Real-time collaboration features -- Advanced conflict resolution - -### **Design Principles for Draft System** - -1. **Progressive Enhancement**: Site works without drafts, drafts enhance UX -2. **Data Safety**: Never lose user content, even in edge cases -3. **Performance First**: Drafts shouldn't impact site loading for regular visitors -4. **Conflict Transparency**: Always show user what's happening with their content -5. **Graceful Degradation**: Fallback to basic editing if draft system fails - -**Note**: Current architecture already supports foundation for all these enhancements through the unified Editor system and API client pattern. - -## ποΈ **Server-Hosted Static Sites Implementation** (Sept 2025) - -### **β COMPLETED: Unified Binary HTTP Server** -The HTTP server has been successfully implemented and is production-ready: -- β **Full REST API** - All content CRUD operations (`internal/api/handlers.go`) -- β **Multi-Database Support** - SQLite + PostgreSQL with sqlc-generated queries -- β **Authentication System** - JWT + mock tokens, ready for authentik integration -- β **Bulk Operations** - Efficient bulk content retrieval (`injector.go:56-96`) -- β **Content Enhancement** - Build-time content injection from database - -### **π― NEW PRIORITY: Server-Hosted File Enhancement** - -**Goal**: Enable real-time content updates for server-hosted static sites through database-driven file enhancement. - -**Architecture**: Database as source of truth β Content changes β File updates β Immediate deployment - -### **Phase 1: Core File Enhancement System** -- [ ] **Extend enhancer.go** - Add `EnhanceInPlace()` method for in-place file modification -- [ ] **Site Manager** - Create registration system for static site paths -- [ ] **Handler Integration** - Hook file enhancement into `UpdateContent()` API calls -- [ ] **Configuration Extension** - Add sites configuration to `insertr.yaml` - -**Files to modify**: -- `internal/content/enhancer.go` - Add in-place enhancement methods -- `internal/api/handlers.go:225` - Integrate file enhancement trigger -- `insertr.yaml` - Add sites configuration section -- `cmd/serve.go` - Initialize site manager in server - -### **Phase 2: Multi-Site Server Management** -- [ ] **CLI Site Commands** - `insertr sites register/list/enhance` -- [ ] **File Backup System** - Backup original files before enhancement -- [ ] **Error Handling** - Graceful file permission and disk space handling -- [ ] **Performance Optimization** - Selective file updates, change detection - -### **Phase 3: Production Features** -- [ ] **Authentik Integration** - OIDC authentication for production deployment -- [ ] **Caddy Integration** - Reverse proxy configuration templates -- [ ] **Monitoring & Logging** - Track enhancement operations and errors -- [ ] **Multi-Environment** - Development vs production configuration - -### **Implementation Approach: Leverage Existing Architecture** - -**Reuse Existing Components**: -- β **Bulk Injection** - `injector.go:56-96` already handles efficient content injection -- β **Multi-Site Support** - `siteID` parameter used throughout API and database -- β **Authentication** - `auth.go:47-67` supports JWT tokens ready for authentik -- β **Content Client Interface** - `types.go:18-28` extensible for new features - -**New Components** (minimal additions): -- **Site Manager** - Register static site paths and manage file enhancement -- **In-Place Enhancer** - Extend existing enhancer for file modification -- **Configuration** - Extend YAML config for site registration - -### **Target Deployment Architecture** -``` -βββββββββββββββββββββββββββββββββββββββ -β Caddy Reverse Proxy β -βββββββββββββββββββ¬ββββββββββββββββββββ€ -β Static Sites β Insertr Server β -β /site1/* βββββ β :8080/api/* β -β /site2/* βββββ β Authentication β -β /admin/* βββββ β File Enhancement β -βββββββββββββββββββ΄ββββββββββββββββββββ - β β - βΌ βΌ - βββββββββββββββ βββββββββββββββββββ - βStatic Files β β Database + β - β/var/www/ ββββββ€ Enhancement β - β site1/ β β Engine β - β site2/ β βββββββββββββββββββ - βββββββββββββββ -``` - -**Content Update Workflow**: -1. Editor makes content change β API call to `/api/content/{id}` -2. Content saved to database (source of truth) -3. File enhancement triggered β Static files updated in-place -4. Changes immediately visible to visitors (served by Caddy) - -### **Future CI/CD Integration Features** (Post-Server Implementation) - -#### **External Build Trigger System** -- **Webhook Integration**: Trigger external CI/CD pipelines when content changes -- **GitHub Actions Templates**: Pre-built workflows for Hugo, Next.js, Jekyll + Insertr -- **Platform Integrations**: Native Netlify, Vercel, CloudFlare Pages integration -- **Build Status Tracking**: Monitor external build progress and deployment status - -#### **Hybrid Deployment Models** -- **File + Pipeline Mode**: Server-hosted sites with optional CI/CD rebuilds -- **Content API Mode**: Headless CMS for external static site generators -- **Multi-Environment**: Staging/production deployment coordination -- **Build Caching**: Intelligent rebuilds based on content vs template changes - -#### **Advanced Content Workflows** -- **Scheduled Publishing**: Time-based content activation -- **Content Approval**: Multi-user approval workflows before deployment -- **A/B Testing**: Content variations for different user segments -- **Rollback Integration**: Coordinate content rollbacks with deployment rollbacks - -### **Draft System Foundation** (Ready for Extension) - -**Current Architecture Supports**: -- β **Bulk Operations** - `injector.go:56-96` efficient for batch content updates -- β **Version Control** - Full version history with rollback capabilities -- β **Content Types** - Extensible type system ready for draft fields - -**Future Draft Features**: -- **Server-Side Drafts** - Extend `ContentItem` with `is_draft` field -- **Batch Publishing** - Publish multiple draft items simultaneously -- **Preview Mode** - View sites with draft content before publishing -- **Auto-Save Drafts** - Background saving during editing sessions - -### **Benefits of Server-Hosted Approach** - -1. **β Immediate Deployment** - Content changes are live instantly -2. **β Database Source of Truth** - No git-based workflow complexity -3. **β Content-Only Updates** - No template rebuilds required -4. **β Existing Infrastructure** - Leverages Caddy + authentik setup -5. **β Performance** - Static file serving with dynamic content injection -6. **β Multi-Site** - Single server manages multiple enhanced sites -7. **β Zero Downtime** - Updates don't require site rebuilds or deploys - -## π― **Future Class Extensions: Advanced Access Control** (Planned) - -### **Granular Permission System for `.insertr-gate`** - -**Current Implementation**: Simple boolean authentication gate for page-level editing access. - -**Future Enhancement Concept**: Role-based access control and section-level permissions for enterprise applications. +**Future Enhancement**: Role-based access control and section-level permissions for enterprise applications. #### **Potential Extended Gate Classes** ```html @@ -506,10 +143,6 @@ The HTTP server has been successfully implemented and is production-ready:
Need help? Contact our support team anytime.