A standardized approach to describing microservices and their relationships through structured specification file and automated parsing tools.
# Install directly with Go
go install github.com/holydocs/servicefile/cmd/servicefile@latestAdd structured comments to your Go code to describe your service:
/*service:name UserServicedescription: Handles user authentication and profile managementowner: team-authtags: auth, user-management, microservice*/package main
// Service that uses PostgreSQL for data storage/*service:uses PostgreSQLdescription: Stores user data and authentication tokenstechnology:postgresqlproto:tcp*/typeUserRepositorystruct {
db*sql.DB
}
// Service that provides gRPC APIs/*service:repliesdescription: Provides user management APIs to other servicestechnology:grpc-serverproto:grpc*/typeUserServerstruct {
repo*UserRepository
}
// Service that makes HTTP requests to external service/*service:requests NotificationServicedescription: Sends user notifications via email and SMStechnology:notification-serviceproto:http*/typeNotificationClientstruct {
httpClient*http.Client
}
// Service that replies to user requests/*service:replies Userdescription: Provides web interface for user interactionstechnology:http-serverproto:httpperson:true*/typeWebServerstruct {
router*gin.Engine
}Use the CLI tool to generate a service file from your Go code:
# Generate from current directory
servicefile generate
# Generate from specific directory
servicefile generate --dir ./my-service
# Generate recursively (default)
servicefile generate --recursive
# Specify output file
servicefile generate --output my-service.yaml
# Disable go.mod dependency inference
servicefile generate --analyze-go-mod=falseThe tool generates a servicefile.yaml with your service description:
servicefile: "0.1.0"info:
name: UserServicedescription: Handles user authentication and profile managementowner: team-authtags:
- auth
- user-management
- microservicerelationships:
- action: usesparticipant: PostgreSQLdescription: Stores user data and authentication tokenstechnology: postgresqlproto: tcp
- action: repliesdescription: Provides user management APIs to other servicestechnology: grpc-serverproto: grpc
- action: requestsparticipant: NotificationServicedescription: Sends user notifications via email and SMStechnology: notification-serviceproto: http
- action: repliesparticipant: Userdescription: Provides web interface for user interactionstechnology: http-serverproto: httpperson: trueservicefile: The version of the ServiceFile specificationinfo.name: The name of your serviceinfo.description: A description of what your service doesinfo.system: (Optional) The larger system or platform this service belongs toinfo.owner: (Optional) The team or individual responsible for this serviceinfo.repository: (Optional) The URL of repositoryinfo.tags: (Optional) A list of tags to categorize and organize your service
ServiceFile supports several relationship types:
service:uses: Service depends on another service/databaseservice:requests: Service makes requests to another serviceservice:replies: Service provides APIs for other services/personsservice:sends: Service sends messages/eventsservice:receives: Service receives messages/events
Each relationship can have:
participant: The name of the related service/resourcedescription: Description of the relationshiptechnology: Technology or product used (e.g.,postgresql,redis,firebase,kafka)external: (Optional) Whether this is an external dependency (e.g.,true,false)person: (Optional) Whether this relationship is with a person rather than a service or system (e.g.,true,false)proto: (Optional) Communication protocol used (e.g.,http,grpc,tcp,udp,amqp)tags: (Optional) A list of tags to categorize and organize the relationship (e.g.,persistence,security,critical)
ServiceFile supports documenting and extracting multiple services from a single codebase or monorepo. Each service should be defined with its own service:name comment block. Relationships can be attached to a specific service using the service:{service_name}:{action} format:
/*service:name UserServicedescription: Handles user authenticationtags: auth, user-management*/// service:UserService:uses DatabaseService// technology:postgres// description: Uses PostgreSQL for user data// tags:persistence, critical/*service:name NotificationServicedescription: Handles user notificationstags: notification, messaging*/// service:NotificationService:requests EmailService// technology:http// description: Requests email delivery// tags:external, email/*service:name WebServicedescription: Handles web interface and user interactionstags: web, frontend*/// service:WebService:replies User// technology:http// description: Provides web interface to users// person:trueWhen you run the parser, it will generate a separate YAML file for each service (e.g., userservice.servicefile.yaml, notificationservice.servicefile.yaml).
If only one service is found, the output will be a single file (e.g., servicefile.yaml).
See the internal/parser/golang/testdata/default directory for complete examples of how to document services using ServiceFile comments.