cli

module
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT

README

ModelHelper CLI

ModelHelper (mh) reads the structure of a database and turns it into code. Point it at a table, pick a template, and get a struct, a repository, a controller, or whatever the template describes. The templates are plain YAML files, so you can change them or write your own.

What it does

  • Explore a database. List tables, schemas and columns from a connection.
  • Generate code from templates. Combine a source table with one or more templates, and print the result, copy it to the clipboard, or write it to the right folders in your project.
  • Create projects from templates. Scaffold a whole project, folders and files, from a project template.
  • Copy data between sources. Copy tables from one SQL Server connection to another.

Supported sources: SQL Server (mssql) and PostgreSQL (postgres). There is also a built-in demo source, so you can try the CLI without a database.

Why use it when you can ask an AI?

AI assistants are good at code that has not been written before. A lot of the code in a real project is not like that. The repository for the tenth table looks like the repository for the ninth, and the same goes for the structs, the controllers and the queries. For that kind of code, a template does the job well:

  • It costs no tokens. The CLI does not call a model. Generating a file takes milliseconds, and you can spend your AI budget on the parts that need thinking.
  • The output is the same every time. The same table and template give the same code. There is nothing to re-read for surprises, and the result does not change between runs or between people.
  • Your conventions are written down once. Naming, error handling, logging and folder layout live in the template, and every table follows them.
  • It works offline and with databases that you cannot send to an external service. Code generation reads the structure of your tables, not the data.
  • Fixing a template fixes everything after it. If you change how a repository handles errors, regenerate and the change applies to every table.

This is not either/or. Use mh for the code that repeats, and an AI assistant for the rest: business logic, tests, refactoring, and writing the templates themselves. The Modelhelper skills let Claude Code write a template from your existing code, so the AI does that work once and the CLI repeats it.

Install

You need Go (see go.mod for the version). Install the latest version with:

go install github.com/Modelhelper/cli/v3/cmd/mh@latest

This puts an mh binary in $(go env GOBIN), or in $(go env GOPATH)/bin if GOBIN is not set. Make sure that folder is on your PATH.

To build from a clone instead:

git clone https://github.com/Modelhelper/cli.git
cd cli
go build -o mh ./cmd/mh

You also need a set of templates. They live in a separate repository, Modelhelper/templates. Clone it next to the CLI.

Quick start

The first time you run mh without a config, it starts a wizard and creates ~/.modelhelper/config.yaml. The wizard asks for a connection, the folders with your templates, and your programming languages.

Try it with the demo source first. No database needed:

# list the templates for Go
mh code template list --lang go

# preview a struct for the demo table "order"
mh code generate -t go-struct --demo -s order --screen

Then use a real database:

# add a connection (see `mh connection create --help` for the types)
mh connection create --help

# list the tables
mh source list

# generate a repository for dbo.Order and copy it to the clipboard
mh code generate -t go-db-repo -s dbo.Order --copy

Useful flags for mh code generate:

Flag Meaning
-t, --template Template to use. Repeat it for several templates
-s, --source Table to use as the model, as Schema.Table. Repeat it for several tables
-c, --connection Connection to use. The default connection is used if you leave it out
--screen Print the generated code
--copy Copy the generated code to the clipboard
--export-bykey Write the files into the folders defined in the project config (see below)
--overwrite Replace files that already exist
--code-only Print only the code, with no statistics
--demo Use the built-in sample tables

Using it in a project

Add a .modelhelper folder at the root of your project, next to .git. A config.yaml in it tells mh where each kind of file belongs:

version: "3.0"
name: flight-api
language: go

locations:
  model: ./src/core/models
  core-command: ./src/core/commands
  api-controller: ./src/adapters/api/controllers

Every template has a key and a fileName. With --export-bykey, mh looks up the key in locations and writes the file there, using the template's file name:

mh code generate --export-bykey \
  -t go-hex-feat-db-get-model \
  -t go-hex-gin-controller \
  -s dbo.Order

Run mh from the folder that contains .modelhelper. Templates in .modelhelper/templates/ replace global templates with the same name, which lets one project tweak a template without touching the shared set.

Create a project from a template

mh project template list
mh project create -t go-hex-api -n flight-api --dry-run   # show what would be created
mh project create -t go-hex-api -n flight-api             # create it

A project template is a folder of files with placeholders such as the project name. The folder structure is kept, including empty folders. Add -d <dir> to choose where it is created.

Commands

Command What it does
mh code generate Generate code from templates and a source
mh code template list List templates, filter by language, key, type or model
mh code template detail <name> Show one template
mh source list List the tables in a connection
mh source copy Copy data from one source to another
mh connection create/list/default/delete Manage connections
mh project create Create a project from a template
mh project Show the project in the current folder
mh language list List the configured languages
mh config open Open the config file in an editor
mh serve Start the ModelHelper web server

Run mh <command> --help for all options.

Templates

Templates are YAML files with a Go text/template body. They have a language, a type (file, block or snippet), a key, an optional file name, and the code to generate. Blocks can be included in other templates, which is how SQL for SQL Server and PostgreSQL is kept apart from the Go code that uses it.

The template format and the full set of templates are documented in Modelhelper/templates.

Agent skills

Modelhelper/skills has skills for Claude Code that help you turn existing code into a template and set up the .modelhelper folder in a project.

Contributing

Contributions are welcome. Read CONTRIBUTING.md for how to report issues, open pull requests and set up a development environment. For new features, please open an issue first.

Community

Join the community on Slack: Join ModelHelper

License

MIT, see LICENSE.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL