kratos new command creates a new Kratos service project by cloning a template repository and configuring it with your project name.
Usage
Description
This command scaffolds a new microservice project using a predefined template. It supports both the standard service template and admin template, or you can specify a custom repository. The command will:- Clone the template repository
- Rename the project to your specified name
- Update the directory structure
- Set up the initial project configuration
Arguments
project-name(optional) - The name of the project to create. If not provided, you’ll be prompted to enter it interactively.
Flags
Custom repository URL to use as a template. Overrides the default template selection.
Specific branch of the repository to use. Defaults to the repository’s default branch.
Timeout duration for the project creation operation.
Retain go.mod from parent directory. Use this when creating a project within an existing Go module.
Available Templates
When you don’t specify a custom repository, Kratos offers two built-in templates:Service Template
Repository:
https://github.com/go-kratos/kratos-layout.gitStandard microservice template with HTTP and gRPC supportAdmin Template
Repository:
https://github.com/go-kratos/kratos-admin.gitAdmin service template with additional administrative featuresExamples
Basic Usage
Create a new service with the default template:Create with Custom Name
Use Custom Repository
Specify Branch
Create Within Existing Module
Create with Absolute or Home Path
What Gets Created
After runningkratos new, you’ll have a project structure like:
Next Steps
After creating your project:If the project directory already exists, you’ll be prompted to confirm whether you want to override it.
Related Commands
kratos run- Run your newly created projectkratos proto- Generate code from proto files