Skip to main content

Template Tables

Overview

The template tables manage the complete lifecycle of code generation templates, including template content, metadata, marketplace features, purchases, and reviews. Templates are the core engine of Scoriet's code generation capability.


templates

Stores master template definitions with metadata, pricing, and marketplace information.

Purpose

  • Store template definitions and metadata
  • Manage template visibility and distribution (private/public/store)
  • Track template versions, pricing, and sales
  • Manage template cloning and inheritance
  • Support template marketplace and monetization

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
namestring(100)NO-Template name
full_namestring(500, indexed)YESNULLFull template name with branding
descriptiontextYESNULLTemplate description
categorystring(100)NOWebTemplate category (Web, Mobile, Desktop, API, Database, etc.)
languagestring(50, indexed)NO-Primary language (PHP, Python, Node.js, Java, C#, etc.)
is_activebooleanNOtrueTemplate active status
tagsjsonYESNULLSearch tags (JSON array)
file_countintegerNO0Number of template files
creator_user_idunsignedBigInteger(FK)YESNULLFK: users.id - Template creator
project_idunsignedBigInteger(FK)YESNULLFK: projects.id - Associated project
visibilityenumYESprivateVisibility (private, public, store)
visibility_lockedbooleanNOfalseLock template visibility from changes
price_typeenumYESNULLPricing model (credits, euros)
price_creditsintegerYESNULLPrice in platform credits
price_eurosdecimalYESNULLPrice in euros
is_store_approvedbooleanNOfalseMarketplace approval status
fingerprints_generatedbooleanNOfalseContent fingerprints generated
fingerprints_generated_attimestampYESNULLFingerprint generation timestamp
sales_countunsignedBigIntegerNO0Total sales count
total_revenuedecimal(12)NO0Total lifetime revenue
review_statusenumNOdraftReview status (draft, pending_review, approved, rejected)
review_scoreintegerNO0Marketplace review score
is_system_templatebooleanNOfalseSystem/built-in template flag
original_template_idunsignedBigInteger(FK, indexed)YESNULLFK: templates.id - Original if this is a clone
cloned_from_template_idunsignedBigInteger(FK, indexed)YESNULLFK: templates.id - Parent if cloned from another
is_from_storebooleanNOfalseDownloaded from store flag
resale_allowedbooleanNOfalseAllow cloning and resale
template_typeenum(indexed)NOoriginalType (original, cloned, linked)
historyjsonYESNULLFork and contribution history (JSON)
community_ratingjsonYESNULLCommunity reviews and ratings (JSON)
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp
protected_filesjsonYESNULLFiles protected from overwrite (JSON array)
install_scriptjsonYESNULLInstallation instructions (JSON)
update_scriptjsonYESNULLUpdate instructions (JSON)
compatibility_tagstring(100)YESNULLCompatibility marker (e.g., 'Laravel 12', 'React 19')
generation_orderintegerYESNULLGeneration order in multi-template projects
versionstring(20)YESNULLTemplate version string (e.g., '1.0.0')

Indexes

  • Primary Key: id
  • Regular: full_name, language, template_type, is_system_template
  • Composite: (category, is_active), (creator_user_id, visibility), (is_system_template, visibility), (project_id, visibility)
  • Foreign Keys: original_template_id, cloned_from_template_id, creator_user_id, project_id

Relationships

  • Belongs To → Users (creator)
  • Belongs To → Projects (optional)
  • Has Many → Template Files
  • Has Many → Template Variables
  • Has Many → Template Fingerprints
  • Has Many → Template Media
  • Has Many → Template Reviews
  • Has Many → Template Purchases
  • Has Many → Template Schema Dependencies
  • Has One → Original Template (if cloned)

Template Types

  • original: User-created or system templates
  • cloned: Copy of another template
  • linked: Reference to another template (for inheritance)

Visibility Levels

  • private: Only accessible to creator
  • public: Visible to all users, available for forking
  • store: Listed in marketplace for purchase

Review Status

  • draft: Not yet submitted for review
  • pending_review: Awaiting moderator review
  • approved: Approved for marketplace
  • rejected: Rejected (can be resubmitted)

template_files

Stores individual template files with content and metadata.

Purpose

  • Store template file content
  • Track file metadata and settings
  • Support file-level include directives
  • Map files to form windows for UI generation

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
file_namestring(255)NO-Filename (e.g., 'index.php', 'controller.php')
file_pathstring(500)NO-Output path relative to project root
file_contentmediumTextNO-File content with template variables/directives
file_typestring(50)NOtemplateFile type (template, configuration, document, etc.)
content_typeenumNOtextContent type (text, zip)
zip_filenamestring(255)YESNULLIf content_type=zip, the zip filename
output_pathstring(500)YESNULLTemplate output path variable
file_orderintegerNO0Generation order
form_window_typeinteger(0-5)YESNULLAssociated form window type
is_include_onlybooleanNOfalseOnly used via include directive
inject_snippetsjsonYESNULLSnippet injection points (JSON)
inject_separatorjsonYESNULLSeparator between injected snippets
language_overridestring(50)YESNULLOverride template language for this file
versionintegerNO1File version number
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Foreign Key: template_id
  • Composite: (template_id, file_name) - Unique filenames per template

Relationships

  • Belongs To → Templates
  • Has Many → Template Fingerprints
  • Has Many → Template File Field Assignments

Form Window Types

  • 0: Main menu
  • 1: Create/edit window
  • 2: Data table
  • 3: Report (single record)
  • 4: Report (list)
  • 5: Other/custom

Content Types

  • text: Plain text template file
  • zip: Zipped file(s) to be extracted

template_variables

Stores input variables/parameters for templates.

Purpose

  • Define template placeholders and parameters
  • Specify variable requirements and defaults
  • Document template inputs

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
variable_namestring(100)NO-Variable name (e.g., 'projectname', 'author')
descriptiontextYESNULLVariable description and usage
default_valuestring(500)YESNULLDefault value if not provided
is_requiredbooleanNOfalseWhether variable is required
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Unique: (template_id, variable_name) - Variable names unique per template
  • Foreign Key: template_id

Relationships

  • Belongs To → Templates
  • Has Many → Project Template Variable Values (for runtime values)

Common Variables

  • projectname: Project name
  • projectauthor: Project author
  • namespace: PHP namespace
  • package: Java/Python package
  • author: Template author name
  • copyright: Copyright text
  • license: Software license type

template_fingerprints

Stores content hashes and signatures for change detection.

Purpose

  • Detect template file changes
  • Track content modifications
  • Support update detection for cloned templates

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
template_file_idunsignedBigInteger(FK)YESNULLFK: template_files.id - Specific file
file_hashstring(64)NO-SHA-256 hash of file content
normalized_contenttextYESNULLNormalized content for comparison
content_lengthintegerNO-Content length in bytes
token_signaturejsonYESNULLTokenized signature for pattern matching
file_typestring(50)NO-File type (code, doc, config, etc.)
is_significantbooleanNOtrueWhether this is a significant change
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Foreign Keys: template_id, template_file_id
  • Regular: file_hash - Quick hash lookups
  • Composite: (template_id, file_hash) - Detect duplicates

Relationships

  • Belongs To → Templates
  • Belongs To → Template Files (optional)

Hashing Strategy

  • Uses SHA-256 for content hashing
  • Normalized content removes whitespace/formatting
  • Token signature enables intelligent change detection
  • Supports detection of renamed/moved files

template_media

Stores marketing media (logos, images, videos) for templates.

Purpose

  • Store template marketing images and videos
  • Support template showcase/preview
  • Manage template branding

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
media_typeenumNO-Media type (logo, image, video)
file_pathstring(500)YESNULLLocal file path (for stored media)
file_datalongBlobYESNULLBinary media data (for inline storage)
mime_typestring(100)YESNULLMIME type (image/png, video/mp4, etc.)
file_sizeintegerYESNULLFile size in bytes
video_urlstring(500)YESNULLExternal video URL (YouTube, etc.)
titlestring(255)YESNULLMedia title/caption
descriptiontextYESNULLMedia description
sort_orderintegerNO0Display order
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Foreign Key: template_id

Relationships

  • Belongs To → Templates

Media Types

  • logo: Template logo/icon
  • image: Screenshot or promotional image
  • video: Demo or preview video

template_purchases

Tracks marketplace purchases and payment history.

Purpose

  • Record template purchases
  • Track buyer/seller relationships
  • Calculate earnings and payouts
  • Support dispute resolution

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
buyer_user_idunsignedBigInteger(FK)NO-FK: users.id - Buyer
seller_user_idunsignedBigInteger(FK)NO-FK: users.id - Seller/Creator
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
payment_typeenumNO-Payment method (credits, euros)
price_creditsintegerYESNULLPrice in credits (if paid in credits)
price_eurosdecimal(10,2)YESNULLPrice in euros (if paid in euros)
is_paid_outbooleanNOfalsePayout processed flag
payout_idunsignedBigInteger(FK)YESNULLFK: payouts.id - Associated payout
paid_out_attimestampYESNULLPayout timestamp
seller_earningsdecimal(10,2)YESNULLSeller's share of payment
platform_feedecimal(10,2)YESNULLPlatform's share of payment
transaction_referencestring(100)YESNULLExternal payment reference
notestextYESNULLTransaction notes
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Unique: (buyer_user_id, template_id) - User can only buy template once
  • Composite: (seller_user_id, is_paid_out), (template_id, created_at)
  • Foreign Keys: buyer_user_id, seller_user_id, template_id, payout_id

Relationships

  • Belongs To → Users (buyer)
  • Belongs To → Users (seller)
  • Belongs To → Templates
  • Belongs To → Payouts

template_reviews

Stores user reviews and ratings for marketplace templates.

Purpose

  • Collect user feedback on templates
  • Build community reputation
  • Provide social proof for marketplace

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
reviewer_user_idunsignedBigInteger(FK)NO-FK: users.id - Review author
votetinyIntNO-Rating (1-5 stars)
commenttextYESNULLReview comment/feedback
is_verified_purchasebooleanNOfalseVerified purchase flag
helpful_countintegerNO0Count of helpful votes
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Unique: (template_id, reviewer_user_id) - One review per user per template
  • Composite: (template_id, vote, created_at) - For sorting reviews
  • Foreign Keys: template_id, reviewer_user_id

Relationships

  • Belongs To → Templates
  • Belongs To → Users (reviewer)

template_schema_dependencies

Defines which database schemas are required for template functionality.

Purpose

  • Specify schema requirements for templates
  • Support dependency management
  • Enable compatibility checking

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_idunsignedBigInteger(FK)NO-FK: templates.id (CASCADE)
schema_idunsignedBigInteger(FK)NO-FK: schemas.id (CASCADE)
is_requiredbooleanNOtrueRequired or optional dependency
aliasstring(100)YESNULLAlias for the schema in template
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Unique: (template_id, schema_id) - Each schema once per template
  • Foreign Keys: template_id, schema_id

Relationships

  • Belongs To → Templates
  • Belongs To → Schemas

Usage

When generating code, Scoriet checks if all required schemas are available in the project before template generation.


template_file_field_assignments

Maps form fields to template files for visibility control.

Purpose

  • Control field visibility in template-generated forms
  • Map schema fields to specific template files
  • Define field state (visible, grayed, inactive, invisible)

Fields

FieldTypeNullDefaultDescription
idbigIncrementsNOAutoPrimary key
template_file_idunsignedBigInteger(FK)NO-FK: template_files.id (CASCADE)
schema_field_idunsignedBigInteger(FK)NO-FK: schema_fields.id (CASCADE)
visibility_stateenumNOvisibleVisibility (visible, grayed, inactive, invisible, not_available)
sort_orderintegerNO0Display order
created_byunsignedBigInteger(FK)YESNULLFK: users.id - Assignment creator
created_attimestampNO-Creation timestamp
updated_attimestampNO-Last update timestamp

Indexes

  • Primary Key: id
  • Unique: (template_file_id, schema_field_id) - Each field once per file
  • Foreign Keys: template_file_id, schema_field_id, created_by

Relationships

  • Belongs To → Template Files
  • Belongs To → Schema Fields
  • Belongs To → Users (creator)

Visibility States

  • visible: Field shown and editable
  • grayed: Field shown but disabled
  • inactive: Field hidden but data preserved
  • invisible: Field completely hidden
  • not_available: Field not applicable to this template

Key Concepts

Template Hierarchy

Templates (master definition)
├── Template Files (content to generate)
├── Template Variables (input parameters)
├── Template Fingerprints (change detection)
├── Template Media (marketing images)
└── Template Dependencies (required schemas)

Template Types and Versioning

  • Original: Created from scratch
  • Cloned: Copy from another template (independent)
  • Linked: Reference/inheritance (changes propagate)

Template Lifecycle

  1. Creation (draft status)
  2. Development (private visibility)
  3. Testing with projects
  4. Public release (optional)
  5. Store submission → Review → Approval
  6. Sales and earnings tracking

Monetization

  • Free: No pricing set, distributed for free
  • Credits: Purchased with platform credits
  • Euros: Purchased with real currency (Stripe/PayPal)
  • Hybrid: Price in both currencies

Marketplace Features

  • Visibility control (private/public/store)
  • Review system and ratings
  • Sales tracking and revenue reports
  • Verified purchase badges
  • Template recommendations

  • See Core Tables for user and creator information
  • See Project Tables for template usage in projects
  • See Schema Tables for template schema requirements
  • See Generation Domain for template usage in code generation