Add a CRUD resource to an existing LiveTemplate app with database schema, queries, handler, and template
Installation
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Add a CRUD resource to an existing LiveTemplate app with database schema, queries, handler, and template
keywords
["lvt","livetemplate","lt"]
category
core
version
1.0.0
lvt-add-resource
Adds a full CRUD (Create, Read, Update, Delete) resource to an existing LiveTemplate application. This skill intelligently infers field types, generates database migrations, SQL queries, Go handlers, and HTML templates.
🎯 ACTIVATION RULES
Context Detection
This skill typically runs in existing LiveTemplate projects (.lvtrc exists).
✅ Context Established By:
Project context - .lvtrc exists (most common scenario)
Agent context - User is working with lvt-assistant agent
Keyword context - User mentions "lvt", "livetemplate", or "lt"
With Context:
✅ "add a posts resource"
✅ "create a products resource with name and price"
✅ "generate CRUD for tasks"
Without Context (needs keywords):
✅ "add a posts resource to my lvt app"
✅ "use livetemplate to create a products resource"
❌ "add a posts resource" (no context, no keywords)
User Prompts
This skill should activate when the user requests to add a resource to their app:
Explicit prompts:
"Add a [resource] resource to my app"
"Generate CRUD for [resource] with [fields]"
"Create a [resource] with [field1], [field2], [field3]"
"I need a [resource] resource with [field descriptions]"
Implicit prompts:
"Let's add [resource] to the app"
"I want to track [resources]"
"Can you add [resource] functionality?"
"Create [resource] management"
Examples:
"Add a posts resource with title, content, and published"
"Generate CRUD for products with name, price, quantity"
"Create a users resource with name email password"
"I need tasks with title description due_date completed"
Context Awareness
Before executing this skill, verify:
In Project Directory:
Check for .lvtrc file (confirms it's an lvt project)
Check for go.mod (confirms it's a Go project)
Check for database/ directory
Dependencies Available:
lvt binary is installed and accessible
Project was created with lvt new
Not Already Exists:
Check if resource directory already exists
Warn user if resource name conflicts
⚠️ CONFIRM BEFORE EXECUTING
When adding a resource, show what will be created and ask for confirmation:
I'll add a **products** resource with these fields:
- name (string)
- price (float)
- quantity (int)
- description (text)
This will create:
- app/products/products.go (handler)
- app/products/products.tmpl (template)
- database/migrations/..._create_products.sql
- Update database/queries.sql
**Proceed?**
- **yes** - create the resource
- **change X** - modify fields or name
- **advanced** - explore options (pagination, edit mode, references)
- **no** - cancel
If user says "advanced", show:
⚙️ **Advanced Resource Options**
| Option | Current | Alternatives |
|--------|---------|--------------|
| Pagination | infinite scroll | page numbers |
| Edit Mode | modal | inline, page |
| Page Size | 20 | 10, 50, 100 |
**Field modifiers:**
- `field:references:table` - foreign key relationship
- `field:references:table:CASCADE` - with cascade delete
What would you like to change?
Then WAIT for user response before running commands.
Checklist
Confirmation Phase:
Step 1: Verify we're in an lvt project directory
Check for .lvtrc file
Check for go.mod file
Check for database/ directory
If missing, inform user they need to create an app first (use lvt:new-app skill)
Step 2: Extract resource details from user request
Resource name (singular form preferred, e.g., "post", "user", "task")
Field list with types (explicit or to be inferred)
Step 3: Present what will be created and ask for confirmation
Show resource name and fields
Show files that will be created/updated
Wait for user approval
Execution Phase (after approval):
Step 4: Validate prerequisites
Verify lvt command is available
Check current directory is project root
Step 5: Parse and organize fields
If user provides field:type format, use as-is
If user provides just field names, rely on lvt's type inference
Any field ending with: _at, _date, _time, or ending with date
Foreign Key References
To create foreign key relationships:
Format: field_name:references:table_name
With custom ON DELETE: field_name:references:table_name:CASCADE
Options: CASCADE, SET NULL, RESTRICT, NO ACTION
Example:user_id:references:users:CASCADE
Example Commands
# Simple resource with type inference
lvt gen resource posts title content published
# Explicit types
lvt gen resource products name:string price:float quantity:int enabled:bool
# With foreign key
lvt gen resource comments post_id:references:posts:CASCADE content author
# With pagination options
lvt gen resource articles title content --pagination numbers --page-size 10
# With edit mode
lvt gen resource tasks title description due_date --edit-mode page
Error Handling
If resource directory already exists:
Warn user about potential data loss
Ask for confirmation before proceeding
Suggest using a different name
If not in an lvt project:
Check for .lvtrc file
If missing, inform user they need to create an app first
Suggest using lvt:new-app skill
If field names are invalid:
Check for Go identifier validity (alphanumeric + underscore, no spaces)
Suggest corrections if needed
Avoid SQL reserved keywords
If migration fails:
Show migration error output
Check for common issues (syntax, constraints, duplicates)
Suggest manual review of migration file
If build fails after generation:
Run go mod tidy again
Check for import errors
Verify sqlc generated models exist
Check route injection didn't break main.go syntax
Success Response
After successful resource generation, provide:
✅ Resource '[name]' generated successfully!
📁 Files created:
- app/[resource]/[resource].go
- app/[resource]/[resource].tmpl
- app/[resource]/[resource]_test.go
- database/migrations/[timestamp]_create_[table].sql
📝 Files updated:
- database/schema.sql
- database/queries.sql
- cmd/[app]/main.go (route: /[resource])
✅ Migration applied successfully
✅ Models generated successfully
✅ App builds successfully
🚀 Next steps:
1. Start your app: lvt serve (or go run main.go)
2. Visit: http://localhost:8080/[resource]
3. Test CRUD operations in your browser
Common User Scenarios
Scenario 1: Blog posts
User: "Add a posts resource with title content published"