Chapter 4
Code Generation & Type Sync
The commands that do 80% of the boilerplate so you focus on the actual product.
By the end of this chapter you'll be able to
- Generate a full resource end-to-end with one command and explain every token in it
- Identify each of the 8 generated files and what to edit when defaults aren't enough
- Pick the right field type for slugs, images, videos, tag lists, money, and rich text
- Model one-to-one, one-to-many, and many-to-many relationships with belongs_to and many_to_many
- Choose between inline --fields and YAML --from for the situation
- Keep TypeScript types in sync with Go models
Lessons
Module: Resources
What is a resource?
Model + handler + service + types + routes — the standard slice.
Anatomy of grit generate — Contact end-to-end
Every token of the command, the full field-type table, the three ways to run it.
Touring what got generated
Read every one of the 8 generated files for Contact and connect them mentally.
Module: Going deeper on fields
Field types deep dive — slug, images, video, tags, defaults
The patterns you reach for once a plain string isn't enough — with cookbook recipes.
File fields + Excel I/O
:file: / :files: syntax, FileRef lifecycle that stops bucket leaks, five dropzone variants, and the v3.31.35 client-side Excel import/export.
Relationships — one-to-one, one-to-many, many-to-many
belongs_to + many_to_many cover every cardinality. Three runnable examples.
Short form vs long form (inline --fields vs YAML --from)
When each shines, and exactly what the long form lets you express that the short form can't.
Module: Keeping types aligned
Module: Customising the generated UI
Customising admin forms
The 17 field types, helper text, multi-step flows, when to drop out of the declarative form.
Customising admin tables (incl. column packing)
Formats, badges, filters, and the new cell() render — fit 5 fields into 2 columns.
Using the generated API from the web app
The auto-generated React Query hook + shared Zod schemas — list, create, update, delete.
Public catalog cheatsheet — Category + Product
Move catalog reads out of the protected group; cheatsheet for list, detail, by-category, related products.
Module: Going public
grit expose form / table — surfacing resources outside the admin
One command per resource emits a Next.js page wired to the shared schema + React Query hook.
Public form sharing — token-gated submissions
Generate a shareable link for any resource. Optional bcrypt password. No new endpoints.
Form-share schema + editable shares — v3.31.43
Public form now renders the resource's actual fields; admin can edit label + password after creation.
Protecting web pages — middleware + ProtectedWebRoute
Two patterns, one command. SSR cookie gate for whole sections, client wrapper for role gates.
Chapter assignment
Generate Order + items
Generate an `Order` resource with fields: customerId, total, status. Add an `OrderItem` resource that belongs to Order. Run `grit sync` so the frontend types match. Create one Order from the admin panel.
See success criteriaLesson 1 takes ~5 min.
Start chapterSpot a typo? Have an idea?
Help us improve this chapter. One click opens a GitHub issue with this chapter's URL pre-filled — suggest a clearer wording, report a bug, or request a new lesson. The course keeps improving thanks to learners like you.
Suggest an improvement on GitHub