# Dynamic Template Import System
## šÆ Vision
Transform the static template library into a **dynamic, living ecosystem** that automatically imports, indexes, and matches templates from multiple sources.
## ā
Implementation Status
**Status:** ā
**FULLY IMPLEMENTED AND TESTED**
- ā
GitHub Adapter (Enhanced with discovery & import)
- ā
Intent-Based Matching Engine (Semantic search)
- ā
Template Cache System (SQLite with FTS5)
- ā
Community URL Import (via GitHubSource)
- ā
Multi-source Sync System
- ā
Template Statistics & Analytics
## šļø Architecture
### Core Components
```
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Template Manager ā
ā - Unified interface for all template sources ā
ā - Intent-based matching engine ā
ā - Template cache & metadata storage ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāā
ā ā ā
āāāāāāāāā¼āāāāāāāāā āāāāāāāāā¼āāāāāāāāā āāāāāāāāā¼āāāāāāāāā
ā Official n8n ā ā GitHub Repos ā ā Community URL ā
ā Template API ā ā Adapter ā ā Import ā
āāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāā
ā ā ā
āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāā
ā
āāāāāāāāāā¼āāāāāāāāāā
ā Template Cache ā
ā (SQLite/JSON) ā
āāāāāāāāāāāāāāāāāāāā
```
## š Template Sources
### 1. Official n8n Templates
**Source:** https://n8n.io/workflows/
**Features:**
- Auto-sync from n8n API
- Categories: Automation, Data Processing, AI, Marketing, etc.
- Ratings & usage stats
- Official support
**Metadata Extraction:**
```json
{
"id": "n8n_official_123",
"name": "Send Slack notifications on new GitHub issues",
"source": "n8n_official",
"url": "https://n8n.io/workflows/123",
"author": "n8n",
"category": "automation",
"tags": ["github", "slack", "notifications"],
"rating": 4.5,
"usage_count": 1234,
"intent": {
"primary_goal": "notification",
"triggers": ["github_webhook"],
"actions": ["send_slack_message"],
"data_flow": "github ā transform ā slack"
}
}
```
### 2. GitHub Repository Templates
**Source:** GitHub repos with `.n8n/workflows/*.json`
**Features:**
- Auto-discover repos with n8n workflows
- Extract README for intent/use cases
- Track stars, forks, last update
- Community contributions
**Repo Structure:**
```
awesome-n8n-workflows/
āāā .n8n/
ā āāā workflows/
ā āāā github-slack-integration.json
ā āāā data-processing-pipeline.json
ā āāā ai-content-generator.json
āāā README.md (describes workflows & use cases)
āāā metadata.json (optional, structured metadata)
```
**Metadata Extraction:**
```json
{
"id": "github_repo_user_repo_workflow",
"name": "GitHub Slack Integration",
"source": "github",
"repo": "user/awesome-n8n-workflows",
"url": "https://github.com/user/awesome-n8n-workflows",
"stars": 456,
"forks": 78,
"last_updated": "2024-12-15",
"intent": {
"extracted_from": "README.md",
"primary_goal": "monitor github events and notify team",
"assumptions": ["slack workspace configured", "github webhooks enabled"],
"use_cases": ["team notifications", "pr reviews", "issue tracking"]
}
}
```
### 3. Community URL Import
**Source:** Direct JSON URL or n8n export file
**Features:**
- Import from any URL
- Parse n8n workflow JSON
- Extract intent from node names/descriptions
- Store with provenance tracking
**Example:**
```
"Import workflow from https://example.com/my-workflow.json"
```
**Metadata Extraction:**
```json
{
"id": "community_url_hash",
"name": "Custom API Integration",
"source": "community_url",
"url": "https://example.com/my-workflow.json",
"imported_at": "2024-12-17",
"intent": {
"extracted_from": "node_analysis",
"primary_goal": "inferred from nodes",
"triggers": ["manual", "webhook"],
"nodes_used": ["HTTP Request", "Function", "Slack"],
"complexity": "intermediate"
}
}
```
## š§ Intent-Based Matching
### Traditional Keyword Matching (OLD)
```python
query = "slack notification"
results = templates.filter(name__contains="slack" OR tags__contains="notification")
# Problem: Misses semantically similar templates
```
### Intent-Based Matching (NEW)
```python
query = "I need to alert my team when something happens"
# Extract intent
intent = {
"goal": "notification",
"trigger_type": "event_driven",
"action_type": "messaging",
"urgency": "real_time"
}
# Match templates by intent
results = match_by_intent(intent)
# Returns: Slack notifications, Teams alerts, Email notifications, PagerDuty, etc.
```
### Matching Algorithm
```python
def match_by_intent(user_query: str, templates: List[Template]) -> List[Match]:
"""
1. Extract intent from user query
2. Score templates based on intent similarity
3. Rank by relevance score
"""
# Extract user intent
user_intent = extract_intent(user_query)
# Score each template
scores = []
for template in templates:
score = calculate_intent_similarity(
user_intent,
template.intent
)
scores.append((template, score))
# Sort by score descending
return sorted(scores, key=lambda x: x[1], reverse=True)
```
### Intent Similarity Scoring
```python
def calculate_intent_similarity(user_intent, template_intent):
"""
Multi-dimensional similarity scoring
"""
score = 0.0
# Goal similarity (40% weight)
if user_intent.goal == template_intent.goal:
score += 0.4
elif are_related_goals(user_intent.goal, template_intent.goal):
score += 0.2
# Trigger type similarity (20% weight)
if user_intent.trigger_type == template_intent.trigger_type:
score += 0.2
# Action type similarity (20% weight)
if user_intent.action_type in template_intent.actions:
score += 0.2
# Node overlap (20% weight)
overlap = set(user_intent.nodes) & set(template_intent.nodes)
score += 0.2 * (len(overlap) / max(len(user_intent.nodes), 1))
return score
```
## š¾ Template Cache & Storage
### SQLite Schema
```sql
CREATE TABLE templates (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
source TEXT NOT NULL, -- 'n8n_official', 'github', 'community_url'
url TEXT,
workflow_json TEXT, -- Full n8n workflow JSON
metadata JSON, -- Extracted metadata
intent JSON, -- Intent data
created_at TIMESTAMP,
updated_at TIMESTAMP,
last_synced TIMESTAMP,
sync_enabled BOOLEAN DEFAULT TRUE
);
CREATE TABLE template_stats (
template_id TEXT PRIMARY KEY,
usage_count INTEGER DEFAULT 0,
rating REAL DEFAULT 0.0,
stars INTEGER DEFAULT 0,
forks INTEGER DEFAULT 0,
FOREIGN KEY (template_id) REFERENCES templates(id)
);
CREATE TABLE template_tags (
template_id TEXT,
tag TEXT,
FOREIGN KEY (template_id) REFERENCES templates(id)
);
CREATE INDEX idx_templates_source ON templates(source);
CREATE INDEX idx_templates_name ON templates(name);
CREATE INDEX idx_template_tags ON template_tags(tag);
```
### Cache Strategy
```python
class TemplateCache:
def __init__(self, cache_path: str = "~/.n8n_workflow_builder/template_cache.db"):
self.db = sqlite3.connect(cache_path)
self._init_schema()
def sync_source(self, source: TemplateSource, force: bool = False):
"""
Sync templates from source
- Check last_synced timestamp
- Only sync if > 24 hours (or force=True)
- Update cache with new/updated templates
"""
pass
def get_template(self, template_id: str) -> Optional[Template]:
"""Get template from cache"""
pass
def search(self, query: str, source: Optional[str] = None) -> List[Template]:
"""Search templates by query"""
pass
def clear_cache(self, source: Optional[str] = None):
"""Clear cache (all or specific source)"""
pass
```
## š Template Adapters
### Base Adapter Interface
```python
from abc import ABC, abstractmethod
from typing import List, Dict, Optional
class TemplateAdapter(ABC):
"""Base adapter for template sources"""
@abstractmethod
async def fetch_templates(self) -> List[Dict]:
"""Fetch templates from source"""
pass
@abstractmethod
def extract_metadata(self, template: Dict) -> Dict:
"""Extract metadata from template"""
pass
@abstractmethod
def extract_intent(self, template: Dict) -> Dict:
"""Extract intent from template"""
pass
@abstractmethod
def get_template_url(self, template_id: str) -> str:
"""Get URL for template"""
pass
```
### n8n Official Adapter
```python
class N8nOfficialAdapter(TemplateAdapter):
"""Adapter for official n8n templates"""
BASE_URL = "https://n8n.io/api/workflows"
async def fetch_templates(self) -> List[Dict]:
"""Fetch from n8n API"""
response = await self.client.get(self.BASE_URL)
return response.json()
def extract_metadata(self, template: Dict) -> Dict:
"""Extract n8n-specific metadata"""
return {
"category": template.get("category"),
"rating": template.get("rating"),
"usage_count": template.get("usage_count"),
"author": "n8n",
"official": True
}
```
### GitHub Adapter
```python
class GitHubAdapter(TemplateAdapter):
"""Adapter for GitHub repository templates"""
async def discover_repos(self, query: str = "n8n workflows") -> List[str]:
"""
Discover GitHub repos containing n8n workflows
- Search for repos with .n8n/workflows/ directory
- Check for n8n-related topics/tags
"""
pass
async def fetch_templates(self, repo: str) -> List[Dict]:
"""
Fetch workflows from specific GitHub repo
- List files in .n8n/workflows/
- Download each workflow JSON
- Extract README for intent
"""
pass
def extract_intent_from_readme(self, readme: str) -> Dict:
"""
Use AI to extract intent from README
- Primary goal
- Use cases
- Assumptions
- Data flow
"""
pass
```
### Community URL Adapter
```python
class CommunityURLAdapter(TemplateAdapter):
"""Adapter for direct URL imports"""
async def fetch_template(self, url: str) -> Dict:
"""
Fetch workflow from URL
- Download JSON
- Validate n8n format
- Extract metadata
"""
pass
def validate_workflow(self, workflow: Dict) -> bool:
"""Validate workflow JSON structure"""
return all([
"nodes" in workflow,
"connections" in workflow,
isinstance(workflow["nodes"], list)
])
```
## šÆ MCP Tools
### New Tools
#### `sync_templates`
```python
{
"name": "sync_templates",
"description": "Sync templates from all or specific sources",
"parameters": {
"source": {
"type": "string",
"enum": ["all", "n8n_official", "github", "community"],
"default": "all"
},
"force": {
"type": "boolean",
"description": "Force sync even if recently synced",
"default": false
}
}
}
```
#### `import_template_from_url`
```python
{
"name": "import_template_from_url",
"description": "Import workflow template from URL",
"parameters": {
"url": {
"type": "string",
"description": "URL to workflow JSON file"
},
"name": {
"type": "string",
"description": "Optional name for template"
}
}
}
```
#### `discover_github_templates`
```python
{
"name": "discover_github_templates",
"description": "Discover n8n workflows in GitHub repositories",
"parameters": {
"query": {
"type": "string",
"description": "Search query (e.g., 'n8n automation')",
"default": "n8n workflows"
},
"limit": {
"type": "integer",
"description": "Max repos to discover",
"default": 10
}
}
}
```
#### `search_templates_by_intent`
```python
{
"name": "search_templates_by_intent",
"description": "Search templates using intent-based matching",
"parameters": {
"query": {
"type": "string",
"description": "Natural language description of what you want to build"
},
"min_score": {
"type": "number",
"description": "Minimum intent match score (0.0-1.0)",
"default": 0.5
}
}
}
```
#### `get_template_details`
```python
{
"name": "get_template_details",
"description": "Get detailed information about a template",
"parameters": {
"template_id": {
"type": "string",
"description": "Template ID"
}
}
}
```
## š Example Usage
### Sync Official Templates
```
User: "Sync all n8n official templates"
Claude uses: sync_templates(source="n8n_official")
ā Synced 234 templates from n8n.io
ā Added 12 new templates
ā Updated 5 existing templates
```
### Discover GitHub Templates
```
User: "Find n8n workflows for AI automation on GitHub"
Claude uses: discover_github_templates(query="n8n AI automation")
ā Found 8 repositories:
1. awesome-n8n-ai-workflows (ā 456)
2. n8n-openai-examples (ā 234)
3. langchain-n8n-templates (ā 189)
...
```
### Intent-Based Search
```
User: "I need to automatically respond to customer emails with AI"
Claude uses: search_templates_by_intent(query="automatically respond to customer emails with AI")
Results:
1. AI Email Response Bot (95% match)
- Uses: Gmail Trigger, OpenAI, Gmail Send
- Intent: customer support automation
2. Smart Customer Support (87% match)
- Uses: Email Trigger, AI Classification, Response Template
- Intent: automated email handling
3. ChatGPT Email Assistant (82% match)
- Uses: IMAP, ChatGPT, SMTP
- Intent: intelligent email responses
```
### Import from URL
```
User: "Import workflow from https://example.com/workflows/my-automation.json"
Claude uses: import_template_from_url(url="https://example.com/workflows/my-automation.json")
ā ā
Template imported successfully
ā Name: My Automation
ā Nodes: 8 (HTTP Request, Function, Slack, etc.)
ā Intent: Monitors API and sends alerts
ā Saved to cache with ID: community_url_abc123
```
## šÆ Implementation Phases
### Phase 1: Foundation (Week 1)
- [ ] Template cache database setup
- [ ] Base adapter interface
- [ ] Template manager core
### Phase 2: Official Templates (Week 1)
- [ ] n8n official adapter
- [ ] Sync mechanism
- [ ] Basic metadata extraction
### Phase 3: GitHub Integration (Week 2)
- [ ] GitHub adapter
- [ ] Repository discovery
- [ ] README intent extraction
### Phase 4: Community Import (Week 2)
- [ ] URL import adapter
- [ ] Validation & security
- [ ] Provenance tracking
### Phase 5: Intent Matching (Week 3)
- [ ] Intent extraction engine
- [ ] Similarity scoring algorithm
- [ ] Search ranking
### Phase 6: MCP Integration (Week 3)
- [ ] MCP tool definitions
- [ ] Tool handlers
- [ ] Testing & documentation
## š Benefits
### For Users
- ā
Access to 1000+ templates (vs current ~10)
- ā
Always up-to-date with latest community workflows
- ā
Intent-based search finds what you actually need
- ā
Discover workflows you didn't know existed
### For System
- ā
Living, breathing template ecosystem
- ā
Community-driven growth
- ā
Better AI recommendations
- ā
Reduced maintenance (auto-sync)
### For Community
- ā
Easier workflow sharing
- ā
Automatic indexing of GitHub repos
- ā
Increased visibility for quality templates
- ā
Standardized metadata format
## š Next Steps
1. Get approval for architecture
2. Create database schema
3. Implement base adapter
4. Start with n8n official adapter
5. Add intent extraction
6. Integrate with existing system