Prompt
How do I tie docs, APIs, and infrastructure together for each service?
Latest observation
A good way to tie docs, APIs, and infrastructure together per service is to treat each service as a single, versioned unit with one source of truth and a few tightly linked artifacts.
Recommended structure
For each service, keep these together:
- Service code
- API contract
- OpenAPI for REST
- AsyncAPI for events
- gRPC proto files if applicable
- Infrastructure as code
- Terraform, Pulumi, CDK, Helm, Kustomize, etc.
- Service documentation
- README
- runbook
- architecture notes
- operational docs
- Tests
- contract tests
- integration tests
- smoke tests
Best practice: one service, one repo or one service folder
Option 1: Polyrepo
Each service has its own repo containing:
- app code
- API spec
- infra code
- docs
This is simplest for ownership and keeping things aligned.
Option 2: Monorepo
Use a dedicated folder per service:
/services
/billing
/src
/api
openapi.yaml
/infra
main.tf
/docs
README.md
runbook.md
/users
/src
/api
/infra
/docs
This works well if you have many services and shared tooling.
What to connect
1. Docs should reference the API contract
Your service README should link to:
- API spec location
- generated docs
- auth requirements
- example requests/responses
- changelog
If possible, generate human-readable docs from the API spec so the spec stays authoritative.
2. Infra should deploy the same version as the code and API
Pin the service image/tag and any schema versions in infrastructure:
- Docker image tag
- OpenAPI version
- DB migration version
- feature flags or environment config
This avoids “API says one thing, infra runs another.”
3. CI/CD should validate the bundle
Every service pipeline should check:
- API spec is valid
- docs are updated
- infra plan applies cleanly
- contract tests pass
- service starts with declared config
Practical pattern
A strong pattern is:
- API spec is the contract
- Docs are generated from or linked to the contract
- Infra declares how that service is deployed
- CI ensures all three stay in sync
Example service layout
billing-service/
src/
api/openapi.yaml
infra/
terraform/
docs/
README.md
architecture.md
runbook.md
tests/
contract/
integration/
Naming and metadata
Add consistent metadata across all artifacts:
- service name
- owner/team
- version
- environment
- dependencies
- SLOs
- contact/on-call
You can put this in:
service.yamlcatalog-info.yamlfor Backstage- a top-level manifest
Example:
name: billing-service
owner: team-payments
language: go
api: api/openapi.yaml
infra: infra/terraform
docs: docs/README.md
If you want this to scale
Use a service catalog or portal like:
- Backstage
- Port
- OpsLevel
These can index:
- API docs
- ownership
- infra resources
- dashboards
- runbooks
Rule of thumb
If someone opens a service directory, they should immediately find:
- what it does
- how to call it
- how it is deployed
- who owns it
- how to operate it
If you want, I can give you a sample repo template or a Backstage-compatible service descriptor for this setup.