Prerequisites
Before creating a module, ensure you have:- Intent Architect 4.4.0 or later installed
- Visual Studio 2022 or later (for C# modules)
- The Intent.ModuleBuilder module installed in your application
- Basic understanding of C# and code generation concepts
Module Structure Overview
An Intent Architect module consists of:- Templates: Generate output files from metadata
- Decorators: Modify existing template outputs
- Factory Extensions: Hook into the Software Factory lifecycle
- API Models: Strongly-typed access to designer metadata
- Designer Configuration: Custom designers and visual elements
- .imodspec file: Module specification and manifest
Creating Your First Module
Intent.ModuleBuilder - Core module building functionalityIntent.ModuleBuilder.CSharp - C# specific templates (if targeting C#)Intent.Common.CSharp - C# code generation utilitiesIntent.OutputManager.RoslynWeaver - Code weaving support- Name: Your module identifier (e.g.,
MyCompany.MyModule) - Version: Starting version (e.g.,
1.0.0) - Description: What your module does
Module naming conventions
- Use reverse domain notation:
CompanyName.ProductName.Feature - Be specific:
MyCompany.AspNetCore.ControllersnotMyCompany.WebApi - Avoid generic names that might conflict
- Use consistent casing (PascalCase recommended)
- Name:
MyTemplate - Templating Method:
C# String InterpolationorT4 Template - File Extension: Target file extension (e.g.,
cs)
- File Per Model: One file per metadata element
- Single File: One file for the entire application
- Single File List Model: One file processing multiple elements
- Custom: Full control over instantiation
Templates/MyTemplate/MyTemplateTemplate.csTemplates/MyTemplate/MyTemplateTemplatePartial.csTemplates/MyTemplate/MyTemplateTemplateRegistration.cs
using Intent.Engine;
using Intent.Modules.Common.CSharp.Templates;
using Intent.Templates;
namespace MyCompany.MyModule.Templates.MyTemplate
{
partial class MyTemplateTemplate : CSharpTemplateBase<object>
{
public const string TemplateId = "MyCompany.MyModule.MyTemplate";
public MyTemplateTemplate(IOutputTarget outputTarget, object model = null)
: base(TemplateId, outputTarget, model)
{
}
protected override CSharpFileConfig DefineFileConfig()
{
return new CSharpFileConfig(
className: "GeneratedClass",
@namespace: $"{OutputTarget.GetNamespace()}",
relativeLocation: $"{OutputTarget.GetNamespace()}");
}
public override string TransformText()
{
return @$"
namespace {Namespace}
{{
public class {ClassName}
{{
public void GeneratedMethod()
{{
// Generated code here
}}
}}
}}";
}
}
}
Module Metadata (.imodspec)
The.imodspec file is the module’s manifest:
Intent.ModuleBuilder.imodspec
.imodspec key elements
.imodspec key elements
- id: Unique module identifier
- version: Semantic version (MAJOR.MINOR.PATCH)
- supportedClientVersions: Compatible Intent Architect versions
- templates: All templates provided by the module
- dependencies: Required modules
- factoryExtensions: Lifecycle hooks
- decorators: Template decorators
- designers: Custom designers included
Version ranges
Version ranges
Use semantic versioning ranges:
[4.4.0-a, 5.0.0-a)- Versions 4.4.0 (inclusive) to 5.0.0 (exclusive)[4.5.0-a,)- Version 4.5.0 and later- Check Intent Architect version: Help > About
Project Structure
A typical module project structure:Template Types
File Per Model
Generates one file for each metadata element. Best for entities, services, controllers.
Single File
Generates one file per output target. Best for startup files, configuration.
Single File List Model
Generates one file processing multiple elements. Best for registrations, indexes.
Custom Registration
Full control over template instantiation. Best for complex scenarios.
Best Practices
Naming Conventions
- Templates: End with
Templatesuffix (e.g.,EntityTemplat) - Decorators: End with
Decoratorsuffix - API Models: End with
Modelsuffix - Extensions: End with
Extensionssuffix
Code Organization
- Keep template logic in partial classes
- Use API models for metadata access
- Separate concerns: generation vs. business logic
- Use helper methods for complex transformations
Testing
- Create test applications for each major feature
- Test with various metadata configurations
- Verify edge cases (empty models, special characters)
- Test upgrade scenarios
Documentation
- Add XML comments to public APIs
- Document template settings and their effects
- Provide usage examples
- Include migration guides for breaking changes
Common Patterns
Accessing Application Settings
Querying Metadata
Cross-Template Dependencies
Troubleshooting
Module not appearing in repository
Module not appearing in repository
- Verify
.imodspecversion is incremented - Check
supportedClientVersionsincludes your Intent version - Rebuild and repackage the module
- Clear module cache:
intent cache clear
Template not generating output
Template not generating output
- Check template registration
GetModels()returns elements - Verify template ID matches between template and registration
- Ensure output target is configured correctly
- Check for exceptions in Software Factory output
Build errors in generated code
Build errors in generated code
- Verify all dependencies are installed
- Check NuGet package references in
.csproj - Ensure using statements are correct
- Review template output in Software Factory logs
Next Steps
Module Builder Details
Learn about the Module Builder module and its features
Creating Templates
Deep dive into template development
Creating Decorators
Learn how to modify existing template outputs
Factory Extensions
Hook into Software Factory lifecycle events