CLI Commands
The Grit CLI is a single binary that scaffolds projects, generates full-stack resources, and syncs types between Go and TypeScript. Install it once and use it across all your Grit projects.
Installing the CLI
Install the Grit CLI globally using Go:
$ grit generate resource Invoice -iDefining fields for InvoiceEnter fields as name:type (e.g., title:string)Valid types: string, text, int, uint, float, bool, datetime, date, slug, belongs_to, many_to_manyPress Enter with no input when done.> number:string✓ Added number (string)> amount:float✓ Added amount (float)> status:string✓ Added status (string)> due_date:date✓ Added due_date (date)> paid:bool✓ Added paid (bool)>
More Examples
grit remove resource
Remove a previously generated resource. This deletes the Go model, service, handler, Zod schemas, TypeScript types, React hooks, resource definition, and admin page. It also cleans up all injection markers that were added when the resource was generated.
Syntax
grit remove resource <Name># Shorthand aliasgrit rm resource <Name>
The resource name should be the singular PascalCase name (e.g., Post, Product, BlogCategory) — the same name you used with grit generate resource.
grit add role
Add a new role to your project. This command updates all relevant files across the stack in one step — Go model constants, TypeScript types, Zod schemas, shared constants, and admin panel resource definitions (badge, filter, and form options).
This single command updates 7 locations across your project:
- Go model constants (RoleModerator = "MODERATOR")
- Zod schema enum validation
- TypeScript union type
- ROLES constants object
- Admin badge configuration
- Admin table filter options
- Admin form select options
The role name is automatically uppercased. Multi-word roles use underscores:grit add role CONTENT_MANAGER
grit start
Start development servers for your Grit project. Use subcommands to launch the frontend client apps or the Go API server individually.
grit start client
Runs pnpm dev from the project root, which starts all frontend apps (web, admin, expo, docs) via Turborepo.
grit start server
Runs go run cmd/server/main.go from the apps/api directory to start the Go API server.
Both commands auto-detect the project root by looking for docker-compose.yml or turbo.json, so you can run them from any subdirectory within your project.
grit sync
Parse all Go model files and regenerate the corresponding TypeScript types and Zod schemas in the shared package. Use this command whenever you manually modify a Go model and want the frontend types to stay in sync.
How It Works
- Finds the project root by walking up directories looking for docker-compose.yml or turbo.json
- Scans all .go files in apps/api/internal/models/
- Parses each file using Go's AST (Abstract Syntax Tree) parser to extract struct definitions
- For each struct, reads field names, Go types, JSON tags, and GORM tags
- Maps Go types to TypeScript types and Zod validators
- Writes TypeScript interface files to packages/shared/types/
- Writes Zod schema files to packages/shared/schemas/
- Skips the User model (which has custom hand-written schemas)
When to Use It
- ✓After manually adding or removing fields from a Go model
- ✓After changing a field's type in a Go struct
- ✓After modifying GORM tags (e.g., adding type:text)
- ✓After adding a completely new model file manually (without using grit generate)
Note: You do not need to run grit sync after using grit generate resource. The generator already creates the TypeScript types and Zod schemas for the new resource.
grit update
Update the Grit CLI itself to the latest version. This removes the current binary and installs the newest release from GitHub using go install.
Note: grit update updates the CLI tool itself. To update your project's scaffold files (admin panel, configs, web app), use grit upgrade instead.
grit version
Print the current version of the Grit CLI.
Quick Reference
| Command | Description |
|---|---|
| grit new <name> | Scaffold a new full-stack project |
| grit new <name> --api | Scaffold Go API only |
| grit new <name> --full | Scaffold everything including docs |
| grit generate resource <Name> | Generate full-stack CRUD resource |
| grit g resource <Name> | Shorthand for generate resource |
| grit remove resource <Name> | Remove a generated resource and clean up markers |
| grit add role <ROLE> | Add a new role across all project files |
| grit start client | Start frontend apps via pnpm dev |
| grit start server | Start Go API server |
| grit sync | Sync Go models to TypeScript + Zod |
| grit migrate | Run GORM AutoMigrate for all models |
| grit migrate --fresh | Drop all tables then re-migrate |
| grit seed | Populate database with initial data |
| grit upgrade | Update project scaffold files to latest |
| grit update | Remove old CLI and install latest version |
| grit version | Print CLI version |