Template System Design (Current Implementation)
Last Updated: 2026-02-15
Status: Active
1. Overview
This document describes the current implementation design of the DistroNexus template system across metadata, core services, desktop workflow integration, PowerShell command surface, and automation validation.
2. Architectural Layers
2.1 Metadata Layer
Primary source:
config/templates.json
Key responsibilities:
- Template identity and category definition.
- Script sequencing and execution metadata.
- Version/channel options and defaults.
- Preflight checks and output artifact declarations.
2.2 Core Domain Model Layer
Primary model file:
src/Client/DistroNexus.Core/Models/Template.cs
Core entities:
TemplateTemplateScriptTemplateVersionOption/TemplateOptionValueTemplatePreflightCheckTemplateOutputArtifactTemplateApplicationResultTemplateProgressTemplateValidationResult
2.3 Service Layer
Service contract:
src/Client/DistroNexus.Core/Interfaces/ITemplateService.cs
Service implementation:
src/Client/DistroNexus.Core/Services/TemplateService.cs
Core capabilities:
- Catalog loading and caching.
- Template search/get operations.
- Apply pipeline orchestration.
- Validation and compatibility checks.
- Custom template import/export.
- Application history persistence.
2.4 Desktop Integration Layer
DI registration:
src/Client/DistroNexus.Desktop/App.xaml.cs
Wizard integration:
src/Client/DistroNexus.Desktop/Wizard/InstallWizardWorkflowViewModel.cssrc/Client/DistroNexus.Desktop/Wizard/Steps/SelectTemplateStep.cssrc/Client/DistroNexus.Desktop/Wizard/Steps/TemplateApplyStep.cs
2.5 PowerShell Surface Layer
Manifest exports:
src/PowerShell/DistroNexus.psd1
Primary cmdlets:
Get-DistroNexusTemplateApply-DistroNexusTemplateInvoke-DistroNexusTemplateAutomation
3. Runtime Data and Storage
3.1 Built-in Metadata Source
config/templates.json
3.2 User/Runtime Data (AppData)
%APPDATA%\DistroNexus\templates.json(user template cache)%APPDATA%\DistroNexus\template-application-history.json(execution history)
4. Core Execution Sequence
Execution entry:
TemplateService.ApplyTemplateAsync(templateId, instanceName, variables, progress, cancellationToken)
Sequence:
- Resolve template by ID.
- Build effective variable set.
- Run preflight checks.
- Execute scripts ordered by
Order. - Report progress via
TemplateProgress. - Persist history record.
5. Variable Resolution Strategy
Effective variables are merged in this order:
Template.VariablesTemplate.DefaultSelectionsTemplate.VersionOptions.DefaultValue(when missing)- Runtime override variables passed to apply call
Later sources override earlier ones.
6. Preflight Check Design
Preflight checks are modeled by TemplatePreflightCheck and executed before scripts.
Behavior:
- Required check failure => terminate apply operation.
- Optional check failure => warning + continue.
- Conditional applicability supports
AppliesToVariable/AppliesToValue.
7. Script Execution Design
7.1 Script Sources
Scripts may come from:
- inline content (
Content), or - relative path (
ScriptPath) resolved via allowed roots.
7.2 Script Types
- Bash scripts execute inside target WSL instance.
- PowerShell scripts execute on host context.
7.3 Ordering and Failure Handling
- Scripts are ordered by
Order. - Timeout behavior is evaluated per script (
TimeoutSeconds). ContinueOnErrordetermines whether a failed script aborts the pipeline.
8. Security Model
Path and execution guardrails in current implementation:
- absolute script path rejection,
- path traversal detection,
- allowed-root enforcement for script file resolution.
These controls prevent unbounded script-path injection during template execution.
9. Desktop User Flow Integration
Template flow in wizard:
- User reaches template selection step.
- User chooses template (or skips as supported by workflow).
- Apply step executes template and renders status/progress output.
- Completion state is propagated to final workflow state.
10. PowerShell Integration Design
10.1 Discovery
Get-DistroNexusTemplate reads and filters catalog by ID/category.
10.2 Apply
Apply-DistroNexusTemplate resolves template and executes scripts for target instance with optional variable overrides.
10.3 Automation Validation
Invoke-DistroNexusTemplateAutomation supports:
AllTemplatesorSelectedTemplatesmodes,DryRun,- capability-gated classification (
Blocked), - CI guard with explicit override,
- output artifacts (
test-results.xml,run-manifest.json,summary.md).
11. Built-in Template Topology (Current)
Current category distribution:
Development: 10Platform: 1CloudNative: 2Database: 1DataAndAI: 1
Gap note:
DevOpscategory is not currently represented as a dedicated built-in category.
12. Design Trade-offs and Constraints
-
Local-first validation over CI-first runtime execution
- safer and predictable for WSL-dependent workloads.
-
Script flexibility with path constraints
- preserves extensibility while enforcing safety boundaries.
-
Metadata-driven expansion
- minimizes core-code churn when adding new templates.
13. Known Limitations
- Capability-gated templates may classify as
Blockeddepending on host features. DevOpsbuilt-in category is pending if strict category parity is required.
14. Related Documents
docs/development/template-system-comprehensive-guide.mddocs/specs/template-system-requirements-analysis.mddocs/development/template-system-implementation-checklist.mddocs/development/template-system-acceptance-checklist.md