adding-a-new-microservice
Creates and initializes a new microservice. Use when explicitly asked by the user to create a new microservice.
When & Why to Use This Skill
This Claude skill automates the end-to-end process of creating and initializing new microservices within a Go-based architecture. By leveraging the microbus-io/fabric framework, it streamlines the development workflow—from directory setup and boilerplate code generation to service blueprint configuration and main application integration—ensuring architectural consistency and reducing manual setup time.
Use Cases
- Rapid Scaffolding: Quickly generate the entire file structure and necessary boilerplate for new microservices to accelerate the transition from design to development.
- Standardized Service Creation: Enforce consistent directory structures and configuration patterns across a distributed system to maintain high-quality code standards.
- Automated Configuration: Initialize service.yaml blueprints through automated code generation to prevent manual entry errors and ensure compatibility with the fabric framework.
- Seamless System Integration: Automatically register new services into the main application lifecycle, ensuring they are correctly positioned relative to core infrastructure and ingress proxies.
| name | Adding a new microservice |
|---|---|
| description | Creates and initializes a new microservice. Use when explicitly asked by the user to create a new microservice. |
Workflow
Copy this checklist and track your progress:
Creating a new microservice:
- [ ] Step 1: Create a Directory for the New Microservice
- [ ] Step 2: Create `doc.go` with Code Generation Directive
- [ ] Step 3: Generate Initial `service.yaml`
- [ ] Step 4: Fill in `service.yaml`
- [ ] Step 5: Generate Microservice File Structure
- [ ] Step 6: Add the Microservice to the Main Application
- [ ] Step 7: Propose Features
Step 1: Create a Directory for the New Microservice
Each microservice is kept in a separate directory. Create a new directory for the new microservice.
mkdir -p myservice
cd myservice
Step 2: Create doc.go with Code Generation Directive
Create doc.go with the directive to trigger the code generator.
package myservice
//go:generate go run github.com/microbus-io/fabric/codegen
Step 3: Generate Initial service.yaml
Run go generate to create the initial service.yaml file.
Important Do not attempt to create service.yaml yourself from scratch. Always let the code generator initialize it.
Step 4: Fill in service.yaml
The service.yaml file is the blueprint of your microservice. Fill in the general section:
- The
hostdefines the host name under which this microservice will be addressable. It must be unique across the application. Use reverse domain notation, e.g.myservice.myproject.mycompany. - The
descriptionshould explain what this microservice is about.
general:
host: myservice.myproject.mycompany
description: My microservice does X, Y, and Z
Important: Do not fill in any other section of service.yaml unless explicitly asked to do so by the user.
Step 5: Generate Microservice File Structure
Run go generate again to generate the file structure of the microservice.
Step 6: Add the Microservice to the Main Application
Add the new microservice to the app in main.go, if not already added.
Note that main.go is typically located in the main directory of the project, not inside the directory of the microservice.
The order is important: add the new microservice after the core infrastructure microservices are added, and before the HTTP ingress proxy is added.
func main() {
app := application.New()
// The configurator must be first
app.Add(
configurator.NewService(),
)
// Infrastructure services
app.Add(
httpegress.NewService(),
openapiportal.NewService(),
metrics.NewService(),
)
// Add your solution microservices here
app.Add(
myservice.NewService(),
)
// HTTP ingress proxy is last
app.Add(
httpingress.NewService(),
)
err := app.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "%+v", err)
os.Exit(19)
}
}
Step 7: Propose Features
If you have an idea for what the microservice should include, prepare a proposal categorizing them by feature:
- Configuration properties
- Functional endpoints (RPCs)
- Outbound events
- Inbound event sinks
- Web handler endpoints
- Tickers (recurring operations)
- Metrics
Save the proposal in AGENTS.md, then show it to the user and seek additional instructions.