code-generator
When to use this skill
Use this skill whenever the user wants to:
- Generate functions, classes, or modules with proper documentation and error handling
- Scaffold a new project with configuration files and directory structure
- Create boilerplate code (CRUD controllers, service layers, data models)
- Refactor or optimize existing code structure
- Generate code from templates or specifications
How to use this skill
Workflow
- Clarify requirements - Identify the target language, framework, and coding conventions
- Choose the generation type - Function/class, module/package, or full project scaffold
- Generate code - Produce complete, documented, tested code following the patterns below
- Validate output - Ensure the code compiles/runs and follows project conventions
Code Generation Patterns
Function generation (Python example):
def calculate_order_total(
items: list[OrderItem],
discount_pct: float = 0.0,
tax_rate: float = 0.08,
) -> Decimal:
"""Calculate the total price for an order including tax and discount.
Args:
items: List of order items with price and quantity.
discount_pct: Discount percentage (0.0 to 1.0).
tax_rate: Tax rate to apply after discount.
Returns:
Final order total as a Decimal rounded to 2 places.
Raises:
ValueError: If discount_pct is not between 0 and 1.
"""
if not 0 <= discount_pct <= 1:
raise ValueError(f"discount_pct must be 0-1, got {discount_pct}")
subtotal = sum(item.price * item.quantity for item in items)
discounted = subtotal * Decimal(1 - discount_pct)
total = discounted * Decimal(1 + tax_rate)
return total.quantize(Decimal("0.01"))
Project scaffold (TypeScript/Node):
my-service/
├── src/
│ ├── controllers/ # Route handlers
│ ├── services/ # Business logic
│ ├── models/ # Data models / DTOs
│ ├── middleware/ # Auth, logging, error handling
│ └── index.ts # Entry point
├── tests/
│ ├── unit/
│ └── integration/
├── package.json
├── tsconfig.json
└── README.md
Supported Languages
- Python (with type hints, docstrings, pytest)
- JavaScript / TypeScript (ESM, JSDoc or TSDoc)
- Java (JavaDoc, Maven/Gradle)
- Go (godoc, modules)
- Rust (rustdoc, Cargo)
Best Practices
- Always include error handling - Validate inputs, use typed exceptions, return meaningful error messages
- Add documentation - Every public function/class gets a docstring with params, returns, and raises
- Follow language conventions - PEP 8 for Python, gofmt for Go, Prettier for TypeScript
- Generate tests alongside code - At minimum, one happy-path and one error-path test per function
- Use type annotations - Catch bugs early with static typing where the language supports it
Keywords
代码生成, code generation, scaffold, boilerplate, template, 函数, 类, 模块, project structure, code scaffold, 项目脚手架
More from partme-ai/full-stack-skills
vite
Guidance for Vite using the official Guide, Config Reference, and Plugins pages. Use when the user needs Vite setup, configuration, or plugin selection details.
68element-plus-vue3
Provides comprehensive guidance for Element Plus Vue 3 component library including installation, components, themes, internationalization, and API reference. Use when the user asks about Element Plus for Vue 3, needs to build Vue 3 applications with Element Plus, or customize component styles.
63vue3
Guidance for Vue 3 using the official guide and API reference. Use when the user needs Vue 3 concepts, patterns, or API details to build components, apps, and tooling.
54electron
Build cross-platform desktop applications with Electron, covering main/renderer process architecture, IPC communication, BrowserWindow management, menus, tray icons, packaging, and security best practices. Use when the user asks about Electron, needs to create desktop applications, implement Electron features, or build cross-platform desktop apps.
51uniapp-project
Provides per-component and per-API examples with cross-platform compatibility details for uni-app, covering built-in components, uni-ui components, and APIs (network, storage, device, UI, navigation, media). Use when the user needs official uni-app components or APIs, wants per-component examples with doc links, or needs platform compatibility checks.
40ascii-cli-logo-banner
Entry point for ASCII CLI banners that routes to the Python built-in font skill or figlet.js/FIGfont skill. Use when the user wants a startup banner, ASCII logo, terminal welcome screen, or CLI branding for a service.
38