docs/src/content/en/reference/templates/overview.mdx
This reference provides comprehensive information about Mastra templates, including how to use existing templates, create your own, and contribute to the community ecosystem.
Mastra templates are pre-built project structures that demonstrate specific use cases and patterns. They provide:
Install a template using the create-mastra command:
npx create-mastra@latest --template template-name
This creates a complete project with all necessary code and configuration.
After installation:
Navigate to project directory:
cd your-project-name
Configure environment variables:
cp .env.example .env
Edit .env with required API keys as documented in the template's README.
Install dependencies (if not done automatically):
npm install
Start development server:
npm run dev
All templates follow this standardized structure:
Templates must meet these technical requirements:
src/mastra/ directorysrc/mastra/agents/src/mastra/tools/src/mastra/workflows/src/mastra/index.tsUse the standard Mastra TypeScript configuration:
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"outDir": "dist"
},
"include": ["src/**/*"]
}
Include a .env.example file with all required environment variables:
# LLM provider API keys (choose one or more)
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key_here
# Other service API keys as needed
OTHER_SERVICE_API_KEY=your_api_key_here
We recommend using OpenAI, Anthropic, or Google model providers for templates. Choose the provider that best fits your use case:
import { Agent } from '@mastra/core/agent'
const agent = new Agent({
name: 'example-agent',
model: 'openai/gpt-5.4', // or other provider strings
instructions: 'Your agent instructions here',
})
Templates must be:
"type": "module" in package.json)Every template must include a comprehensive README:
# Template Name
Brief description of what the template demonstrates.
## Overview
Detailed explanation of the template's functionality and use case.
## Setup
1. Copy `.env.example` to `.env` and fill in your API keys
2. Install dependencies: `npm install`
3. Run the project: `npm run dev`
## Environment variables
- `OPENAI_API_KEY`: Your OpenAI API key. Get one at [OpenAI Platform](https://platform.openai.com/api-keys)
- `ANTHROPIC_API_KEY`: Your Anthropic API key. Get one at [Anthropic Console](https://console.anthropic.com/settings/keys)
- `GOOGLE_GENERATIVE_AI_API_KEY`: Your Google AI API key. Get one at [Google AI Studio](https://makersuite.google.com/app/apikey)
- `OTHER_API_KEY`: Description of what this key is for
## Usage
Instructions on how to use the template and examples of expected behavior.
## Customization
Guidelines for modifying the template for different use cases.
Include clear comments explaining:
Templates must demonstrate:
For information on contributing your own templates to the Mastra ecosystem, see the Contributing Templates guide in the community section.
:::info
Templates provide an excellent way to learn Mastra patterns and accelerate development. Contributing templates helps the entire community build better AI applications.
:::