Templates
Templates are installable application bundles that combine Next.js pages, serverless scripts, and API resources into a single deployable package. Templates enable developers to distribute complete, customizable solutions on the marketplace with automatic subdomain deployment and dependency management.
Syntax
Creating a Template
Template Structure
Template Components
Templates consist of three primary components that work together to create complete applications.
Page
pageA Next.js page component that serves as the template's user interface. Pages are built, optimized, and deployed to a CDN with automatic subdomain assignment.
Pages support React Server Components, client-side interactivity, and the full Next.js App Router feature set.
Scripts
scriptsServerless functions that provide backend logic, data processing, and API integrations. Scripts are deployed to the Mirra platform and can be invoked by the page or triggered by events.
Resources
resourcesReferences to marketplace resources that the template depends on. Resources can be required (installation fails without them) or optional (enhanced functionality when available).
During installation, the platform automatically installs required resources and prompts for optional ones.
Description
Templates provide a distribution mechanism for complete applications on the Mirra marketplace. Each template bundles a Next.js frontend, serverless backend scripts, and external API integrations into a single installable package that users can deploy with customization.
When a user installs a template, the platform performs several operations: validates dependencies, deploys scripts to the Mirra platform, builds and uploads the Next.js page to a CDN, assigns a unique subdomain, and applies user customization. The result is a fully functional application accessible at template-name.username.getmirra.app.
Repository Structure
Templates are stored in Git repositories with a standardized directory structure:
The template.json file defines the template configuration, including name, version, dependencies, and customization options. The page.tsx file serves as the Next.js page entry point.
See a complete working example at github.com/Oz-Networks/mirra-sdk/tree/main/templates/example-template
Build Process
Templates must be built before publishing. The build process compiles the Next.js page, bundles dependencies, optimizes assets, and uploads the result to a CDN.
The build executes five steps:
- Dependency installation - Installs NPM packages from
package.json - Next.js compilation - Builds the page with production optimizations
- Asset optimization - Compresses images, minifies JavaScript and CSS
- CDN upload - Uploads build artifacts to the content delivery network
- Metadata update - Records the CDN URL and build status
Build failures typically result from missing dependencies, TypeScript errors, or invalid Next.js configuration. Check build logs for specific error messages.
Customization
Templates support user customization through configurable fields. Customization enables users to personalize branding, behavior, and feature flags without modifying code.
Customization fields support five data types:
colorHex color values for branding and theming. Rendered as a color picker in the installation UI.
numberNumeric values for intervals, limits, and quantities. Supports integers and decimals.
booleanFeature flags and toggles. Rendered as a checkbox in the installation UI.
stringText values for names, URLs, and configuration strings.
selectEnumerated options from a predefined list. Rendered as a dropdown menu.
Customization values are injected into the template at installation time and accessible in both page components and scripts through environment variables.
Examples
Creating a Template
This example creates a cryptocurrency portfolio tracker template with customization options.
Request
Response
Building a Template
Build the template to prepare it for publishing.
Request
Response
Checking Installation Requirements
Verify whether a user can install a template and view estimated costs.
Request
Response
The missingResources array lists required resources the user has not yet installed. Installation fails if required resources are missing.
Installing a Template
Install a template with custom configuration values.
Request
Response
The installation process validates dependencies, deploys scripts, installs resources, builds the page, assigns a subdomain, and applies customization.
Publishing a Template
Publish a template to the marketplace with pricing configuration.
Request
Publishing Requirements
- Template successfully built with valid CDN URL
- All resource dependencies available in marketplace
- Complete metadata (name, description, version)
To unpublish and remove from marketplace:
Unpublishing prevents new installations but does not affect existing installations.
Pricing
Templates use composite pricing that combines setup fees, recurring hosting costs, and usage-based charges.
Pricing Components:
setupFee- One-time installation fee charged when the template is first installedmonthlyFee- Recurring monthly hosting fee for page deployment and subdomainestimatedUsageCost.perUse- Estimated cost per script execution or resource callestimatedUsageCost.perMonth- Estimated total monthly usage cost based on typical usagebreakdown- Cost breakdown showing script execution and resource API costs separately
Actual usage costs vary based on script invocation frequency and resource pricing. The platform tracks usage and bills users monthly.
Versioning
Templates use semantic versioning (MAJOR.MINOR.PATCH) to track changes and enable safe updates.
Version Format
1.0.0- Major.Minor.Patch for stable releases1.0.0-beta.1- Pre-release versions with label and number1.0.0-alpha.3- Alpha versions for early testing
Creating Versions
Each version references a specific Git commit hash, enabling reproducible builds and rollback capabilities. Users can upgrade installations to newer versions or pin to specific versions.
Troubleshooting
Build Failures
When template builds fail, check the build logs for specific error messages. Common causes include:
- Missing dependencies in
package.json- Verify all imports have corresponding package entries - TypeScript compilation errors - Run
tsc --noEmitlocally to identify type issues - Invalid Next.js configuration - Ensure
next.config.jsfollows Next.js 13+ App Router conventions - CDN upload failures - Verify network connectivity and CDN credentials
To debug locally, clone the repository and run npm run build to reproduce build errors.
Installation Failures
Installation fails when dependencies are missing or incompatible. Common issues:
- Missing required resources - Check
check-requirementsendpoint before installation - Incompatible versions - Verify template version compatibility with platform version
- Insufficient permissions - Ensure API key has
templates:installpermission - Quota exceeded - Check account limits for templates, scripts, and resources
Install missing resources manually before attempting template installation.
Customization Not Applied
When customization values do not appear in the deployed template:
- Verify field keys in customization request match
template.jsondefinitions exactly - Confirm data types match field type specifications (string, number, boolean, color, select)
- Check that values are within allowed ranges or option sets
- Rebuild the template after changing customization configuration
Customization values are injected at build time, not runtime. Changes require a rebuild.
See Also
- Scripts - Serverless functions for template backend logic
- Resources - API integrations for template functionality
- Examples: Templates - Complete template implementation examples
- Example Template Repository - Reference implementation
- Marketplace - Browse published templates