---
name: template-generator
description: Use when you have an existing, mature project and want to reuse its structure and conventions as a template for future projects.
---

# Template Generator

## Overview

Use this skill to convert stable project memory into a reusable project template blueprint.

This skill consumes `.docs/` generated by `project-scanner` and, when present, `docs/spark/rules/KNOWLEDGE_RULES.md` generated by `knowledge-rules`. Stable Memory is descriptive truth; Knowledge Rules are prescriptive constraints.

This skill is a **Template Blueprint Builder**. The generated template must be an engineering blueprint, not a generalized copy of the source project.

**Announce at start:**

> spark template 🧩 Using template-generator to build reusable project blueprint

## Required References

Before generating `.template/`, you MUST read every reference file in this skill:

- MUST read `references/input-and-output.md`.
- MUST read `references/blueprint-pipeline.md`.
- MUST read `references/generation-contracts.md`.
- MUST read `references/reusable-ui-and-behavior.md`.

Do not skip required references because the source memory looks small, backend-only, frontend-only, familiar, or simple. If a reference section does not apply, record it as not applicable after reading it.

Do not scan raw source code unless `.docs` is incomplete, contradictory, or missing critical evidence needed to avoid an unsafe template.

## Core Contract

Templates must:

- remain reusable, deterministic, evidence-driven, and architecture-first
- stay polyglot and framework-agnostic unless the approved template source is framework-specific
- preserve proven architecture, structure, routing, API, database, testing, UI architecture, reusable units, and behavior contracts
- convert concrete business names into placeholders
- mark uncertain conclusions as `Needs Review`
- produce operational generation rules when onboarding must create folders, files, reusable units, behavior-backed pages, or starter features

Templates must not:

- scan raw source as a substitute for `.docs`
- generate a new project
- copy source business data into the template
- generalize unsupported patterns
- reduce the template to parent folders when stable memory supports deeper skeletons
- treat organization-specific rules as SPARK-wide rules

## Output Contract

Generate exactly:

```txt
.template/
├── TEMPLATE_PROFILE.md
├── TEMPLATE_WORKFLOW.md
├── FOLDER_STRUCTURE.md
├── FILE_STRUCTURE.md
├── CODE_STRUCTURE.md
├── ROUTING_STRUCTURE.md
├── API_STRUCTURE.md
├── DATABASE_STRUCTURE.md
├── TESTING_STRUCTURE.md
└── GENERATION_RULES.md
```

Physically create `.template/` and write the files to disk. Do not create other permanent files.

## Template Thinking Rules

- prefer engineering pattern over project structure
- prefer convention over implementation
- prefer architecture over technology
- prefer generic contract over concrete naming
- prefer reusable pattern over business logic
- prefer executable skeleton contracts over vague structure descriptions
- extract why before how
- evidence overrides assumptions
- unknown is better than incorrect
- never generalize unsupported patterns

## Execution Flow

1. Read `.docs/` and validate the required memory set.
2. Read `docs/spark/rules/KNOWLEDGE_RULES.md` if present.
3. Read every required reference from `references/`.
4. Build one internal blueprint from stable memory plus rule overlay.
5. Generalize business-specific names into placeholders.
6. Classify technology, dependency, copy safety, and uncertainty.
7. Project the blueprint into the exact 10 `.template` files.
8. Validate the template before reporting success.

## Non-Negotiables

- `.docs` is the source for what exists.
- `KNOWLEDGE_RULES.md` is the source for what must be enforced.
- `.template` owns how to generate.
- The internal blueprint is temporary and must never be written as its own file.
- `GENERATION_RULES.md` must be executable enough that `project-onboarding` does not guess.
- Behavior contracts and page archetypes must come from Stable Memory, Knowledge Rules, or explicit developer request.

## Checklist

- [ ] Announce skill usage.
- [ ] Read `references/input-and-output.md`.
- [ ] Read `references/blueprint-pipeline.md`.
- [ ] Read `references/generation-contracts.md`.
- [ ] Read `references/reusable-ui-and-behavior.md`.
- [ ] Read the complete `.docs` memory set.
- [ ] Read `docs/spark/rules/KNOWLEDGE_RULES.md` if present.
- [ ] Generate exactly the 10 `.template` files.
- [ ] Validate placeholders, business-neutrality, copy safety, behavior contracts, and operational rules.
- [ ] Report generated files and `Needs Review` items.
