Schema Examples
These examples are intentionally varied and concise. Adapt them to your own domain.
Project Scope Examples
Define scopes in defineConfig() before you start adding local fields to entities. The config is pure data: project id, title, menu groups, scopes, spaces and the entity list.
E-commerce Storefronts
import { defineConfig } from '@flexkit/schema';
export default defineConfig({
title: 'Commerce',
projectId: 'commerce123',
scopes: [
{ name: 'default', label: 'Default', isDefault: true },
{ name: 'es', label: 'Spain Store' },
{ name: 'pt', label: 'Portugal Store' },
{ name: 'fr', label: 'France Store' },
{ name: 'it', label: 'Italy Store' },
{ name: 'uk', label: 'United Kingdom Store' },
{ name: 'en', label: 'United States Store' },
{ name: 'de', label: 'Germany Store' },
{ name: 'lengow', label: 'Marketplace Feed' },
{ name: 'fruugo', label: 'Partner Marketplace' },
],
schema: [
// ...
],
});CRM Regions And Divisions
export default defineConfig({
title: 'CRM',
projectId: 'crm123',
scopes: [
{ name: 'default', label: 'Global', isDefault: true },
{ name: 'na', label: 'North America' },
{ name: 'emea', label: 'Europe, Middle East & Africa' },
{ name: 'apac', label: 'Asia Pacific' },
{ name: 'latam', label: 'Latin America' },
{ name: 'enterprise', label: 'Enterprise Division' },
{ name: 'smb', label: 'SMB Division' },
{ name: 'government', label: 'Government' },
],
schema: [
// ...
],
});1) E-commerce: Catalog + Orders
import { defineEntity } from '@flexkit/schema';
export const product = defineEntity({
name: 'product',
plural: 'products',
display: 'name',
menu: { label: 'Products', group: 'catalog' },
attributes: [
{
name: 'name',
label: 'Name',
scope: 'local',
dataType: 'string',
inputType: 'text',
searchable: true,
defaultValue: '',
},
{
name: 'sku',
label: 'SKU',
scope: 'global',
dataType: 'string',
inputType: 'text',
unique: true,
defaultValue: '',
},
{
name: 'price',
label: 'Price',
scope: 'local',
dataType: 'float',
inputType: 'number',
defaultValue: '',
},
{
name: 'category',
label: 'Category',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'single', entity: 'category', field: 'name' },
},
],
});2) CRM: Deals + Contacts
export const deal = defineEntity({
name: 'deal',
plural: 'deals',
display: 'name',
menu: { label: 'Deals', group: 'sales' },
attributes: [
{
name: 'name',
label: 'Deal Name',
scope: 'local',
dataType: 'string',
inputType: 'text',
defaultValue: '',
},
{
name: 'stage',
label: 'Stage',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'single', entity: 'pipelineStage', field: 'name' },
},
{
name: 'contacts',
label: 'Contacts',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'multiple', entity: 'contact', field: 'firstName' },
},
{
name: 'amount',
label: 'Amount',
scope: 'global',
dataType: 'float',
inputType: 'number',
defaultValue: '',
},
],
});3) ERP: Procurement + Inventory
export const purchaseOrder = defineEntity({
name: 'purchaseOrder',
plural: 'purchaseOrders',
display: 'number',
menu: { label: 'Purchase Orders', group: 'operations' },
attributes: [
{
name: 'number',
label: 'PO Number',
scope: 'global',
dataType: 'string',
inputType: 'text',
unique: true,
defaultValue: '',
},
{
name: 'supplier',
label: 'Supplier',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'single', entity: 'supplier', field: 'name' },
},
{
name: 'status',
label: 'Status',
scope: 'global',
dataType: 'string',
inputType: 'select',
defaultValue: 'draft',
options: {
list: [
{ label: 'Draft', value: 'draft' },
{ label: 'Approved', value: 'approved' },
{ label: 'Received', value: 'received' },
],
},
},
{
name: 'deliveryDate',
label: 'Delivery Date',
scope: 'global',
dataType: 'date',
inputType: 'datetime',
defaultValue: '',
},
],
});4) Healthcare: Appointments
export const appointment = defineEntity({
name: 'appointment',
plural: 'appointments',
menu: { label: 'Appointments', group: 'operations' },
attributes: [
{
name: 'patient',
label: 'Patient',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'single', entity: 'patient', field: 'fullName' },
},
{
name: 'doctor',
label: 'Doctor',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'single', entity: 'doctor', field: 'fullName' },
},
{
name: 'startAt',
label: 'Start',
scope: 'global',
dataType: 'datetime',
inputType: 'datetime',
defaultValue: '',
},
{
name: 'isFollowUp',
label: 'Follow-up',
scope: 'global',
dataType: 'boolean',
inputType: 'switch',
defaultValue: '',
},
],
});5) Education: LMS Courses
export const course = defineEntity({
name: 'course',
plural: 'courses',
display: 'title',
menu: { label: 'Courses', group: 'catalog' },
attributes: [
{
name: 'title',
label: 'Title',
scope: 'local',
dataType: 'string',
inputType: 'text',
defaultValue: '',
},
{
name: 'description',
label: 'Description',
scope: 'local',
dataType: 'string',
inputType: 'editor',
defaultValue: '',
},
{
name: 'instructor',
label: 'Instructor',
scope: 'relationship',
dataType: 'string',
inputType: 'relationship',
defaultValue: '',
relationship: { mode: 'single', entity: 'instructor', field: 'name' },
},
{
name: 'published',
label: 'Published',
scope: 'global',
dataType: 'boolean',
inputType: 'switch',
defaultValue: '',
},
],
});Example Design Checklist
- Set
displayto one attribute name per entity. - Use relationships for reusable dimensions.
- Choose
localscope for localized/regional values. - Keep IDs, SKUs, and core references global and stable.
Last updated on