Core Concepts

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 -i
Defining fields for Invoice
Enter fields as name:type (e.g., title:string)
Valid types: string, text, int, uint, float, bool, datetime, date, slug, belongs_to, many_to_many
Press 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

terminal
# Blog post with title, content, and published flag
$ grit g resource Post --fields "title:string,content:text,published:bool"
# Product with name, price, and stock
$ grit g resource Product --fields "name:string,description:text,price:float,stock:uint"
# Event with title, date, and description
$ grit g resource Event --fields "title:string,description:text,start_date:datetime,end_date:datetime"
# Category with just a name
$ grit g resource Category --fields "name:string,description:text"
# Article with an auto-generated slug
$ grit g resource Article --fields "title:string,slug:slug,body:text,published:bool"

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.

terminal
$ grit remove resource Post

Syntax

usage
grit remove resource <Name>
# Shorthand alias
grit 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).

terminal
$ grit add role MODERATOR

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.

terminal
$ grit start client

grit start server

Runs go run cmd/server/main.go from the apps/api directory to start the Go API server.

terminal
$ grit start 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.

terminal
$ grit sync

How It Works

  1. Finds the project root by walking up directories looking for docker-compose.yml or turbo.json
  2. Scans all .go files in apps/api/internal/models/
  3. Parses each file using Go's AST (Abstract Syntax Tree) parser to extract struct definitions
  4. For each struct, reads field names, Go types, JSON tags, and GORM tags
  5. Maps Go types to TypeScript types and Zod validators
  6. Writes TypeScript interface files to packages/shared/types/
  7. Writes Zod schema files to packages/shared/schemas/
  8. 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.

terminal
$ grit update
→ Removing old binary: /home/user/go/bin/grit
→ Installing latest version...
✓ Grit CLI updated successfully!

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.

terminal
$ grit version
grit version 0.13.0

Quick Reference

CommandDescription
grit new <name>Scaffold a new full-stack project
grit new <name> --apiScaffold Go API only
grit new <name> --fullScaffold 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 clientStart frontend apps via pnpm dev
grit start serverStart Go API server
grit syncSync Go models to TypeScript + Zod
grit migrateRun GORM AutoMigrate for all models
grit migrate --freshDrop all tables then re-migrate
grit seedPopulate database with initial data
grit upgradeUpdate project scaffold files to latest
grit updateRemove old CLI and install latest version
grit versionPrint CLI version