Skip to main content

Mockup Backend Plugin

The Mockup Backend provides persistence and version management for UI mockups created in the Mockup frontend plugin.

Overview

PropertyValue
Package@internal/plugin-mockup-backend
TypeBackend
Plugin IDmockup
DatabasePostgreSQL via Knex

Architecture

API Endpoints

Mockup Operations

MethodEndpointDescription
GET/mockupsList mockups
POST/mockupsCreate new mockup
GET/mockups/:idGet mockup with latest
PATCH/mockups/:idUpdate mockup metadata
DELETE/mockups/:idDelete mockup

Version Operations

MethodEndpointDescription
POST/mockups/:id/versionsSave new version
GET/mockups/:id/versionsList versions
GET/mockups/:id/versions/:vidGet specific version

Database Schema

mockups

ColumnTypeDescription
idUUIDPrimary key
nameVARCHARMockup name
descriptionTEXTOptional description
ownerVARCHAROwner user reference
created_atTIMESTAMPCreation time
updated_atTIMESTAMPLast update time

mockup_versions

ColumnTypeDescription
idUUIDPrimary key
mockup_idUUIDForeign key to mockup
version_tagVARCHAROptional version tag
layout_dataJSONBLayout configuration
created_byVARCHARCreator user ref
created_atTIMESTAMPCreation time

Request/Response Schemas

Create Mockup

// POST /mockups
interface CreateMockupRequest {
name: string;
description?: string;
}

interface CreateMockupResponse {
id: string;
name: string;
description?: string;
owner: string;
createdAt: string;
updatedAt: string;
}

Save Version

// POST /mockups/:id/versions
interface SaveVersionRequest {
layoutData: LayoutItem[];
versionTag?: string;
}

interface SaveVersionResponse {
id: string;
mockupId: string;
versionTag?: string;
layoutData: LayoutItem[];
createdBy: string;
createdAt: string;
}

Layout Item Structure

interface LayoutItem {
i: string; // Unique identifier
x: number; // X position (grid units)
y: number; // Y position (grid units)
w: number; // Width (grid units)
h: number; // Height (grid units)
component: string; // Component type
props: Record<string, any>; // Component properties
}

MockupStore Service

interface MockupStore {
// Mockup operations
list(owner?: string): Promise<Mockup[]>;
get(id: string): Promise<Mockup | null>;
create(input: CreateMockupInput, owner: string): Promise<Mockup>;
update(id: string, input: UpdateMockupInput): Promise<Mockup>;
delete(id: string): Promise<void>;

// Version operations
saveVersion(
mockupId: string,
input: SaveVersionInput,
createdBy: string,
): Promise<Version>;
listVersions(mockupId: string): Promise<Version[]>;
getVersion(mockupId: string, versionId: string): Promise<Version | null>;
getLatestVersion(mockupId: string): Promise<Version | null>;
}

Validation

All inputs are validated using Zod schemas:

const createMockupSchema = z.object({
name: z.string().min(1).max(255),
description: z.string().max(1000).optional(),
});

const saveVersionSchema = z.object({
layoutData: z.array(
z.object({
i: z.string(),
x: z.number().int().min(0),
y: z.number().int().min(0),
w: z.number().int().min(1),
h: z.number().int().min(1),
component: z.string(),
props: z.record(z.any()),
}),
),
versionTag: z.string().max(50).optional(),
});

Usage Examples

Create Mockup

curl -X POST http://localhost:7007/api/mockup/mockups \
-H "Content-Type: application/json" \
-d '{
"name": "Dashboard Design",
"description": "Main dashboard layout"
}'

Save Version

curl -X POST http://localhost:7007/api/mockup/mockups/xxx/versions \
-H "Content-Type: application/json" \
-d '{
"layoutData": [
{"i": "1", "x": 0, "y": 0, "w": 12, "h": 2, "component": "text", "props": {"content": "Title"}},
{"i": "2", "x": 0, "y": 2, "w": 6, "h": 4, "component": "card", "props": {"title": "Stats"}}
],
"versionTag": "v1.0"
}'

Get Mockup with Latest Version

curl http://localhost:7007/api/mockup/mockups/xxx

Response:

{
"id": "xxx",
"name": "Dashboard Design",
"description": "Main dashboard layout",
"owner": "user:default/john.doe",
"createdAt": "2024-01-15T10:00:00Z",
"updatedAt": "2024-01-15T12:00:00Z",
"latestVersion": {
"id": "yyy",
"mockupId": "xxx",
"versionTag": "v1.0",
"layoutData": [...],
"createdBy": "user:default/john.doe",
"createdAt": "2024-01-15T12:00:00Z"
}
}