Template Overlays Specification¶
This document is the authoritative technical specification for ConnectSoft's overlay system, versioning, and compatibility management. It serves as the contract for both humans and agents working with template overlays, defining the rules, mechanisms, and patterns that govern overlay composition, versioning, and compatibility.
Important
This specification defines the technical contract for overlay system. All overlay implementations, Factory agents, and human developers must adhere to these rules and patterns.
Document Purpose¶
This specification provides:
- Complete technical contract for overlay system architecture
- Overlay application process and composition rules
- Versioning scheme for base and specialized templates
- Compatibility management and declaration format
- Recipe system for template composition
- Authoritative source for agents and developers
For template architecture details, see Template Architecture Specification. For practical guides, see Template Layering Guide.
Overlay System Architecture¶
What is an Overlay?¶
An overlay is a collection of code, documentation, and metadata that extends or modifies a base template. Overlays enable:
- Domain-specific functionality (Identity, Auth, Audit, Worker)
- Composition of multiple overlays (Identity + Worker)
- Reusability of overlay components across templates
- Flexibility in template generation
Overlay Components:
- Code Files - Domain-specific projects, classes, interfaces
- Documentation - Domain-specific documentation files
- Metadata - Template.json extend files, configuration
- Tests - Domain-specific test projects and test cases
Overlay Types¶
ConnectSoft defines several overlay types:
Domain Overlays:
- Identity Overlay - User management, authentication, authorization
- Auth Overlay - OAuth2/OIDC server functionality
- Audit Overlay - Audit trail and compliance logging
- Worker Overlay - Background job processing
Feature Overlays:
- Worker Overlay - Background job processing capabilities
- Scheduler Overlay - Scheduled task execution
- API Gateway Overlay - API gateway integration
Infrastructure Overlays: - Observability Overlay - Enhanced observability features - Security Overlay - Additional security features
Overlay Composition Order and Precedence¶
Overlays are applied in a specific order defined by the recipe:
Composition Rules:
- Base is always first - All compositions start with base template
- Overlays applied sequentially - Order matters for file patching and token replacement
- Later overlays override earlier - Conflicts resolved by last overlay wins
- Metadata merged sequentially - template.json extended in order
Precedence Diagram:
flowchart TB
BASE[Base Template<br/>Priority: 0]
OVERLAY1[First Overlay<br/>Priority: 1]
OVERLAY2[Second Overlay<br/>Priority: 2]
OVERLAY3[Third Overlay<br/>Priority: 3]
BASE --> OVERLAY1
OVERLAY1 --> OVERLAY2
OVERLAY2 --> OVERLAY3
OVERLAY3 --> FINAL[Final Template<br/>All Overlays Applied]
style BASE fill:#BBDEFB
style OVERLAY1 fill:#C8E6C9
style OVERLAY2 fill:#FFF9C4
style OVERLAY3 fill:#FFCCBC
style FINAL fill:#A5D6A7
Multi-Overlay Scenarios¶
Multiple overlays can be composed to create complex templates:
Example: Identity + Worker
- Base Template (foundation)
- Identity Overlay (domain logic)
- Worker Overlay (background jobs)
Example: Auth + Scheduler
- Base Template (foundation)
- Auth Overlay (OAuth2/OIDC server)
- Scheduler Overlay (scheduled tasks)
Stacking Rules:
- No circular dependencies - Overlays cannot depend on each other in cycles
- Explicit dependencies - Overlays declare dependencies on other overlays
- Compatibility checks - All overlays must be compatible with base and each other
- Order matters - Overlays applied in recipe order
Overlay Application Process¶
File Addition¶
Purpose: Add new files from overlay to final template.
Process:
- Overlay defines new files (code, docs, tests)
- Files copied to final template structure
- Tokens replaced (ServiceName, Namespace, etc.)
- File paths adjusted if needed
Example:
Identity Overlay adds:
- src/Identity.Api/Identity.Api.csproj
- src/Identity.Domain/Identity.Domain.csproj
- src/Identity.Infrastructure/Identity.Infrastructure.csproj
- tests/Identity.UnitTests/Identity.UnitTests.csproj
File Patching¶
Purpose: Modify existing base files without replacing them entirely.
Mechanisms:
-
Marker-Based Insertion
- Base files contain markers (e.g.,
// #IDENTITY_REGISTRATION) - Overlay files define content to insert at markers
- Content inserted between markers during generation
- Base files contain markers (e.g.,
-
Patch Files
- Overlay defines patch files (unified diff format)
- Patches applied to base files
- Conflicts detected and resolved
-
Partial Replacement
- Overlay defines sections to replace
- Base file sections replaced with overlay content
- Rest of base file preserved
Example Marker-Based Insertion:
Base File (Program.cs):
// ... base code ...
// #IDENTITY_REGISTRATION
// Overlay will insert Identity service registration here
// #END_IDENTITY_REGISTRATION
// ... more base code ...
Identity Overlay File:
// #IDENTITY_REGISTRATION
builder.Services.AddConnectSoftIdentityInfrastructure(configuration);
// #END_IDENTITY_REGISTRATION
Result:
// ... base code ...
builder.Services.AddConnectSoftIdentityInfrastructure(configuration);
// ... more base code ...
Token Replacement¶
Purpose: Replace placeholders with actual values during generation.
Tokens:
ServiceName- Name of the generated serviceRootNamespace- Root namespace for generated codeServiceNameLower- Lowercase service nameServiceNamePascal- PascalCase service name- Domain-specific tokens (e.g.,
IdentityService)
Replacement Process:
- All files scanned for token patterns
- Tokens replaced with actual values
- File names updated if they contain tokens
- Project references updated
Example:
Token: ServiceName
Value: IdentityBackendService
Before: namespace MyCompany.ServiceName.Domain;
After: namespace MyCompany.IdentityBackendService.Domain;
Documentation Merging¶
Purpose: Combine base and overlay documentation into final structure.
Process:
- Base docs copied to final
docs/directory - Overlay docs copied to final
docs/directory - Cross-references updated
- Table of contents merged
- Navigation structure updated
Merging Rules:
- Base docs preserved
- Overlay docs added
- Conflicts resolved by overlay wins
- Cross-references updated to reflect final structure
Metadata Merging¶
Purpose: Combine base template.json with overlay extend files.
Process:
- Load base template.json
- Apply overlay extend files in order
- Merge according to rules (see Template Architecture Specification)
- Validate final template.json
- Write merged template.json
Merge Order:
- Apply identityOverrides
- Apply symbolOverrides
- Apply symbolAdds
- Apply postActionsAdds
- Apply primaryOutputsAdds
Versioning & Compatibility¶
Base Template Versioning¶
Scheme: Semantic Versioning (MAJOR.MINOR.PATCH)
Format: MAJOR.MINOR.PATCH (e.g., 1.2.3)
Version Bump Rules:
-
MAJOR - Breaking changes to template structure
- Changes to required parameters
- Changes to project structure
- Changes to extension point interfaces
- Example:
1.2.3→2.0.0
-
MINOR - New features, backward compatible
- New optional parameters
- New extension points
- New base functionality
- Example:
1.2.3→1.3.0
-
PATCH - Bug fixes, backward compatible
- Bug fixes in base code
- Documentation updates
- Minor improvements
- Example:
1.2.3→1.2.4
Version Location:
- Base template version in
template/template.json:
Specialized Template Versioning¶
Scheme: Semantic Versioning (MAJOR.MINOR.PATCH) with base compatibility range
Format: MAJOR.MINOR.PATCH (e.g., 2.1.0)
Version Bump Rules:
-
MAJOR - Breaking changes to overlay structure or base compatibility
- Changes requiring new base template version
- Breaking changes to overlay structure
- Example:
2.1.0→3.0.0
-
MINOR - New features, backward compatible
- New overlay features
- New parameters
- Example:
2.1.0→2.2.0
-
PATCH - Bug fixes, backward compatible
- Bug fixes in overlay code
- Documentation updates
- Example:
2.1.0→2.1.1
Base Compatibility:
- Specialized templates declare compatible base template versions
- Example:
2.1.0compatible with base^1.5.0(>=1.5.0 <2.0.0)
Compatibility Declaration Format¶
Overlays declare compatibility with base template versions using a manifest file.
Overlay Manifest Structure:
{
"overlayId": "identity-backend",
"version": "2.1.0",
"baseCompatibility": {
"minVersion": "1.5.0",
"maxVersion": "2.0.0",
"range": "^1.5.0"
},
"dependencies": {
"overlays": []
},
"metadata": {
"displayName": "Identity Backend Overlay",
"description": "Identity domain logic overlay",
"author": "ConnectSoft"
}
}
Compatibility Range Syntax:
^1.5.0- Compatible with >=1.5.0 <2.0.0>=1.5.0 <2.0.0- Explicit range~1.5.0- Compatible with >=1.5.0 <1.6.01.5.0- Exact version (not recommended)
Dependencies:
Overlays can depend on other overlays:
Compatibility Matrix¶
A compatibility matrix tracks which overlay versions work with which base versions:
Matrix Format:
| Base Version | Identity Overlay | Auth Overlay | Worker Overlay |
|---|---|---|---|
| 1.5.0 | 2.0.0 - 2.1.0 | 1.0.0 - 1.2.0 | 1.0.0 - 1.1.0 |
| 1.6.0 | 2.1.0 - 2.2.0 | 1.1.0 - 1.3.0 | 1.1.0 - 1.2.0 |
| 2.0.0 | 3.0.0+ | 2.0.0+ | 2.0.0+ |
Compatibility Matrix Diagram:
graph TB
subgraph BaseVersions["Base Template Versions"]
B1[1.5.0]
B2[1.6.0]
B3[2.0.0]
end
subgraph IdentityVersions["Identity Overlay Versions"]
I1[2.0.0]
I2[2.1.0]
I3[2.2.0]
I4[3.0.0]
end
B1 -->|Compatible| I1
B1 -->|Compatible| I2
B2 -->|Compatible| I2
B2 -->|Compatible| I3
B3 -->|Compatible| I4
style B1 fill:#BBDEFB
style B2 fill:#BBDEFB
style B3 fill:#BBDEFB
style I1 fill:#C8E6C9
style I2 fill:#C8E6C9
style I3 fill:#C8E6C9
style I4 fill:#C8E6C9
Breaking Change Handling¶
Breaking Changes Defined:
-
Base Template Breaking Changes:
- Removal of required parameters
- Changes to extension point interfaces
- Changes to project structure
- Changes to required post-actions
-
Overlay Breaking Changes:
- Changes requiring new base template version
- Removal of overlay parameters
- Changes to overlay structure
Breaking Change Process:
- Identify Breaking Change - Document what breaks
- Bump MAJOR Version - Increment MAJOR version number
- Update Compatibility - Update compatibility declarations
- Migration Guide - Create migration guide for users
- Communication - Notify users of breaking changes
Migration Strategies:
- Gradual Migration - Support both old and new versions temporarily
- Automated Migration - Provide migration scripts/tools
- Documentation - Clear migration guides
- Deprecation Period - Deprecate old versions before removal
Version Bump Procedures¶
When to Bump Base Template Version¶
MAJOR Bump:
- Breaking changes to template structure
- Changes to required parameters
- Changes to extension point interfaces
- Changes to project structure
MINOR Bump:
- New optional parameters
- New extension points
- New base functionality
- New post-actions
PATCH Bump:
- Bug fixes
- Documentation updates
- Minor improvements
When to Bump Specialized Template Version¶
MAJOR Bump:
- Breaking changes to overlay structure
- Changes requiring new base template version
- Removal of overlay parameters
MINOR Bump:
- New overlay features
- New overlay parameters
- New overlay functionality
PATCH Bump:
- Bug fixes in overlay
- Documentation updates
- Minor improvements
How to Update Compatibility Declarations¶
Process:
-
Determine Base Compatibility
- Test overlay with base template versions
- Identify minimum and maximum compatible versions
- Document any breaking changes
-
Update Overlay Manifest
- Update
baseCompatibility.range - Update
baseCompatibility.minVersionandmaxVersion - Update overlay version if needed
- Update
-
Update Compatibility Matrix
- Add new overlay version to matrix
- Update compatibility ranges
- Document any breaking changes
-
Test Compatibility
- Test overlay with all compatible base versions
- Verify overlay application process
- Verify final template generation
Testing Compatibility After Version Bumps¶
Test Process:
- Unit Tests - Test overlay application with base versions
- Integration Tests - Test full template generation
- Compatibility Tests - Test with all compatible base versions
- Regression Tests - Ensure no regressions
Test Matrix:
| Base Version | Overlay Version | Test Status |
|---|---|---|
| 1.5.0 | 2.1.0 | ✅ Pass |
| 1.6.0 | 2.1.0 | ✅ Pass |
| 2.0.0 | 2.1.0 | ❌ Fail |
Communication of Breaking Changes¶
Communication Channels:
- Release Notes - Document breaking changes in release notes
- Migration Guides - Provide step-by-step migration guides
- Deprecation Warnings - Warn users before breaking changes
- Documentation Updates - Update all relevant documentation
Breaking Change Notice Format:
## Breaking Changes in v2.0.0
### Base Template v2.0.0
**Breaking:** Removed `UseLegacyMessaging` parameter
- **Impact:** Templates using `UseLegacyMessaging=true` will fail
- **Migration:** Use `MessagingType=Legacy` instead
- **Deprecation:** Parameter deprecated in v1.9.0
**Breaking:** Changed `IMetricsFeature` interface
- **Impact:** Custom metrics implementations need update
- **Migration:** See [Migration Guide](migration-guide.md)
Recipe System¶
Recipe File Format¶
Recipes define how to compose base template with overlays.
YAML Format:
# Recipe: identity-worker-service.yaml
templateId: identity-worker-service
displayName: "Identity Backend with Worker"
version: "1.0.0"
description: "Identity backend service with background job processing"
layers:
- base:
templateId: microservice-base
version: "^1.5.0"
- overlay:
overlayId: identity-backend
version: "^2.1.0"
- overlay:
overlayId: worker
version: "^1.0.0"
metadata:
tags:
- identity
- worker
- backend
classifications:
- ConnectSoft
- Microservice
- Identity
- Worker
JSON Format:
{
"templateId": "identity-worker-service",
"displayName": "Identity Backend with Worker",
"version": "1.0.0",
"description": "Identity backend service with background job processing",
"layers": [
{
"base": {
"templateId": "microservice-base",
"version": "^1.5.0"
}
},
{
"overlay": {
"overlayId": "identity-backend",
"version": "^2.1.0"
}
},
{
"overlay": {
"overlayId": "worker",
"version": "^1.0.0"
}
}
],
"metadata": {
"tags": ["identity", "worker", "backend"],
"classifications": ["ConnectSoft", "Microservice", "Identity", "Worker"]
}
}
Recipe Composition Rules¶
Rules:
- Base is always first - Recipe must start with base layer
- Overlays in order - Overlays applied in recipe order
- Version compatibility - All layers must be compatible
- Dependency resolution - Overlay dependencies resolved automatically
- Validation - Recipe validated before execution
Validation Rules:
- Base template version must exist
- All overlay versions must exist
- All versions must be compatible
- No circular dependencies
- All required dependencies present
Recipe Validation¶
Validation Process:
- Parse Recipe - Validate YAML/JSON syntax
- Check Base - Verify base template exists and version compatible
- Check Overlays - Verify all overlays exist and versions compatible
- Check Dependencies - Verify overlay dependencies resolved
- Check Compatibility - Verify all layers compatible with each other
- Check Circular Dependencies - Verify no circular dependencies
Validation Errors:
- Base template not found
- Overlay not found
- Version incompatibility
- Missing dependencies
- Circular dependencies
Recipe Execution Order¶
Execution Process:
- Load Base Template - Load base template code, docs, metadata
- Resolve Dependencies - Resolve all overlay dependencies
- Apply Overlays - Apply overlays in recipe order:
- Apply Identity overlay
- Apply Worker overlay
- Resolve Tokens - Replace all tokens with actual values
- Validate Final Template - Validate final template structure
- Output Final Template - Write final template artifact
Execution Order Diagram:
flowchart TD
START[Start Recipe Execution]
LOADBASE[Load Base Template<br/>Code + Docs + Metadata]
RESOLVE[Resolve Dependencies]
APPLY1[Apply Identity Overlay]
APPLY2[Apply Worker Overlay]
RESOLVETOKENS[Resolve Tokens<br/>ServiceName, Namespace, etc.]
VALIDATE[Validate Final Template]
OUTPUT[Output Final Template Artifact]
START --> LOADBASE
LOADBASE --> RESOLVE
RESOLVE --> APPLY1
APPLY1 --> APPLY2
APPLY2 --> RESOLVETOKENS
RESOLVETOKENS --> VALIDATE
VALIDATE --> OUTPUT
style START fill:#E3F2FD
style LOADBASE fill:#BBDEFB
style APPLY1 fill:#C8E6C9
style APPLY2 fill:#FFF9C4
style OUTPUT fill:#A5D6A7
Generation-Time Composition Flow¶
The complete flow from base template to final template artifact:
flowchart TB
subgraph Input["Input"]
BASE[Base Template<br/>v1.5.0]
RECIPE[Recipe File<br/>identity-worker-service.yaml]
OVERLAY1[Identity Overlay<br/>v2.1.0]
OVERLAY2[Worker Overlay<br/>v1.0.0]
end
subgraph Process["Composition Process"]
VALIDATE[Validate Recipe<br/>& Compatibility]
LOAD[Load Base Template]
APPLY1[Apply Identity Overlay]
APPLY2[Apply Worker Overlay]
MERGE[Merge Metadata]
REPLACE[Replace Tokens]
end
subgraph Output["Output"]
FINAL[Final Template Artifact<br/>Ready for dotnet new]
end
BASE --> VALIDATE
RECIPE --> VALIDATE
OVERLAY1 --> VALIDATE
OVERLAY2 --> VALIDATE
VALIDATE --> LOAD
LOAD --> APPLY1
APPLY1 --> APPLY2
APPLY2 --> MERGE
MERGE --> REPLACE
REPLACE --> FINAL
style Input fill:#E3F2FD
style Process fill:#FFE0B2
style Output fill:#A5D6A7
Related Documents¶
- Template Architecture Specification - Core template architecture
- Template Architecture Overview - Business-oriented overview
- Template Layering Guide - Three-layer architecture guide
- Extensibility Guide - Extension point patterns
- ADR-0002: Template Layering and Submodules - Architecture decision record