Volume 5: Domain Template Creation

Chapter 4.9: AI-Powered Template Selection (Zero-Code Setup)

"Run one command. Copy one file. Your domain now has AI-powered template recommendations."


The Problem: Template Overload

You've built a domain with 20 expertly crafted templates. Each template solves a specific problem. But now your users face a paradox: choice paralysis.

When faced with 20 options, users: - Browse aimlessly through the Templates tab - Read descriptions one by one - Guess which template might work - Pick suboptimally or give up

Even with perfect organization, this creates friction. What if users could just... ask?

"I need to welcome a new client"
→ AI: "I recommend Template 1: Listing Presentation..."

"How do I market an open house?"
→ AI: "Use Template 7: Open House Flyer..."

That's what this chapter gives you: Conversational AI template selection for ANY domain, with literally zero backend code to write.


The Magic: One Generic Service

Here's the breakthrough insight: Every domain needs the same AI capabilities.

All domains need to: - Recommend templates based on user questions - Explain CSV requirements - Search by keyword or category - Maintain conversation history

So instead of generating custom backend code for each domain, we built one generic service that works with ANY domain by loading different JSON knowledge bases.

How It Works

User in Real Estate domain → /api/claude-domain/chat?domain=real-estate
                           → Service loads: real-estate-knowledge-base.json
                           → Claude recommends from 20 real estate templates

User in Healthcare domain → /api/claude-domain/chat?domain=healthcare  
                          → Service loads: healthcare-knowledge-base.json
                          → Claude recommends from healthcare templates

One service. Infinite domains. No code changes.


For Domain Builders: The Process

Step 1: Run the Generator (10 seconds)

node scripts/create-domain-ai-model.js --domain=your-domain

