Skip to content

Template Validation AI Assistance

Overview

GuardKit's comprehensive audit (Level 3) includes AI-assisted analysis for 4 sections: - Section 8: Comparison with Source - Section 11: Detailed Findings - Section 12: Validation Testing - Section 13: Market Comparison

AI assistance provides automated analysis while maintaining human oversight and review.

How AI Assistance Works

1. Analysis Trigger

When you reach an AI-assisted section during a comprehensive audit:

============================================================
  Section 8: Comparison with Source (AI-Assisted)
============================================================

Would you like AI to analyze this section? [Y/n]:

2. AI Processing

AI analyzes the template using: - Context: Template files, manifest, settings, documentation - Patterns: Code structure, naming conventions, architecture - Best Practices: Industry standards, framework conventions - Comparison: Source codebase (if available) vs generated templates

3. Human Review

AI findings are presented for review:

AI Analysis Complete (Section 8)

Findings:
  ✅ 12 patterns correctly extracted
  ⚠️ 3 patterns with minor deviations
  ❌ 1 pattern missing from templates

Review AI findings? [Y/n/details]:

4. Approval or Adjustment

You can: - Approve: Accept AI findings as-is - Review: See detailed analysis - Adjust: Modify findings before adding to report - Reject: Discard AI analysis and do manual review

AI-Assisted Sections

Section 8: Comparison with Source

What AI Does: - Compares source codebase with generated templates - Identifies pattern fidelity (how well templates match source) - Detects missing or incorrect patterns - Measures abstraction quality

AI Accuracy: ~90% agreement with expert manual analysis

Example Output:

## Pattern Fidelity Analysis

### ✅ Correctly Extracted (12 patterns)
1. Repository pattern - Matches source implementation
2. UseCase pattern - Correct abstraction
3. DTO mappings - Accurate structure
...

### ⚠️ Minor Deviations (3 patterns)
1. Error handling - Simplified from source
   - Source: Result<T, ErrorType>
   - Template: Result<T> (generic error)
   - Impact: Low (acceptable simplification)
...

### ❌ Missing Patterns (1 pattern)
1. Logging interceptor - Not included in templates
   - Recommendation: Add as optional template file
...

### Abstraction Quality: 8.5/10
Templates successfully generalize source patterns while maintaining core structure.


Section 11: Detailed Findings

What AI Does: - Analyzes template quality across multiple dimensions - Identifies code smells and anti-patterns - Checks consistency across template files - Validates placeholder usage

AI Accuracy: ~85% agreement with expert manual analysis

Example Output:

## Quality Analysis

### Code Quality
- ✅ Clean architecture principles followed
- ✅ Separation of concerns maintained
- ⚠️ Some duplication in template files (3 instances)
- ✅ Proper abstraction levels

### Placeholder Consistency
- ✅ Naming conventions consistent (PascalCase for classes)
- ❌ Inconsistent module placeholders (CamelCase vs snake_case)
  - Files affected: 5
  - Recommendation: Standardize to snake_case
- ✅ All placeholders properly escaped

### Documentation Quality
- ✅ All template files have header comments
- ⚠️ 3 files missing inline documentation
- ✅ README covers all major concepts
- ⚠️ Examples could be more comprehensive

### Test Coverage
- ✅ Unit test templates present
- ⚠️ Integration test templates missing
- ✅ Test naming conventions consistent
- ✅ Assertions clear and specific

### Overall Score: 8.2/10
High-quality template with minor consistency issues to address.


Section 12: Validation Testing

What AI Does: - Generates test scenarios for template validation - Identifies edge cases to test - Suggests validation test cases - Recommends testing strategy

AI Accuracy: ~88% agreement with expert manual analysis

Example Output:

## Testing Recommendations

### Unit Testing
Test each template file independently:

1. **Repository Templates**
   ```bash
   # Test scenario 1: Basic CRUD operations
   guardkit init my-template
   npm run test:unit

   # Expected: All repository tests pass
   ```

2. **UseCase Templates**
   ```bash
   # Test scenario 2: Business logic validation
   # Expected: Use cases properly orchestrate repositories
   ```

### Integration Testing
Test template files working together:

1. **End-to-End Flow**
   ```bash
   # Test scenario 3: Complete user flow
   # Create → Read → Update → Delete
   npm run test:integration
   ```

### Edge Cases to Test
1. ✅ Empty input handling
2. ✅ Null value propagation
3. ⚠️ Concurrent access patterns - Not covered
4. ✅ Error boundaries
5. ⚠️ Large dataset handling - Should add test

### Test Coverage Goals
- Unit tests: ≥80% line coverage
- Integration tests: All critical paths
- E2E tests: Happy path + error cases

### Recommended Test Files
1. `tests/repositories/*.test.ts` - Repository layer
2. `tests/usecases/*.test.ts` - Business logic
3. `tests/integration/*.test.ts` - End-to-end flows
4. `tests/edge-cases/*.test.ts` - Edge case scenarios


Section 13: Market Comparison

What AI Does: - Compares template with similar templates/frameworks - Identifies unique features and gaps - Benchmarks against industry standards - Suggests competitive improvements

AI Accuracy: ~80% agreement with expert manual analysis

Example Output:

## Market Comparison Analysis

