template-extraction
Provides a 5-level framework for identifying, extracting, and adapting code from reference projects into your own.
Install
mkdir -p .claude/skills/template-extraction && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/13741" && unzip -o skill.zip -d .claude/skills/template-extraction && rm skill.zipInstalls to .claude/skills/template-extraction
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Methodology for extracting reusable code templates from open-source reference projects. Use when (1) analyzing a reference project for extractable modules, (2) creating .template files from source code, (3) migrating modules into the project, (4) planning template extraction sprints. Keywords — "extract template", "create template", "reference project", "module extraction", "migrate moduleKey capabilities
- →Analyze a reference project for extractable modules
- →Create .template files from source code
- →Migrate modules into a project
- →Plan template extraction sprints
- →Document extractable modules as Module Cards
- →Identify hardcoded values and replace them with placeholders
How it works
The skill defines a framework for identifying, extracting, and documenting reusable code modules from reference projects. It involves analyzing project structure, creating Module Cards, and transforming source files into parameterized templates.
Inputs & outputs
When to use template-extraction
- →Extract modules from projects
- →Create template files
- →Plan module migration
- →Standardize project extraction
About this skill
Template Extraction Methodology
Core Principle
能直接用绝对不自己写 — If it exists in open-source, extract it as a template. Never write from scratch.
1. The 5-Level Thinking Framework
Different operations naturally map to different granularity levels. Module is the center of gravity:
Level 1: 项目 Project → SELECT sources (which project is worth studying?)
Level 2: 层 Layer → CLASSIFY placement (backend / frontend / agent / devops)
Level 3: 模块 Module → DEFINE boundaries ★ CORE LEVEL ★
Level 4: 文件 File → EXTRACT templates (each .template file)
Level 5: 生成 Generate → ADAPT to project (AI generates final code from template)
Why Module is the Best Granularity
| Level | Too Coarse? | Too Fine? | Module is Just Right |
|---|---|---|---|
| Project | Can't reuse directly — architecture differs | — | — |
| Layer | Each layer contains very different things | — | — |
| Module | — | — | ✅ Self-contained, clear boundaries, portable |
| File | — | Loses context, missing dependencies | — |
Operation-to-Level Mapping
| Operation | Best Level | What It Means |
|---|---|---|
| 参考 Reference | 🏗️ Project | Study architecture decisions and design philosophy |
| 模板 Template | 📄 File | Atomic unit of reuse — one file with {{placeholders}} |
| 迁移 Migrate | 📦 Module | Move a cohesive feature unit (e.g., entire auth module) |
| 创建 Create | 🧱 Layer | Build project skeleton layer by layer |
| 生成 Generate | 📄 File | AI fills in file details using module context |
The Dependency Chain
Reference(Project) → Template(File) → Migrate(Module) → Create(Layer) → Generate(File)
↓ ↓ ↓ ↓ ↓
Study Distill Transport Scaffold Fill details
2. Module Card — Standard Format
Every extractable module MUST be documented as a Module Card. This is the atomic unit of the template system.
Module Card Template
## 📦 Module: {{MODULE_NAME}}
**Source**: `{{REFERENCE_PROJECT}}/{{SOURCE_PATH}}/`
**Target**: `.agent/templates/{{TARGET_PATH}}/`
**Layer**: {{LAYER}} (backend / frontend / agent / orchestration / devops)
**Priority**: {{PRIORITY}} (🔴 Critical / 🟠 High / 🟡 Medium / 🔵 Low)
### Description
{{One paragraph describing what this module does and why it's worth extracting}}
### File Manifest
| # | Source File | Template Output | Role |
|---|------------|-----------------|------|
| 1 | `source/component.tsx` | `target/component.tsx.template` | Main component |
| 2 | `source/types.ts` | `target/types.ts.template` | Type definitions |
| 3 | `source/hook.ts` | `target/hook.ts.template` | Business logic |
### Dependencies
- **npm**: `react-markdown`, `@radix-ui/popover`
- **internal**: `shared/components/ui/popover`
### Adaptation Notes
- Replace `{{API_BASE_URL}}` with project API endpoint
- Replace `{{ALIAS}}` with project path alias (`@/`)
- i18n: Wrap user-facing strings with `t()`
### Quality Checklist
- [ ] All files have `@source` annotation in header
- [ ] All `{{placeholder}}` variables documented
- [ ] Dependencies listed in package.json / requirements.txt
- [ ] Usage example provided
- [ ] Registered in `docs/templates/README.md`
3. Extraction Workflow (Step-by-Step)
Phase 1: Project-Level Analysis (参考)
Input: A reference project in `.github/references/`
Output: List of extractable modules with priority ranking
Steps:
- Scan project structure —
list_dirthesrc/orapp/directory - Identify high-value modules — Look for:
- Self-contained feature directories
- Reusable utility libraries
- Patterns not yet in our template system
- Score each module using the Value Matrix:
| Factor | Weight | Question |
|---|---|---|
| Reusability | 30% | Can this be used in 3+ projects? |
| Complexity | 25% | Would this take >2h to write from scratch? |
| Quality | 25% | Is this production-grade code? |
| Relevance | 20% | Does our project need this? |
- Output: Module Cards for top-ranked modules
Phase 2: Module-Level Extraction (模板)
Input: A Module Card
Output: .template files in `.agent/templates/`
Steps:
- Read all source files in the module
- Identify hardcoded values → Replace with
{{PLACEHOLDER}} - Remove project-specific logic → Keep only generic pattern
- Add file header annotations:
For Python:
"""
{{ModuleName}} - {{Description}}
@module {{module_path}}
@source {{reference_project}}/{{source_file_path}}
@reference {{github_url}}
@template {{template_id}}
"""
For TypeScript/TSX:
/**
* {{ComponentName}} - {{Description}}
*
* @module {{module_path}}
* @source {{reference_project}}/{{source_file_path}}
* @reference {{github_url}}
* @template {{template_id}}
*/
- Write
.templatefile to.agent/templates/{{target_path}}/ - Update documentation in
docs/templates/0X-*.md
Phase 3: Module-Level Migration (迁移)
Input: .template files for a module
Output: Working code in the project
Steps:
- Copy all template files in the module to target directory
- Remove
.templateextension - Replace all
{{PLACEHOLDER}}values with project-specific values - Install dependencies (
npm install/pip install) - Update imports — Adjust path aliases
- Add i18n — Wrap user-facing strings
- Update
@templatetag in each file to point to source template - Verify build — Run
npm run build/pytest
Phase 4: Layer-Level Creation (创建)
Input: A new layer or feature to build
Output: Complete feature skeleton
Steps:
- Identify which modules are needed for this layer
- Migrate modules in dependency order (types → hooks → components → views)
- Wire up routing — Add to
app.tsxormain.py - Connect to existing infrastructure — Auth, API client, stores
Phase 5: File-Level Generation (生成)
Input: A template file + project context
Output: Final adapted code file
Steps:
- Read the template and understand its pattern
- Analyze project context — Existing types, API endpoints, store shape
- Generate adapted code — Fill in all placeholders, adjust types, add tests
- Add proper file header with
@templateand@referencetags
4. Standard Placeholders
Use these standardized placeholder names consistently across all templates:
| Placeholder | Description | Example |
|---|---|---|
{{ModuleName}} | PascalCase module name | ChatCitation |
{{module_name}} | snake_case module name | chat_citation |
{{moduleName}} | camelCase module name | chatCitation |
{{FeatureName}} | PascalCase feature name | Document |
{{feature_name}} | snake_case feature name | document |
{{ALIAS}} | Import path alias | @ or @/ |
{{API_BASE_URL}} | API base URL | /api/v1 |
{{APP_NAME}} | Application name | Ottawa GenAI |
{{TABLE_NAME}} | Database table name | chat_sessions |
{{ROUTE_PREFIX}} | API route prefix | /chat |
5. Template File Naming Convention
.agent/templates/
├── {layer}/ # Layer directory
│ ├── {module}/ # Module directory (if multi-file)
│ │ ├── component.tsx.template # Individual template file
│ │ ├── types.ts.template
│ │ └── hook.ts.template
│ └── single-file.py.template # Single-file module
Rules:
- Extension: always
.templateappended to the real extension - Naming: match the target filename (e.g.,
chat-input.tsx.template) - Organization: mirror the project's directory structure
6. Documentation Registry
Every template must be registered in two places:
6.1 Detail Doc (docs/templates/0X-*.md)
Each layer has its own detail document:
01-backend-templates.md02-frontend-templates.md03-ai-agent-templates.md- etc.
The detail doc contains:
- Full code snippets for each template
- Source file links
- Key features and usage notes
6.2 Master Index (docs/templates/README.md)
The master index contains:
- Directory tree overview
- Source traceability table (template → reference project)
- Status summary (extracted count / pending count)
7. Decision Tree: When to Extract vs. Skip
Is this module available in a reference project?
├── YES → Is it self-contained (< 10 files, clear boundaries)?
│ ├── YES → Is it generic enough to reuse in 3+ projects?
│ │ ├── YES → ✅ EXTRACT as template
│ │ └── NO → 🔧 EXTRACT but mark as "project-specific adaptation needed"
│ └── NO → Is the valuable part isolatable?
│ ├── YES → ✅ EXTRACT the valuable subset
│ └── NO → ⏸️ SKIP — use as reference only, document patterns in ARCHITECTURE_ANALYSIS.md
└── NO → Is there a well-known npm/pip package?
├── YES → 📦 USE the package directly (e.g., `npx shadcn add`)
└── NO → ✍️ WRITE from scratch (last resort)
8. Quick Reference: Module Extraction Checklist
When extracting a module, verify each step:
- Module Card created with all fields
- Source files read and understood
- Placeholders identified and replaced with
{{STANDARD_NAME}} - Project-specific logic removed or flagged
- File headers added with
@source,@template,@reference - Dependencies documented (npm/pip packages)
- Adaptation notes written (what to change when using)
- Template files written to
.agent/templates/ - Detail doc updated (
docs/templates/0X-*.md) - Master index updated (
docs/templates/README.md) - Usage example provided in template file or docs
When not to use it
- →When a module is not self-contained or has unclear boundaries
- →When a module is not generic enough to reuse in multiple projects
- →When a well-known npm/pip package already exists for the functionality
Limitations
- →Requires manual judgment for identifying high-value modules and removing project-specific logic
- →Relies on adherence to specific documentation and file annotation standards
How it compares
This methodology provides a structured, multi-level approach to code reuse, formalizing the extraction and documentation of modules into templates rather than ad-hoc copying.
Compared to similar skills
template-extraction side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| template-extraction (this skill) | 0 | 5mo | No flags | Intermediate |
| software-architecture | 333 | 6mo | No flags | Intermediate |
| codex | 32 | 2mo | Review | Advanced |
| game-development | 70 | 6mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
software-architecture
davila7
Guide for quality focused software architecture. This skill should be used when users want to write code, design architecture, analyze code, in any case that relates to software development.
codex
Lucklyric
Invoke Codex CLI for complex coding tasks requiring high reasoning capabilities. This skill should be invoked when users explicitly mention "Codex", request complex implementation challenges, advanced reasoning, or need high-reasoning model assistance. Automatically triggers on codex-related requests and supports session continuation for iterative development.
game-development
davila7
Game development orchestrator. Routes to platform-specific skills based on project needs.
senior-fullstack
davila7
Comprehensive fullstack development skill for building complete web applications with React, Next.js, Node.js, GraphQL, and PostgreSQL. Includes project scaffolding, code quality analysis, architecture patterns, and complete tech stack guidance. Use when building new projects, analyzing code quality, implementing design patterns, or setting up development workflows.
command-name
anthropics
This skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "configure auto-discovery", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.
python-project-structure
wshobson
Python project organization, module architecture, and public API design. Use when setting up new projects, organizing modules, defining public interfaces with __all__, or planning directory layouts.