Block System Architecture

The heart of Autofocus is our expandable block system - a modular architecture that lets creators build rich, interactive content experiences. Each block type serves a specific purpose while maintaining consistent APIs and rendering patterns.

🧩 How Blocks Work

Universal Structure

Every block follows a consistent data structure with type, content, metadata, and ordering information.

id: uuid
type: string
content: json
order_index: integer
page_id: uuid
created_at: timestamp

Rendering Pipeline

Blocks are dynamically rendered based on type, with edit/view modes and real-time updates.

1. Fetch blocks from database
2. Sort by order_index
3. Render appropriate component
4. Subscribe to real-time updates

📦 Available Block Types

Text/Markdown Block

Rich text content with full markdown support including headers, lists, links, and formatted text.

Key Features

GitHub-flavored markdownSyntax highlightingTable supportLive preview

API Structure

{
  "type": "markdown",
  "content": {
    "text": "# My heading\n\nThis is **bold** text with a [link](https://example.com)."
  }
}

Image Block

Single image display with optional captions, alt text, and click-through links.

Key Features

WebP/AVIF optimizationResponsive sizingLazy loadingAlt text support

API Structure

{
  "type": "image",
  "content": {
    "url": "https://example.com/image.jpg",
    "alt": "Description",
    "caption": "Image caption"
  }
}

Image Gallery Block

Multiple images in a responsive grid layout with lightbox functionality.

Key Features

Grid layoutsLightbox viewingBulk uploadImage reordering

API Structure

{
  "type": "image_gallery",
  "content": {
    "images": [
      {"url": "image1.jpg", "caption": "Photo 1"},
      {"url": "image2.jpg", "caption": "Photo 2"}
    ]
  }
}

Link Block

Rich link previews with automatic metadata fetching and custom styling.

Key Features

Auto metadata scrapingCustom thumbnailsClick trackingRich previews

API Structure

{
  "type": "link",
  "content": {
    "url": "https://example.com",
    "title": "Custom Title",
    "description": "Custom description"
  }
}

Kanban Board

Interactive task management with drag-and-drop columns and cards.

Key Features

Drag & dropCustom columnsCard descriptionsProgress tracking

API Structure

{
  "type": "kanban",
  "content": {
    "columns": [
      {
        "title": "To Do",
        "cards": [{"title": "Task 1", "description": "Details"}]
      }
    ]
  }
}

Checklist Block

Interactive checklists with persistent state and progress indicators.

Key Features

Persistent stateProgress trackingNested itemsBulk operations

API Structure

{
  "type": "checklist",
  "content": {
    "items": [
      {"text": "Item 1", "completed": false},
      {"text": "Item 2", "completed": true}
    ]
  }
}

Code Editor Block

Syntax-highlighted code blocks with multiple language support and themes.

Key Features

50+ languagesMultiple themesLine numbersCopy to clipboard

API Structure

{
  "type": "code",
  "content": {
    "code": "console.log('Hello World');",
    "language": "javascript",
    "theme": "dark"
  }
}

Audio Block

Audio player with waveform visualization and podcast-style controls.

Key Features

Waveform displayPlayback controlsChapter markersSpeed control

API Structure

{
  "type": "audio",
  "content": {
    "url": "https://example.com/audio.mp3",
    "title": "Audio Title",
    "duration": 180
  }
}

Record/Receipt Block

Structured data for tracking expenses, records, and financial information.

Key Features

Expense trackingCategory sortingDate filteringExport data

API Structure

{
  "type": "record",
  "content": {
    "type": "expense",
    "amount": 29.99,
    "date": "2024-01-15",
    "category": "Software"
  }
}

Social Media Share Block

Social media profile links with custom icons and engagement metrics.

Key Features

Multiple platformsCustom iconsAnalytics trackingLink validation

API Structure

{
  "type": "social_media",
  "content": {
    "platform": "twitter",
    "username": "example",
    "url": "https://twitter.com/example"
  }
}

3D Model Viewer (STL)

Interactive 3D model viewer supporting STL files with zoom and rotation.

Key Features

STL file support360° rotationZoom controlsLighting options

API Structure

{
  "type": "stl_viewer",
  "content": {
    "url": "https://example.com/model.stl",
    "title": "3D Model",
    "description": "Model description"
  }
}

Shop Block

E-commerce integration with product listings and affiliate links.

Key Features

Product catalogsAffiliate trackingPrice monitoringAmazon integration

API Structure

{
  "type": "shop",
  "content": {
    "products": [
      {
        "title": "Product Name",
        "price": "$29.99",
        "url": "https://example.com/buy"
      }
    ]
  }
}

Location Block

Interactive maps with custom markers and location information.

Key Features

Interactive mapsCustom markersGPS coordinatesLocation sharing

API Structure

{
  "type": "location",
  "content": {
    "latitude": 40.7128,
    "longitude": -74.0060,
    "title": "New York City",
    "description": "Location details"
  }
}

Menu Block

Structured menu system for restaurants, services, or product catalogs.

Key Features

Category organizationPrice displayImage supportSearch functionality

API Structure

{
  "type": "menu",
  "content": {
    "categories": [
      {
        "name": "Appetizers",
        "items": [{"name": "Item", "price": "$9.99"}]
      }
    ]
  }
}

⚙️ Block Operations

CRUD Operations

CREATE
Add new blocks with automatic ordering and real-time updates
READ
Fetch blocks with pagination, filtering, and caching
UPDATE
Edit content with live preview and auto-save functionality
DELETE
Remove blocks with confirmation and undo capabilities

Advanced Features

Drag & Drop Reordering
React DnD with touch support for mobile devices
Real-time Collaboration
Supabase subscriptions for live updates across clients
Version History
Track changes with automatic versioning and rollback
Content Validation
Schema validation and sanitization for security

👨‍💻 Creating Custom Blocks

Block Component Structure

// MyCustomBlock.js
export default function MyCustomBlock({ 
  id, 
  content, 
  isEditing, 
  onEdit, 
  onDelete,
  onReorder 
}) {
  if (isEditing) {
    return <MyCustomBlockEdit {...props} />
  }
  
  return (
    <div className="custom-block">
      {/* Render block content */}
    </div>
  )
}

Registration Process

1. Create block component with view and edit modes
2. Add to block registry in _blocks/index.js
3. Define content schema and validation rules
4. Add database migration for new block type
5. Update block selector UI components

⚡ Performance & Optimization

Rendering Optimization

  • • Virtual scrolling for large block lists
  • • Lazy loading of heavy block types
  • • Memoization of block components
  • • Debounced auto-save functionality
  • • Progressive image loading

Data Optimization

  • • Selective field fetching from database
  • • Client-side caching with state management
  • • Optimistic updates for instant feedback
  • • Batch operations for bulk changes
  • • Content compression for large blocks