pixielity/laravel-sdui

Server-Driven UI Schema Extractors for Filament

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/pixielity/laravel-sdui

v1.0.2 2026-02-09 14:07 UTC

This package is auto-updated.

Last update: 2026-02-09 10:07:29 UTC


README

Laravel SDUI

SDUI Module - Schema Extractors for Filament

This module provides Schema Extractors that convert Filament components (Forms, Tables, Actions, Widgets) into JSON schemas for Server-Driven UI applications.

Architecture

Instead of rebuilding Filament from scratch, this module:

  • ✅ Uses Filament directly for all UI components
  • ✅ Extracts schemas from Filament components
  • ✅ Provides JSON APIs for mobile/frontend clients
  • ✅ Caches extracted schemas for performance
Filament Resources → Schema Extractors → JSON API → Mobile/Frontend

Installation

  1. Register the service provider in config/app.php:
'providers' => [
    // ...
    Modules\SDUI\Providers\SDUIServiceProvider::class,
],
  1. Publish the configuration:
php artisan vendor:publish --tag=sdui-config

Usage

1. Define Filament Resources (Standard Filament)

// app/Filament/Resources/PostResource.php
class PostResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('title')->required(),
            Textarea::make('content'),
            Select::make('status')->options([
                'draft' => 'Draft',
                'published' => 'Published',
            ]),
        ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('title')->searchable(),
                BadgeColumn::make('status'),
                TextColumn::make('created_at')->dateTime(),
            ])
            ->actions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->bulkActions([
                DeleteBulkAction::make(),
            ]);
    }
}

2. Extract Schemas via API

The module automatically provides API endpoints:

# List all resources
GET /api/sdui/resources

# Get complete resource schema
GET /api/sdui/resources/posts

# Get form schema (create page)
GET /api/sdui/resources/posts/form/create

# Get form schema (edit page)
GET /api/sdui/resources/posts/form/edit

# Get table schema
GET /api/sdui/resources/posts/table

# Invalidate cache
POST /api/sdui/cache/invalidate

3. Use Extractors Programmatically

use Modules\SDUI\Contracts\FormSchemaExtractorInterface;
use Modules\SDUI\Contracts\TableSchemaExtractorInterface;
use Modules\SDUI\Contracts\ResourceSchemaExtractorInterface;

class MyController extends Controller
{
    public function __construct(
        protected ResourceSchemaExtractorInterface $extractor
    ) {}

    public function getSchema()
    {
        // Extract complete resource schema
        $schema = $this->extractor->extractResource(PostResource::class);

        // Extract just the form
        $formSchema = $this->extractor->extractCreatePage(PostResource::class);

        // Extract just the table
        $tableSchema = $this->extractor->extractListPage(PostResource::class);

        return response()->json($schema);
    }
}

Available Extractors

FormSchemaExtractor

Extracts schemas from Filament Forms:

  • All field types (TextInput, Select, Textarea, etc.)
  • Validation rules
  • Field relationships
  • Reactive dependencies

TableSchemaExtractor

Extracts schemas from Filament Tables:

  • All column types (TextColumn, BadgeColumn, etc.)
  • Filters
  • Actions and bulk actions
  • Table configuration (pagination, search, sort)

ActionSchemaExtractor

Extracts schemas from Filament Actions:

  • Action properties (label, icon, color)
  • Modal configuration
  • Confirmation dialogs
  • Action forms

ResourceSchemaExtractor

Extracts complete resource schemas:

  • Form schemas (create, edit)
  • Table schemas (list)
  • Navigation configuration
  • All resource pages

WidgetSchemaExtractor

Extracts schemas from Filament Widgets:

  • Stats widgets
  • Chart widgets
  • Table widgets
  • Custom widgets

Schema Registry

The Schema Registry caches extracted schemas for performance:

use Modules\SDUI\Contracts\SchemaRegistryInterface;

$registry = app(SchemaRegistryInterface::class);

// Get cached schema
$schema = $registry->get('posts', 'form');

// Store schema
$registry->set('posts', 'form', $schema);

// Invalidate cache
$registry->invalidate('posts');
$registry->invalidateAll();

// Disable caching temporarily
$registry->withoutCache()->get('posts', 'form');

Configuration

Edit config/sdui.php:

return [
    'cache' => [
        'enabled' => true,
        'ttl' => 3600, // 1 hour
    ],

    'extraction' => [
        'include_hidden_fields' => false,
        'include_validation_rules' => true,
        'include_relationships' => true,
    ],

    'security' => [
        'require_authentication' => false,
        'allowed_resources' => [], // Empty = all allowed
    ],
];

Example JSON Response

{
  "data": {
    "type": "resource",
    "name": "posts",
    "label": "Post",
    "pluralLabel": "Posts",
    "pages": {
      "list": {
        "type": "table",
        "columns": [
          {
            "type": "text",
            "name": "title",
            "label": "Title",
            "searchable": true,
            "sortable": true
          },
          {
            "type": "badge",
            "name": "status",
            "label": "Status",
            "colors": {
              "draft": "gray",
              "published": "success"
            }
          }
        ],
        "actions": [
          {
            "type": "action",
            "name": "edit",
            "label": "Edit",
            "icon": "heroicon-o-pencil"
          }
        ]
      },
      "create": {
        "type": "create",
        "form": {
          "type": "form",
          "fields": [
            {
              "type": "text",
              "name": "title",
              "label": "Title",
              "required": true,
              "validation": ["required", "string", "max:255"]
            },
            {
              "type": "textarea",
              "name": "content",
              "label": "Content"
            }
          ]
        }
      }
    }
  }
}

Benefits

  1. No Duplication: Use Filament directly, no need to rebuild components
  2. Always Up-to-Date: Automatically get Filament improvements
  3. Single Source of Truth: Define UI once in Filament
  4. Performance: Cached schemas for fast API responses
  5. Flexibility: Extract any Filament component to JSON
  6. Type Safety: Full PHP type hints and interfaces

Testing

# Test schema extraction
php artisan test --filter=SchemaExtractorTest

# Test API endpoints
php artisan test --filter=SchemaControllerTest

License

MIT