What it does: - Scans your DataPublisher_DomainTemplates/your-domain/word-templates/*.json files - Intelligently generates categories, tags, and use cases - Creates DataPublisher_DomainTemplates/your-domain/ai-knowledge-base.json (IN your domain package!) - Generates AI_README.md with deployment instructions

The AI is now part of your domain package! Clone the domain, get the AI automatically.

Step 2: Test It Works

Log in to Data Publisher and test:

Upload domain template, clone it and then:

Go to: Data - Data Sets - My Data Sets - Show Files - AI - Open AI Assistant. Strike up a conversation!

✨ That's It for Development!

Open your app, navigate to your domain's data set, click the AI tab, and start chatting. The AI is integrated into your domain package!

Production Deployment: When ready to deploy, just zip and upload using the same Upload .zip button (see "Updating Templates" section for details). One-click deployment!

Your domain now has AI-powered template recommendations. Users can chat with Claude to find the right template. No backend code. No frontend changes. Just generate, zip, and upload!


Prerequisites

1. Domain Structure

Your domain must exist in the standard location:

DataPublisher_DomainTemplates/
└── your-domain/
    ├── domain-config.json
    ├── word-templates/
    │   ├── Template-01-Something.docx
    │   └── Template-01-Something.json  ← Required for each template
    ├── ai-knowledge-base.json  ← AI model (generated)
    └── AI_README.md            ← AI docs (generated)

The AI is integrated into your domain package, making it completely portable.

2. Template Metadata Files

Each template needs a .json file with minimum metadata:

{
  "id": 1,
  "name": "Listing Presentation",
  "description": "Professional listing presentation for sellers",
  "csvFiles": ["agents.csv", "properties.csv"]
}

That's enough! The generator auto-fills: - Categories (from template names: "flyer" → Marketing, "invoice" → Financial) - Tags (extracted keywords: "client", "property", "letter", etc.) - Use cases (auto-generated: "Generate [template]", "Create professional [template]") - Complexity (Simple vs Master-Detail based on CSV count)

Optional enhancements (improves AI quality):

{
  "category": "Client Marketing",
  "useCases": [
    "Present listing proposal to sellers",
    "Demonstrate market expertise with comps"
  ],
  "tags": ["seller", "listing", "marketing"],
  "examples": ["Use when meeting homeowners considering selling"]
}

Real-World Example: Real Estate Domain

Let's walk through creating AI for the real estate domain.

Starting Point

  • 20 templates in DataPublisher_DomainTemplates/real-estate/word-templates/
  • Each has basic .json metadata (name, description, CSV files)
  • No categories or tags defined yet

Run Generator

node scripts/create-domain-ai-model.js --domain=real-estate

Output:

🤖 Domain AI Knowledge Base Generator (Simplified)
============================================================

Domain: Real Estate
Package: DataPublisher_DomainTemplates/real-estate
Output: ai-knowledge-base.json

[1/4] Validating domain...
  ✅ Domain validated
[2/4] Extracting template metadata...
  ✅ Found 20 templates
[3/4] Generating knowledge base...
  ✅ Knowledge base created in domain package
[4/4] Generating documentation...
  ✅ AI_README.md created in domain package

============================================================
✅ Knowledge Base Generation Complete!
============================================================

📁 Files Created (IN DOMAIN PACKAGE):
   - DataPublisher_DomainTemplates/real-estate/ai-knowledge-base.json
   - DataPublisher_DomainTemplates/real-estate/AI_README.md

✨ AI Integrated into Domain Package!
   - Knowledge base is part of your domain
   - Clone domain = get AI automatically
   - Generic claude-domain service auto-loads from domain folder

Generated Knowledge Base

{
  "generatedAt": "2026-03-01T10:00:00Z",
  "templateCount": 20,
  "domainName": "Real Estate",
  "templates": [
    {
      "templateNumber": 1,
      "name": "Listing Presentation",
      "description": "Professional listing presentation for sellers",
      "category": "Packages",  // Auto-inferred from "presentation"
      "complexity": "Master-Detail",  // 3 CSV files
      "tags": ["listing", "presentation", "seller", "property"],
      "useCases": [
        "Generate Listing Presentation",
        "Create professional listing presentation",
        "Automate listing presentation creation"
      ]
    },
    {
      "templateNumber": 2,
      "name": "Property Flyer",
      "category": "Marketing",  // Auto-inferred from "flyer"
      "complexity": "Simple",  // 1 CSV file
      "tags": ["property", "flyer", "marketing"]
    }
    // ... 18 more
  ],
  "categories": ["Packages", "Marketing", "Communication", "Reports"],
  "tags": ["property", "client", "seller", "marketing", "flyer", "listing"]
}

Deploy with One-Click Upload

Here's where it gets really cool. No manual file copying. No PowerShell scripts. No command line at all.

The Modern Way:

  1. Zip your domain package (right-click the folder → "Send to" → "Compressed (zipped) folder") DataPublisher_DomainTemplates/ └── real-estate.zip ← Contains everything: templates, docs, AI knowledge base!

  2. Log in to DataPublisher and navigate to: Data → Data Sets → [Your Data Sets Tab]

  3. Scroll to the bottom of the Domain Template Catalog

  4. Click "Upload .zip" button

  5. Select your real-estate.zip file

  6. Done! The platform:

  7. Extracts the domain package
  8. Registers all templates
  9. Loads the AI knowledge base automatically
  10. Makes everything instantly available to users

What makes this awesome: - ✨ Zero manual file operations - no Copy-Item, no RDP, no server access needed - 🚀 Testing is instant - upload, test, iterate in seconds - 📦 Everything travels together - templates, CSV samples, documentation, AND the AI knowledge base - 🔄 Version control friendly - zip the folder, commit to Git, share with team - 🎯 Production deployment - same button works in production, same workflow everywhere

Test It

After uploading your domain package:

  1. Navigate to: Data → Data Sets → My Data Sets
  2. Click "Clone Domain" to create a test data set from your uploaded domain
  3. Click "Show Files" on your new data set
  4. Click the "AI" tab to open the AI Assistant
  5. Start chatting! Ask: "What templates do you have?"

The AI will immediately know about your 20 templates, categories, and use cases. No configuration. No delay. It just works.

Want to verify it loaded correctly?

Open the browser console and check the health endpoint:

fetch('/api/claude-domain/health?domain=real-estate')
  .then(r => r.json())
  .then(console.log);

Response:

{
  "status": "healthy",
  "domain": "real-estate",
  "domainName": "Real Estate",
  "templates": 20,
  "categories": ["Packages", "Marketing", "Communication", "Reports"],
  "knowledgeBaseLoaded": true
}

✅ Knowledge base loaded! Your AI is live!

User Experience

User opens AI tab in their real estate data set:

User: I just got a new listing. What should I create first?

AI: For a new listing, I recommend Template 1: Listing Presentation. 
    This creates a comprehensive presentation for potential sellers, 
    showcasing your services, market analysis, and pricing strategy.

    You'll need these CSV files:
    - agents.csv (your profile)
    - properties.csv (listing details)
    - comparables.csv (recent comparable sales)

    Once active, you'll want Template 2: Property Flyer for marketing.

User: Perfect! And what about thanking clients after closing?

AI: Use Template 11: Client Thank You. This creates a professional 
    thank you letter personalized for clients after a successful 
    transaction. It requires just clients.csv.

How the Generic Service Works

Architecture

Frontend (ai-chat.html)
    ↓
    GET /api/claude-domain/chat?domain=real-estate
    ↓
claudeDomainService.ts
    ↓
    1. Check cache for 'real-estate' knowledge base
    2. If not cached, load from DataPublisher_DomainTemplates/real-estate/ai-knowledge-base.json
    3. Build system prompt with template list
    4. Send to Claude Sonnet 4
    5. Cache knowledge base for future requests
    ↓
Claude API
    ↓
Response to user

Caching

The service caches knowledge bases per domain: - First request: Reads JSON from disk, caches in memory - Subsequent requests: Instant (served from cache) - New domain: Automatically loads its JSON on first use - Update: Restart PM2 to clear cache, or wait for natural reload

System Prompt Generation

The service builds custom prompts per domain:

buildSystemInstructions(knowledgeBase, domain) {
  return `You are an expert for ${knowledgeBase.domainName}.

AVAILABLE TEMPLATES (${knowledgeBase.templateCount}):
  1. Listing Presentation - Professional presentation for sellers
  2. Property Flyer - Eye-catching property marketing
  ... (all 20 templates)

CATEGORIES:
${knowledgeBase.categories.join(', ')}

When users ask about templates:
1. Understand their goal
2. Recommend the most appropriate template
3. Explain CSV requirements
4. Offer alternatives if multiple fit
`;
}

Claude sees this prompt plus conversation history, enabling intelligent recommendations.



Updating Templates

When you add or modify templates:

Step 1: Re-run Generator

node scripts/create-domain-ai-model.js --domain=your-domain

This regenerates the knowledge base with updated template info.

Step 2: Zip and Upload

The same one-click workflow:

  1. Zip your updated domain package:
  2. Right-click DataPublisher_DomainTemplates/your-domain folder
  3. "Send to" → "Compressed (zipped) folder"

  4. Upload via the UI:

  5. Data → Data Sets → [Your Data Sets Tab]
  6. Scroll to bottom of Domain Template Catalog
  7. Click "Upload .zip"
  8. Select your updated your-domain.zip

  9. That's it! The platform automatically:

  10. Replaces the old version
  11. Reloads the AI knowledge base
  12. Updates template metadata
  13. Makes changes available immediately

No server commands. No manual file copying. Just zip and click!

Step 3: Verify Updates

After upload:

  1. Clone the domain (or use existing data set)
  2. Open AI Assistant
  3. Ask: "What's changed?" or "What templates do you have?"
  4. Verify the AI knows about your new/updated templates

The knowledge base cache refreshes automatically - no restart needed!



Troubleshooting

No Templates Found

Error: During generation: ❌ No templates found

Solution: 1. Verify template JSON files exist: ls DataPublisher_DomainTemplates/your-domain/word-templates/ 2. Check files start with Template- and end with .json 3. Validate JSON syntax: cat Template-01-Something.json | python -m json.tool


Best Practices

1. Enrich Template Metadata

Good AI requires good data. Invest time in:

Example: Basic (works, but generic)

{
  "name": "Client Letter",
  "description": "Letter for clients"
}

Example: Rich (specific AI recommendations)

{
  "name": "Client Thank You Letter",
  "description": "Professional thank you letter for clients after successful real estate transaction, personalized with property details and optional referral request",
  "category": "Communication",
  "useCases": [
    "Thank clients after closing",
    "Request referrals from satisfied sellers",
    "Maintain relationship post-transaction"
  ],
  "tags": ["client", "thank-you", "communication", "relationship"],
  "examples": [
    "Send within 24 hours of closing",
    "Include property photo for personal touch"
  ]
}

The AI can only be as specific as your metadata allows.

2. Test with Real Questions

Before launching, test with actual user scenarios:

❌ "What templates do you have?"  (Too broad)
✅ "I need to welcome a new seller"  (Specific goal)

❌ "Tell me about Template 5"  (Not how users think)
✅ "How do I market my open house?"  (Natural language)

Summary

Adding AI to your domain is now absurdly simple:

Easier Way: 1. Run: node scripts/create-domain-ai-model.js --domain=yours 2. Zip: Right-click domain folder → "Send to" → "Compressed (zipped) folder" 3. Upload: Data → Data Sets → "Upload .zip" button at bottom 4. Test: Clone domain, open AI tab, start chatting! 5. Done! AI integrated, tested, and ready for users.

The Power of Simplicity

  • For Domain Builders: One command creates AI, one button deploys it. Fully integrated, fully portable.
  • For Users: Natural language template discovery. No browsing, just ask!
  • For Maintainers: Zero code per domain, one generic service, zero server access needed.
  • For Business: Instant deployment, instant testing, instant updates.
  • For Distribution: Zip contains everything - templates, docs, CSV samples, AND AI knowledge base!

When to Add AI

Add AI to your domain if: - ✅ You have 10+ templates (worth the API cost) - ✅ Templates serve different purposes (not just variations) - ✅ Users may be unfamiliar with your domain - ✅ You want premium UX

Skip AI if: - ❌ You have <5 templates (manual selection is fine) - ❌ All templates are self-explanatory - ❌ Users already know exactly what they need


Next Steps

  1. Generate knowledge base for your domain
  2. Zip and upload - Use the Upload .zip button in the Data Sets tab
  3. Test in your app - Clone domain, open AI tab, start chatting
  4. Iterate on metadata - Refine template descriptions based on AI responses
  5. Deploy updates - Re-zip and re-upload (same button, instant deployment!)
  6. Monitor usage and continue improving

Your domain deserves intelligent template selection. Give users the power to ask, not browse.


Additional Resources

Welcome to the future of domain automation: Zero-code AI integration