The code generator is the primary tool in Microbus for working with microservices, including the creation of new ones. You can interact with the code generator directly, or instruct a coding agent to do it for you.
Create a new directory for the new microservice. If you expect the solution to have a large number of microservice, you might want to create a nested structure. Lowercase directory names are recommended.
mkdir mydomain/myservice
Create mydomain/myservice/doc.go with the go:generate instruction that will run the code generator. It is recommended to echo the name of the directory for the name of the package.
//go:generate go run github.com/microbus-io/fabric/codegen
package myservice
service.yamlFrom within the directory, run go generate to create an empty service.yaml template.
cd mydomain/myservice
go generate
Fill in the features of the microservice in service.yaml, and go generate again to generate the skeleton code for the new microservice and its client stubs.
Implement the functionality of the microservice in service.go and test it in service_test.go.
Run go generate a final time to update the version number of the microservice.
Include the new microservice in the application in main.go if not already done so by the code generator.
app.Add(
// Add solution microservices here
myservice.NewService(),
)
Start your coding agent, e.g.:
claude
Instruct the agent to read AGENTS.md at the root of the project.
Read @AGENTS.md
Use a prompt similar to the following to create a new microservice.
Use the appropriate skill to create a new "stripe" microservice that will process credit card payments via Stripe. Place it under the @financial directory. Set its hostname to "stripe.financial.ex".
Use prompts similar to the following to add one feature at a time to the microservice:
Use the appropriate skill to add a config property for the Stripe API key.
Use the appropriate skill to create a functional endpoint "CreateIntent" that accepts a credit card number, email, and a dollar amount as arguments, and calls the Stripe API to create an intent. If successful, it should return the transaction ID.