Creating Custom Templates
Learn how to create your own Orchestre templates tailored to your specific needs, technology stack, or domain. Custom templates encode your best practices and accelerate future projects.
Understanding Templates
An Orchestre template is more than boilerplate code - it's a complete knowledge system that includes:
- Code structure optimized for your use case
- Dynamic commands that understand your domain
- Pattern library with proven solutions
- Memory templates for consistent documentation
- Configuration for your specific stack
Template Structure
A complete template follows this structure:
my-template/
├── template.json # Template metadata
├── CLAUDE.md # Template documentation
├── commands/ # Template-specific commands
│ ├── add-feature.md
│ ├── setup-auth.md
│ └── deploy.md
├── patterns/ # Reusable patterns
│ ├── error-handling.md
│ ├── data-access.md
│ └── api-design.md
├── memory-templates/ # Documentation templates
│ ├── feature.md
│ ├── api.md
│ └── decision.md
├── src/ # Template source code
│ └── ...
└── .orchestre/ # Orchestre configurationCreating Your Template
Step 1: Define Template Metadata
Create template.json:
{
"name": "my-custom-template",
"displayName": "My Custom Template",
"description": "A template for building [your domain] applications",
"version": "1.0.0",
"author": "Your Name",
"repository": "https://github.com/yourusername/my-template",
"keywords": ["custom", "domain-specific"],
"requirements": {
"node": ">=18.0.0",
"orchestreVersion": ">=3.0.0"
},
"setupCommands": [
"npm install",
"npm run setup"
],
"structure": {
"sourceDir": "src",
"commandsDir": "commands",
"patternsDir": "patterns"
},
"features": [
"authentication",
"database",
"api",
"testing"
]
}Step 2: Create Template Documentation
Write CLAUDE.md:
# My Custom Template
## Overview
This template is designed for building [specific type] applications with:
- [Key feature 1]
- [Key feature 2]
- [Key feature 3]
## Technology Stack
- **Framework**: [Your framework]
- **Database**: [Your database]
- **Authentication**: [Auth solution]
- **Deployment**: [Platform]
## Architecture Principles
1. [Principle 1]
2. [Principle 2]
3. [Principle 3]
## Getting Started
1. Run `/create my-app my-custom-template`
2. Configure environment variables
3. Run `/orchestrate` to plan your features
4. Use template commands for common tasks
## Template Commands
- `/add-[feature]` - Add domain-specific features
- `/setup-[service]` - Configure external services
- `/deploy-[environment]` - Deploy to different environments
## Conventions
- File naming: [convention]
- Code style: [style guide]
- Testing: [approach]
- Documentation: [standards]Step 3: Design Template Commands
Create intelligent commands that understand your domain:
Example: Domain-Specific Feature Command
Create commands/add-entity.md:
# /add-entity
Add a complete entity with model, API, and UI following our domain patterns.
## Prompt
You are helping create a new entity in a [domain] application.
First, analyze the existing codebase to understand:
1. Current entity patterns
2. API conventions
3. UI component structure
4. Testing approaches
Then implement a complete entity with:
### Data Model
- Database schema/model
- Validation rules
- Relationships with other entities
- Migration files
### API Layer
- CRUD endpoints following REST/GraphQL conventions
- Input validation
- Error handling
- Authentication/authorization
- API documentation
### Business Logic
- Service layer with domain logic
- Event handlers if using event-driven
- Integration with other services
- Caching strategy
### UI Components
- List view with filtering/sorting
- Detail view
- Create/Edit forms
- Delete confirmation
- Loading and error states
### Testing
- Unit tests for business logic
- Integration tests for API
- Component tests for UI
- E2E test scenarios
## Parameters
- `name`: Entity name (required)
- `fields`: Comma-separated list of fields
- `relationships`: Related entities
- `features`: Additional features (search, export, etc.)
## Examples
```bash
/add-entity User "email,name,role"
/add-entity Product "name,price,category" --features "search,inventory"
/add-entity Order --relationships "User,Product" --features "workflow,notifications"
#### Example: Setup Command
Create `commands/setup-monitoring.md`:
```markdown
# /setup-monitoring
Configure comprehensive monitoring for our [domain] application.
## Prompt
Set up monitoring tailored to our domain needs:
1. **Analyze Requirements**
- Identify critical business metrics
- Determine performance KPIs
- List compliance requirements
2. **Configure Monitoring Stack**
Based on our stack, implement:
- Application Performance Monitoring (APM)
- Error tracking
- Log aggregation
- Custom metrics
- Alerting rules
3. **Domain-Specific Metrics**
For our [domain], track:
- [Metric 1]: [Description]
- [Metric 2]: [Description]
- [Metric 3]: [Description]
4. **Dashboards**
Create dashboards for:
- Technical metrics
- Business metrics
- User experience metrics
## Implementation
[Specific implementation details for your stack]Step 4: Create Pattern Library
Document reusable patterns specific to your domain:
Create patterns/authentication.md:
# Authentication Pattern
## Overview
Our standard authentication approach using [method].
## Implementation
### Token Management
```typescript
// Standard token structure
interface AuthToken {
accessToken: string
refreshToken: string
expiresIn: number
tokenType: 'Bearer'
}
// Token refresh logic
async function refreshAuth(refreshToken: string): Promise<AuthToken> {
// Implementation specific to our needs
}Middleware Pattern
export function requireAuth(permissions?: string[]) {
return async (req: Request, res: Response, next: NextFunction) => {
// Our standard auth check
}
}Usage
- All protected routes use
requireAuthmiddleware - Tokens stored in [storage method]
- Refresh handled automatically by [component]
Security Considerations
- [Consideration 1]
- [Consideration 2]
### Step 5: Memory Templates
Create templates for consistent documentation:
Create `memory-templates/feature.md`:
```markdown
# Feature: {FEATURE_NAME}
## Overview
{BRIEF_DESCRIPTION}
## Business Requirements
- {REQUIREMENT_1}
- {REQUIREMENT_2}
## Technical Implementation
### Architecture
{ARCHITECTURE_DESCRIPTION}
### Key Components
- `{COMPONENT_1}`: {DESCRIPTION}
- `{COMPONENT_2}`: {DESCRIPTION}
### API Endpoints
- `{METHOD} {ENDPOINT}`: {DESCRIPTION}
### Database Changes
- {CHANGE_1}
- {CHANGE_2}
## Security Considerations
- {CONSIDERATION_1}
- {CONSIDERATION_2}
## Performance Notes
- {NOTE_1}
- {NOTE_2}
## Testing Strategy
- Unit tests: {COVERAGE}
- Integration tests: {SCENARIOS}
- E2E tests: {FLOWS}
## Deployment Notes
- {NOTE_1}
- {NOTE_2}
## Future Enhancements
- {ENHANCEMENT_1}
- {ENHANCEMENT_2}Advanced Template Features
1. Conditional Logic
Make templates adapt to different scenarios:
// template.json
{
"variants": {
"database": {
"prompt": "Which database?",
"options": ["postgresql", "mysql", "mongodb"],
"affects": ["src/db", "migrations", "commands/add-model.md"]
},
"authentication": {
"prompt": "Authentication method?",
"options": ["jwt", "session", "oauth"],
"affects": ["src/auth", "commands/setup-auth.md"]
}
}
}2. Dynamic Configuration
Allow runtime configuration:
// .orchestre/configure.js
export async function configure(answers) {
return {
replacements: {
'__APP_NAME__': answers.appName,
'__DATABASE__': answers.database,
'__PORT__': answers.port || 3000
},
exclude: answers.database === 'mongodb'
? ['migrations/**']
: ['src/mongodb/**']
}
}3. Post-Install Scripts
Run setup after template installation:
// .orchestre/post-install.js
export async function postInstall(projectPath, config) {
// Generate environment file
const envContent = `
DATABASE_URL=${config.database}://localhost
JWT_SECRET=${generateSecret()}
PORT=${config.port}
`.trim()
await fs.writeFile(
path.join(projectPath, '.env'),
envContent
)
// Run migrations
if (config.database !== 'mongodb') {
await exec('npm run migrate')
}
console.log('✅ Template configured successfully!')
}4. Template Composition
Build templates that extend others:
// template.json
{
"extends": "makerkit-nextjs",
"name": "my-saas-extension",
"additions": {
"commands": ["commands/"],
"patterns": ["patterns/"],
"source": ["src/extensions/"]
},
"overrides": {
"src/config/features.ts": "custom/features.ts"
}
}Testing Your Template
1. Local Testing
# Test template installation
/create test-app file:///path/to/my-template
# Test commands
cd test-app
/add-entity TestEntity
/setup-monitoring2. Automated Tests
Create test/template.test.js:
describe('My Custom Template', () => {
it('should create project structure', async () => {
const projectPath = await createProject('test', 'my-template')
expect(fs.existsSync(path.join(projectPath, 'src'))).toBe(true)
expect(fs.existsSync(path.join(projectPath, 'CLAUDE.md'))).toBe(true)
})
it('should run custom commands', async () => {
await runCommand('/add-entity', 'Test')
expect(fs.existsSync('src/entities/Test.ts')).toBe(true)
expect(fs.existsSync('src/api/test.ts')).toBe(true)
})
})Publishing Your Template
1. Package for Distribution
// package.json
{
"name": "@yourorg/orchestre-template-custom",
"version": "1.0.0",
"description": "Custom Orchestre template for [domain]",
"keywords": ["orchestre-template"],
"files": [
"template.json",
"CLAUDE.md",
"commands/",
"patterns/",
"memory-templates/",
"src/",
".orchestre/"
],
"orchestre": {
"type": "template"
}
}2. Publish to npm
npm publish --access public3. Use Published Template
/create my-app @yourorg/orchestre-template-customBest Practices
1. Keep It Focused
- One clear purpose per template
- Don't try to solve everything
- Make it excellent at one thing
2. Document Everything
- Clear README
- Comprehensive CLAUDE.md
- Example usage for every command
- Pattern explanations
3. Maintain Flexibility
- Use configuration over hard-coding
- Provide escape hatches
- Allow customization
4. Test Thoroughly
- Test all commands
- Verify different configurations
- Check edge cases
- Test on fresh systems
5. Version Carefully
- Follow semantic versioning
- Document breaking changes
- Provide migration guides
Examples of Domain-Specific Templates
1. E-commerce Template
/create shop ecommerce-template
# Includes: product catalog, cart, checkout, payment, shipping2. Healthcare Template
/create clinic healthcare-template
# Includes: HIPAA compliance, patient records, appointments, billing3. Education Template
/create school education-template
# Includes: courses, students, grades, assignments, LMS features4. IoT Template
/create iot-platform iot-template
# Includes: device management, data ingestion, real-time dashboardTroubleshooting
Common Issues
Template not found
- Check file paths in template.json
- Verify all referenced files exist
- Check npm package contents
Commands not working
- Ensure command files end with .md
- Check command file syntax
- Verify prompt section exists
Patterns not applied
- Check pattern file format
- Ensure patterns directory is included
- Verify pattern references
Next Steps
- Analyze your needs - What patterns do you repeat?
- Start simple - Create basic template first
- Add intelligence - Build smart commands
- Test extensively - Ensure reliability
- Share with community - Publish your template
Ready to create your template? Start with:
/orchestrate "Design a custom template for [your domain]"