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 microservices, you might want to create a nested structure. Use only the lowercase letters a through z for the name of the directory.
mkdir -p mydomain/myservice
cd mydomain/myservice
Create doc.go with the go:generate directive that will run the code generator. Set the name of the package to be the same as the name of the directory.
package myservice
//go:generate go run github.com/microbus-io/fabric/codegen
Within the directory of the microservice, run go generate to generate the file structure of the microservice, including service.yaml.
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
Use a prompt similar to the following to create a new microservice.
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:
Add a config property for the Stripe API key.
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.