CLI
The Morphis CLI is the main entry point for scaffolding, development, builds, migrations, runtime, and deployment.
This page is organized as a command reference. Start with the summary, then jump to the individual command you need.
Command summary
Project bootstrap
morphis newcreates a new Morphis project from scratch.morphis new:connectionadds a database connection to an existing project.morphis new:envcreates an environment-specific env file from a server env file.morphis new:servercreates a new server with its own routes file and env file.
Code generators
morphis new:controllerscaffolds a resource-style controller.morphis new:servicescaffolds a service class with a default instance export.morphis new:transformerscaffolds a transformer class.morphis new:validatorscaffolds a validator class and related interface.morphis new:modelscaffolds a model and can introspect existing table columns.morphis sync:modelrefreshes an existing model from live database columns.morphis new:migrationcreates an empty SQL migration file.
Development and inspection
morphis devruns the selected server in watch mode.morphis route:listlists routes as a table, JSON, or OpenAPI.morphis kill:threadkills processes listening on a server port.
Build and runtime
morphis buildbundles a server intodist/<server>/.morphis startbuilds and starts the production bundle.morphis docker:buildbuilds a Docker image for a server.
Database and deployment
morphis migrateruns pending SQL migrations.morphis deploydeploys a built server to AWS, Google Cloud, or Cloudflare.
Help
morphis helpprints the command list, usage patterns, and examples.
Shared CLI behavior
Most runtime-oriented commands resolve the target environment using one of these inputs:
--server=<name>
--env=<name>
--env-file=.env.<name>--env=<name> resolves to the env file pattern .env.<env>.<server>, while the default server file remains .env.<server> when no env name is provided.
Commands that operate on servers such as dev, route:list, build, start, docker:build, kill:thread, and deploy all depend on that resolution logic.
The CLI also runs an update check before dispatching a command. Set MORPHIS_SKIP_UPDATE_CHECK=1 if you need to suppress that behavior in automation or local validation.
morphis new
Usage
morphis new <project-name>What it is for
Creates a new Morphis project with the standard folder structure, starter route file, env file, package manifest, TypeScript config, and optional database setup.
What it does
- creates the base
src/folders such asroutes,controllers,services,validators, andtypes - generates
src/index.tsandsrc/routes/api.ts - creates
.env.apiwithPORT=3000 - writes project scripts like
dev,build,start, androute:list - optionally generates
src/config/database.tsand typedsrc/types/Context.d.ts - initializes a Git repository when Git is available
Notes
- during setup, the CLI interactively asks which database to use
- choosing
No database neededskips database config generation - the generated
devscript runsmorphis dev --server=api --project=<project-name>
Example
morphis new my-backendmorphis new:connection
Usage
morphis new:connectionWhat it is for
Adds another named database connection to an existing Morphis project.
What it does
- prompts for the connection name
- prompts for the database driver
- updates
package.jsonwith any missing driver dependencies - creates or updates
src/config/database.ts - regenerates
src/types/Context.d.tssocurrent.dbstays typed - for D1, updates your env files with the required D1 variables
Notes
- the first connection becomes the default connection automatically
- after adding a non-installed driver, run
bun install - this command is interactive rather than flag-driven
morphis new:env
Usage
morphis new:env <env-name> --server=<name> [--from=.env.<name>]What it is for
Creates an environment-specific env file, usually from the base server env file.
What it does
- copies
.env.<server>by default - writes the target as
.env.<env>.<server> - injects
ENV=<env-name>at the top of the file - refuses to overwrite an existing target env file
Example
morphis new:env dev --server=apimorphis new:server
Usage
morphis new:server <server-name>What it is for
Adds another server entrypoint to an existing project.
What it does
- creates
src/routes/<server>.ts - creates
.env.<server> - auto-selects the next unused port starting from
3000 - adds
dev:<server>,build:<server>, andstart:<server>scripts topackage.json
Example
morphis new:server chatmorphis new:controller
Usage
morphis new:controller <ControllerName>What it is for
Generates a resource-style controller with list, get, create, update, and delete methods.
What it does
- requires a PascalCase name ending in
Controller - derives the route prefix from the class name
- creates a controller file in
src/controllers/ - includes
@Controller, HTTP decorators, and@Validateplaceholders for write actions
Example
morphis new:controller PostControllerNotes
PostControllerbecomes the route prefixposts- generated method bodies are empty stubs for you to fill in
morphis new:service
Usage
morphis new:service <ServiceName>What it is for
Creates a service class and a default singleton-style instance export.
What it does
- normalizes the provided name to a
SomethingServiceclass - creates the file in
src/services/ - decorates the class with
@Trace() - exports an instance such as
chatService
Example
morphis new:service ChatServicemorphis new:transformer
Usage
morphis new:transformer <TransformerName>What it is for
Creates a transformer class in src/transformers/.
What it does
- requires a PascalCase name ending in
Transformer - creates the file in
src/transformers/ - scaffolds a class extending
Transformer<any, any>with a defaulttransform(data)method
Example
morphis new:transformer PostResponseTransformermorphis new:validator
Usage
morphis new:validator <ValidatorName>What it is for
Creates a validator class with both simple-rule and custom-rule placeholders.
What it does
- requires a PascalCase name ending in
Validator - derives an entity interface name from the validator name
- creates the file in
src/validators/ - stubs
getSimpleRules()andgetRules()
Example
morphis new:validator PostValidatormorphis new:model
Usage
morphis new:model <ModelName> [--connection=<name>] [-m] [-c] [-r] [-f] [-s]What it is for
Creates a model class and optionally introspects the target database table to generate declared fields.
What it does
- resolves the target connection from
src/config/database.ts - derives the table name from the model name
- tries to introspect existing SQL columns for supported drivers
- writes the model into
src/models/ - sets the model connection name in the generated class
Supported drivers for introspection
- MySQL
- MariaDB
- PostgreSQL
- Microsoft SQL Server
- SQLite
- D1 using local SQLite storage
Important caveat
The flags -m, -c, -r, -f, and -s are currently accepted but still marked as coming soon in the implementation. The command logs TODO output for those extra scaffolds instead of generating them today.
Example
morphis new:model Post --connection=defaultmorphis sync:model
Usage
morphis sync:model <ModelName> [--connection=<name>]What it is for
Refreshes an existing model from the live table definition in the target database.
What it does
- loads the model from
src/models/<ModelName>.ts - resolves the target database connection
- introspects the live table columns
- updates the model’s declared fields to match the schema
When to use it
Run this after migrations or manual schema changes when you want the model fields to reflect the actual database shape.
morphis new:migration
Usage
morphis new:migration <name> [--connection=<name>]What it is for
Creates an empty .sql migration file for the selected connection.
What it does
- resolves the connection from
src/config/database.ts - ensures the driver supports SQL migrations
- creates the file under
migrations/<connection>/ - prefixes the filename with a timestamp
Example
morphis new:migration create-posts-tablemorphis migrate
Usage
morphis migrate [--connection=<name>]What it is for
Runs pending SQL migrations for the selected connection.
What it does
- loads the named connection from
src/config/database.ts - ensures a
migrationstable exists - reads pending files from
migrations/<connection>/ - records the migration batch after each successful file
Notes
- supported SQL migration drivers are MySQL, MariaDB, PostgreSQL, Microsoft SQL Server, SQLite, and D1
- for D1, local migrations use the configured SQLite storage path
morphis dev
Usage
morphis dev --server=<name> [--env=<name>] [--project=<name>]What it is for
Runs a Morphis server in watch mode for development.
What it does
- resolves the env file for the selected server
- runs
bun --watch - starts
src/index.tswith the selected server - passes
--project=<name>when available so multi-project process management can distinguish servers
Example
morphis dev --server=apimorphis route:list
Usage
morphis route:list --server=<name> [--format=table|json|openapi] [--title=<name>] [--version=<semver>] [--description=<text>]What it is for
Inspects the selected server and prints the registered routes.
What it does
- loads the chosen env file
- imports the selected route file
- outputs route data as a table, JSON, or OpenAPI document
Examples
morphis route:list --server=api
morphis route:list --server=api --format=json
morphis route:list --server=api --format=openapi --title="NDM API"morphis build
Usage
morphis build --server=<name> [--env=<name>]What it is for
Bundles a server for production into dist/<server>/.
What it does
- verifies
src/routes/<server>.tsexists - generates a temporary Bun entrypoint that wraps the router with
Bun.serve() - builds the server into
dist/<server>/index.js - removes the temporary entry file after the build
Example
morphis build --server=apimorphis start
Usage
morphis start --server=<name> [--env=<name>] [--project=<name>] [--no-build]What it is for
Starts the built production server.
What it does
- builds the selected server first unless
--no-buildis set - runs
dist/<server>/index.jswith the selected env file - forces
--colorlessoutput for production runtime logs
Example
morphis start --server=apimorphis docker:build
Usage
morphis docker:build --server=<name> [--env=<name>] [--version=<tag>] [--no-build]What it is for
Builds a Docker image for a Morphis server.
What it does
- optionally runs
morphis buildfirst - verifies
dist/<server>/index.jsexists - generates a temporary Dockerfile
- builds a Linux AMD64 image and loads it into the local Docker daemon
Notes
- image naming is derived from
package.jsonand the selected server and env - the command also supports an internal Lambda adapter path when invoked with
--lambda
Example
morphis docker:build --server=api --version=1.0.0morphis deploy
Usage
morphis deploy --server=<name> [--env=<name>] --target=aws|gcloud|cloudflare [--connection=<name>] [--version=<tag>] [--region=<region>] [--gcp-project=<id>] [--function=<name>] [--service=<name>] [--worker=<name>] [--d1-binding=<name>] [--d1-name=<name>] [--d1-id=<uuid>] [--max-instances=<n>] [--port=<n>] [--sleep-after=<duration>] [--no-build] [--no-docker-build] [--no-migrate]What it is for
Deploys a server to one of the supported cloud targets.
Supported targets
- AWS Lambda and ECR-based packaging
- Google Cloud Run with Artifact Registry
- Cloudflare Containers, with optional D1 migration support
What it does
- resolves the server and env file
- can build the bundle and Docker image for you
- can run migrations unless disabled
- computes sensible default image and service names from the project, server, and env
- uses cloud-specific CLIs such as AWS CLI,
gcloud,docker,curl, andwranglerdepending on the target
Notes
- this is the largest CLI command and the most infrastructure-dependent one
- Cloudflare deployment includes logic for D1 metadata, bindings, and remote migration support
morphis kill:thread
Usage
morphis kill:thread --server=<name> [--project=<name>]What it is for
Kills processes that are listening on the port defined by the selected server env file.
What it does
- reads the server port from the resolved env file
- finds listening processes on that port
- optionally filters to processes whose command line includes
--project=<name> - terminates the matching processes
Example
morphis kill:thread --server=api --project=my-backendmorphis help
Usage
morphis helpWhat it is for
Prints the built-in help screen for the CLI.
What it shows
- the full command list
- common global options
- example command invocations
You also get the same help screen when you run morphis with no command, or when you pass --help or -h.
Recommended reading order
- Start with
morphis newif you are creating a fresh project. - Continue with
morphis devandmorphis route:listfor day-to-day development. - Add
morphis new:connection,morphis new:migration, andmorphis migratewhen your project needs persistence. - Use
morphis build,morphis start,morphis docker:build, andmorphis deploywhen you move toward production.