Guide

CRUD and scaffolding generators for Go

Go has no runtime reflection culture and no decorators, so the ecosystem solved repetition the other way: by generating code you can read. go generate has been in the toolchain since 2014, and the best Go libraries of the last decade are generators.

They do not all generate the same thing, though, and the word "CRUD generator" covers at least four different jobs. Knowing which one you are shopping for is most of the decision.

Star counts and activity dates checked against each project's source on 13 November 2026. Numbers move; the reasoning does not.

Four different jobs

SQL to Go

You write queries, the generator writes typed Go functions for them. No ORM, no surprises about what SQL runs. sqlc is the standard here.

Schema to everything

You describe entities in code or a DSL, the generator writes the model, the query builder and the migrations. ent and GORM gen live here.

Contract to both sides

You describe the API, the generator writes the server stubs and the clients. goa and protobuf with gRPC.

Model to the whole feature

One command writes the model, the service, the HTTP handlers, the routes, the validation, the frontend types and the admin screen. This is scaffolding in the Rails sense, and it is the thinnest category in Go.

At a glance

Go code generators compared
ToolYou writeIt writesStarsLast activity
sqlcSQL queriesTyped Go functions18.5kNovember 2026
entA Go schemaModels, queries, migrations, GraphQL17.2kOctober 2026
GORM genGORM modelsType-safe query code2.6kOctober 2026
goaA design DSLServer, client, OpenAPI6.1kNovember 2026
protobuf and gRPCA .proto fileServer, client, typesGoogleActive
GritOne commandModel to admin screenSee repoNovember 2026

The options

1. sqlc

18,467 stars · active November 2026 · MIT

You write a query in a .sql file with a name and a return shape; sqlc reads your schema and generates a typed Go function. No ORM between you and the database, no surprise N+1, and a compile error when a column disappears. It is the best-liked tool in this category by some distance.

Strengths

  • The SQL that runs is the SQL you wrote
  • A schema change breaks the build rather than production
  • No runtime dependency at all

Trade-offs

  • Dynamic filters are awkward: conditional WHERE clauses fight the model
  • You write every query, including the dull ones
  • Nothing above the database layer

Best for: Teams who like SQL and want the compiler to check it.

2. ent

17,230 stars · active October 2026 · Apache 2.0 · from Meta

Describe entities and edges in Go, and ent generates a fully typed client: queries, mutations, eager loading, migrations, and optionally a GraphQL layer. The graph model makes traversals genuinely pleasant, and the generated API is large enough to feel like learning a framework.

Strengths

  • Completely type-safe queries, including traversals
  • Migrations and a GraphQL layer come from the same schema
  • Strong on modelling relationships

Trade-offs

  • A large generated API to learn
  • Its conventions reach into how you structure the application
  • Harder to drop into an existing database than sqlc

Best for: Graph-shaped domains where relationships are the complexity.

3. GORM gen

2,560 stars · active October 2026 · MIT

If you already use GORM, gen produces type-safe query code from your models or straight from the database, so Where("naem = ?") becomes a compile error instead of an empty result. The smallest change of the three.

Strengths

  • Adds type safety without leaving GORM
  • Can generate models from an existing database
  • Small adoption cost

Trade-offs

  • You inherit GORM’s behaviour, good and bad
  • Much smaller community than sqlc or ent

Best for: Existing GORM codebases that want fewer stringly-typed queries.

4. goa

6,123 stars · active November 2026 · MIT

Design-first. Write the API in goa's DSL and it generates the server scaffolding, the client, the OpenAPI document and the transport code for HTTP and gRPC. The contract is the source of truth and the code follows it.

Strengths

  • One description produces server, client and documentation
  • The spec cannot drift from the implementation
  • HTTP and gRPC from the same design

Trade-offs

  • A DSL to learn, and the team has to edit it first every time
  • Heavy for a small service
  • Nothing about the database or the frontend

Best for: APIs with several consumers where the contract has to be enforced.

5. Full-stack scaffolders

Grit, Buffalo, PocketBase · see the full-stack comparison

The Rails sense of the word: one command writes the model, the service, the handlers, the routes, the validation and a screen. Buffalo does this for server-rendered Go, PocketBase effectively does it through its dashboard, and Grit does it through to a React admin.

Strengths

  • The widest reach: database to user interface in one command
  • Conventions that make a team’s code look alike
  • Removes the work nobody budgets for

Trade-offs

  • You adopt a project layout, not just a library
  • Regeneration is a workflow to learn
  • Hardest to retrofit into an existing codebase

Best for: New applications where the user interface is part of the deliverable.

How to choose

Decide what the source of truth is

SQL, a Go schema, a design document, or a model. Every tool here is a bet on one of those, and the bet is hard to change later because everything downstream is generated from it.

Check the generated code is readable

You will debug it. sqlc and ent both produce code you can step through, which is the strongest argument for generation over reflection: when something is wrong you can open the file and look, rather than reasoning about what a library is doing at runtime.

Check that removal is supported

Generators are judged on the second day, when a field is renamed or a resource is deleted. A tool that only adds leaves orphans: a registry entry pointing at a deleted file, a route to a handler that no longer exists. Ask what the undo looks like before you adopt one.

Do not combine too many

sqlc plus goa plus a frontend generator is three code-generation steps in one build, three sets of conventions, and three things to re-run in the right order. One is usually enough.

Where Grit fits

Grit is in the fourth category, the widest one. grit generate resource Order --fields "total:money,status:select[new,paid]" writes the Go model, the service, the handler, the routes, the migration, the Zod validation schema, the TypeScript types, the React Query hooks and the admin screen, typed against each other.

Two details that matter for a generator you will live with. Everything it writes goes into your repository and is reviewed in a pull request. And grit remove resource Order takes all of it back out, including the injections: the route registration, the sync registry, the permission catalogue, the seeder call. A generator without a removal leaves a codebase nobody can tidy.

Frequently asked questions

What is the best CRUD generator for Go?

It depends which job you mean. For SQL to typed Go, sqlc. For a schema producing models, queries and migrations, ent. For a contract producing both sides, goa. For a model producing an entire feature including the user interface, a full-stack scaffolder.

Is sqlc better than GORM?

They answer different questions. sqlc gives you exactly the SQL you wrote with compile-time checking, and makes dynamic filters awkward. GORM gives you associations, hooks and dynamic query building, and makes the SQL less predictable. Plenty of codebases use both.

Does Go have scaffolding like rails generate?

Not in the standard toolchain. Buffalo has generators for server-rendered Go, PocketBase creates collections through its dashboard, and Grit generates from the Go model through to a React admin screen. The full comparison is here.

Should generated code be committed?

Usually yes. It keeps the build reproducible without the generator installed, it makes the diff of a schema change visible in review, and it means you can read the code you are debugging. The cost is noisier pull requests, which is a smaller problem than the one it solves.

Keep reading