### Similar Templates/Frameworks
1. **NestJS Clean Architecture Template**
   - Similarities: Repository pattern, UseCase layer, DTO mappings
   - Differences: Our template includes ErrorOr pattern, theirs uses exceptions
   - Quality: Comparable (both ~8/10)

2. **TypeScript Domain-Driven Design Template**
   - Similarities: Domain modeling, layered architecture
   - Differences: Their template more complex (aggregates, value objects)
   - Quality: Theirs more comprehensive (9/10) but higher learning curve

### Unique Features (Competitive Advantages)
- ✅ ErrorOr pattern for railway-oriented programming
- ✅ Integrated testing patterns
- ✅ Clear separation of concerns
- ✅ Simplified for faster onboarding

### Gaps Compared to Market Leaders
- ⚠️ Missing CQRS pattern examples
- ⚠️ No event sourcing templates
- ✅ Adequate for most use cases (CRUD-focused)

### Industry Standards Compliance
- ✅ Follows TypeScript best practices
- ✅ Aligns with Clean Architecture principles
- ✅ Matches NestJS conventions
- ⚠️ Could add OpenAPI/Swagger integration

### Positioning
**Target Users**: Small to medium teams building CRUD APIs
**Strengths**: Simplicity, clarity, quick onboarding
**Improvements**: Add advanced patterns as optional modules

### Competitive Score: 7.8/10
Solid template for target audience, room for advanced feature additions.

AI Accuracy and Limitations

Accuracy Metrics

Section AI Accuracy Agreement with Expert
Section 8: Source Comparison 90% High
Section 11: Detailed Findings 85% High
Section 12: Testing 88% High
Section 13: Market Comparison 80% Medium-High

What AI Does Well

Pattern Recognition: Identifies code patterns consistently ✅ Structural Analysis: Detects architectural issues accurately ✅ Consistency Checking: Finds inconsistencies across files ✅ Documentation Review: Identifies missing or incomplete docs ✅ Test Coverage: Suggests comprehensive test scenarios

AI Limitations

⚠️ Context Understanding: May miss business-specific requirements ⚠️ Subjective Decisions: Cannot make architectural trade-off decisions ⚠️ Novel Patterns: Less effective with non-standard patterns ⚠️ Domain Knowledge: May not understand domain-specific constraints

Human Review Required

Always review AI findings for: - Business logic correctness - Security implications - Performance considerations - Domain-specific requirements - Architectural trade-offs

Fallback to Manual Review

If AI assistance is not available or you prefer manual review:

Section 8: Manual Source Comparison

# 1. Review source codebase
cd /path/to/source-codebase

# 2. Review generated templates
cd /path/to/template/templates/

# 3. Compare side-by-side
diff -r /path/to/source-codebase /path/to/template/templates/

# 4. Document findings in audit report

Section 11: Manual Detailed Findings

# Use validation checklist
cat docs/guides/validation-checklist-usage.md

# Review each template file manually
for file in templates/*.template; do
  echo "Reviewing: $file"
  # Check placeholders, structure, documentation
done

Section 12: Manual Testing

# Create test plan manually
# Document test scenarios
# Execute tests and record results

Section 13: Manual Market Comparison

# Research similar templates
# Document comparisons in audit report
# Identify gaps and unique features

Configuration

Enabling/Disabling AI Assistance

Enable for specific sections:

/template-validate <template-path> --sections 8,11,12,13
# AI assistance available for all selected sections

Disable AI assistance:

/template-validate <template-path> --no-ai
# All sections use manual review

AI-only mode (skip manual sections):

/template-validate <template-path> --ai-only
# Only run sections 8, 11, 12, 13

AI Model Configuration

AI assistance uses Claude Sonnet for analysis by default.

Advanced configuration (in settings.json):

{
  "validation": {
    "ai_assistance": {
      "enabled": true,
      "model": "claude-sonnet-4",
      "temperature": 0.3,
      "sections": [8, 11, 12, 13],
      "auto_approve": false,
      "confidence_threshold": 0.85
    }
  }
}

Best Practices

1. Always Review AI Findings

Don't blindly accept AI analysis: - ✅ Read through findings carefully - ✅ Validate recommendations against your context - ✅ Adjust or reject if needed

2. Combine AI + Human Expertise

Use AI for: - Initial analysis and pattern detection - Comprehensive coverage - Consistency checking

Use human review for: - Final decision-making - Business logic validation - Architectural trade-offs

3. Document Adjustments

If you modify AI findings: - ✅ Note why you changed the analysis - ✅ Document your reasoning - ✅ Add to audit report

4. Use AI to Learn

AI analysis can teach you: - Validation best practices - Common template issues - Industry standards - Testing strategies

Troubleshooting

AI Analysis Takes Too Long

Solution: AI analysis can take 2-5 minutes per section. Be patient. If it exceeds 10 minutes, cancel and retry.

AI Findings Seem Wrong

Solution: 1. Review the context AI received 2. Check if source codebase path was correct 3. Verify template files are complete 4. Use manual review as backup

AI Not Available

Solution: Fall back to manual review:

/template-validate <template-path> --no-ai

AI Recommendations Too Generic

Solution: 1. Provide more context in template documentation 2. Add domain-specific information to README 3. Supplement with manual review

See Also