Add Data Model Skill
Use this skill when creating or modifying database-backed resources.
Workflow
- Read Quick Start: Adding a Data Model for simple resources or Creating Pages with Data Models for relationships and production-ready flows.
- Add or update the Ent schema in
app/schema/<resource>.go. - Run
go generate ./app/gojang/models. - Add form structs and validation tags in
app/views/forms/forms.gowhen public UI accepts user input. - Create a feature package such as
app/products/with handlers, routes, and templates. - Register the feature route in
app/cmd/web/main.go. - Rely on admin auto-discovery for normal generated Ent models.
- Add admin overrides in
app/gojang/admin/models.goonly when custom admin metadata or behavior is needed. - Run
go test ./....
Key Patterns
- Follow
app/posts/for public CRUD with HTMX modals and authorization checks. - Use generated Ent predicate packages such as
post.IDEQ(id). - Protect create, update, and delete routes with
middleware.RequireAuth(sm, client). - Use
middleware.OwnsResource(r, ownerID)for user-owned records. - Keep model-specific public handlers outside the framework admin package.
Admin Integration
Plain generated Ent models appear in the admin registry after generation. Use RegisterModel overrides only for custom list fields, hidden fields, read-only fields, hooks, virtual inputs, or eager loading.