── CORE CONCEPTS ──
Template Engine
How Exo resolves, loads, and renders Go templates into production-ready infrastructure files.
## Three-Tier Resolution
When rendering a template, Exo checks three locations in order. The first match wins:
1
Local Override
~/.exo/templates/<path>
Team or user customizations on disk
2
Embedded (Default)
templates/<path> via embed.FS
Bundled with the binary — always available
3
Remote Fetch
github.com/Harsh-BH/exo-templates/
Fetched from GitHub at runtime
## Resolution Logic
internal/renderer/render.go
1func resolveTemplate(name string) ([]byte, error) {2 // Tier 1: Check local override3 home, _ := os.UserHomeDir()4 localPath := filepath.Join(home, ".exo", "templates", name)5 if data, err := os.ReadFile(localPath); err == nil {6 return data, nil7 }89 // Tier 2: Check embedded templates10 if data, err := templates.FS.ReadFile(name); err == nil {11 return data, nil12 }1314 // Tier 3: Fetch from remote repository15 return fetchRemoteTemplate(name)16}1718func fetchRemoteTemplate(name string) ([]byte, error) {19 url := fmt.Sprintf(20 "https://raw.githubusercontent.com/Harsh-BH/exo-templates/main/%s",21 name,22 )23 resp, err := http.Get(url)24 if err != nil {25 return nil, err26 }27 defer resp.Body.Close()28 return io.ReadAll(resp.Body)29}## Embedded Template Filesystem
All default templates are compiled into the binary using Go's embed.FS:
templates/embed.go
1package templates23import "embed"45//go:embed **/*.tmpl **/**/*.tmpl6var FS embed.FS## Template Catalog
| Category | Template Path | Output File |
|---|---|---|
| Docker | docker/dockerfile.tmpl | Dockerfile (Go) |
docker/node.tmpl | Dockerfile (Node) | |
docker/python.tmpl | Dockerfile (Python) | |
| Terraform AWS | terraform/aws/main.tf.tmpl | infra/aws/main.tf |
terraform/aws/provider.tf.tmpl | infra/aws/provider.tf | |
terraform/aws/variables.tf.tmpl | infra/aws/variables.tf | |
| Terraform GCP | terraform/gcp/main.tf.tmpl | infra/gcp/main.tf |
terraform/gcp/provider.tf.tmpl | infra/gcp/provider.tf | |
terraform/gcp/variables.tf.tmpl | infra/gcp/variables.tf | |
| Terraform Azure | terraform/azure/main.tf.tmpl | infra/azure/main.tf |
terraform/azure/provider.tf.tmpl | infra/azure/provider.tf | |
terraform/azure/variables.tf.tmpl | infra/azure/variables.tf | |
| CI/CD | ci/github-actions.tmpl | .github/workflows/go.yml |
ci/gitlab-ci.tmpl | .gitlab-ci.yml | |
| Kubernetes | k8s/deployment.yaml.tmpl | k8s/deployment.yaml |
k8s/service.yaml.tmpl | k8s/service.yaml | |
k8s/ingress.yaml.tmpl | k8s/ingress.yaml | |
| Helm | helm/Chart.yaml.tmpl | charts/<name>/Chart.yaml |
helm/values.yaml.tmpl | charts/<name>/values.yaml | |
helm/templates/deployment.yaml.tmpl | charts/<name>/templates/deployment.yaml | |
helm/templates/service.yaml.tmpl | charts/<name>/templates/service.yaml | |
helm/templates/ingress.yaml.tmpl | charts/<name>/templates/ingress.yaml | |
| Monitoring | monitoring/prometheus.tmpl | monitoring/prometheus.yml |
monitoring/docker-compose.monitoring.tmpl | monitoring/docker-compose.monitoring.yml | |
| Database | db/postgres.tmpl | docker-compose.postgres.yml |
db/mysql.tmpl | docker-compose.mysql.yml | |
db/mongo.tmpl | docker-compose.mongo.yml | |
db/redis.tmpl | docker-compose.redis.yml | |
| Grafana | grafana/dashboard.json.tmpl | grafana_dashboard.json |
| Alerts | alerts/alerts.yml.tmpl | alerts.yml |
| Makefile | makefile/Makefile.tmpl | Makefile |
| Env | env/env.tmpl | .env.example |
| Gitignore | gitignore/gitignore.tmpl | .gitignore |
## Template Variables
All templates receive the ExoConfig struct. Available variables:
go
// Available in all templates via Go's text/template syntax:{{ .Name }} // Project name (e.g., "my-service"){{ .Language }} // Language (e.g., "go", "node", "python"){{ .Provider }} // Cloud provider (e.g., "aws", "gcp", "azure"){{ .CI }} // CI platform (e.g., "github-actions"){{ .Monitoring }} // Monitoring (e.g., "prometheus"){{ .Database }} // Database (e.g., "postgres")## Example: Dockerfile Template
templates/docker/dockerfile.tmpl
1# ── Build Stage ──2FROM golang:1.21-alpine AS builder3WORKDIR /app4COPY go.mod go.sum ./5RUN go mod download6COPY . .7RUN CGO_ENABLED=0 GOOS=linux go build -o /{{ .Name }}89# ── Runtime Stage ──10FROM alpine:latest11RUN apk --no-cache add ca-certificates12WORKDIR /root/13COPY --from=builder /{{ .Name }} .14EXPOSE 808015CMD ["./{{ .Name }}"]## Creating Custom Templates
Override any template by placing your version in ~/.exo/templates/:
bash
# Create override directorymkdir -p ~/.exo/templates/docker# Copy and customize the Dockerfile templatecp $(exo template show docker/dockerfile.tmpl) ~/.exo/templates/docker/dockerfile.tmpl# Edit to your needsvim ~/.exo/templates/docker/dockerfile.tmpl# Exo will now use YOUR template instead of the embedded oneexo gen docker