── 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 override
3 home, _ := os.UserHomeDir()
4 localPath := filepath.Join(home, ".exo", "templates", name)
5 if data, err := os.ReadFile(localPath); err == nil {
6 return data, nil
7 }
8
9 // Tier 2: Check embedded templates
10 if data, err := templates.FS.ReadFile(name); err == nil {
11 return data, nil
12 }
13
14 // Tier 3: Fetch from remote repository
15 return fetchRemoteTemplate(name)
16}
17
18func 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, err
26 }
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 templates
2
3import "embed"
4
5//go:embed **/*.tmpl **/**/*.tmpl
6var FS embed.FS

## Template Catalog

CategoryTemplate PathOutput File
Dockerdocker/dockerfile.tmplDockerfile (Go)
docker/node.tmplDockerfile (Node)
docker/python.tmplDockerfile (Python)
Terraform AWSterraform/aws/main.tf.tmplinfra/aws/main.tf
terraform/aws/provider.tf.tmplinfra/aws/provider.tf
terraform/aws/variables.tf.tmplinfra/aws/variables.tf
Terraform GCPterraform/gcp/main.tf.tmplinfra/gcp/main.tf
terraform/gcp/provider.tf.tmplinfra/gcp/provider.tf
terraform/gcp/variables.tf.tmplinfra/gcp/variables.tf
Terraform Azureterraform/azure/main.tf.tmplinfra/azure/main.tf
terraform/azure/provider.tf.tmplinfra/azure/provider.tf
terraform/azure/variables.tf.tmplinfra/azure/variables.tf
CI/CDci/github-actions.tmpl.github/workflows/go.yml
ci/gitlab-ci.tmpl.gitlab-ci.yml
Kubernetesk8s/deployment.yaml.tmplk8s/deployment.yaml
k8s/service.yaml.tmplk8s/service.yaml
k8s/ingress.yaml.tmplk8s/ingress.yaml
Helmhelm/Chart.yaml.tmplcharts/<name>/Chart.yaml
helm/values.yaml.tmplcharts/<name>/values.yaml
helm/templates/deployment.yaml.tmplcharts/<name>/templates/deployment.yaml
helm/templates/service.yaml.tmplcharts/<name>/templates/service.yaml
helm/templates/ingress.yaml.tmplcharts/<name>/templates/ingress.yaml
Monitoringmonitoring/prometheus.tmplmonitoring/prometheus.yml
monitoring/docker-compose.monitoring.tmplmonitoring/docker-compose.monitoring.yml
Databasedb/postgres.tmpldocker-compose.postgres.yml
db/mysql.tmpldocker-compose.mysql.yml
db/mongo.tmpldocker-compose.mongo.yml
db/redis.tmpldocker-compose.redis.yml
Grafanagrafana/dashboard.json.tmplgrafana_dashboard.json
Alertsalerts/alerts.yml.tmplalerts.yml
Makefilemakefile/Makefile.tmplMakefile
Envenv/env.tmpl.env.example
Gitignoregitignore/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 builder
3WORKDIR /app
4COPY go.mod go.sum ./
5RUN go mod download
6COPY . .
7RUN CGO_ENABLED=0 GOOS=linux go build -o /{{ .Name }}
8
9# ── Runtime Stage ──
10FROM alpine:latest
11RUN apk --no-cache add ca-certificates
12WORKDIR /root/
13COPY --from=builder /{{ .Name }} .
14EXPOSE 8080
15CMD ["./{{ .Name }}"]

## Creating Custom Templates

Override any template by placing your version in ~/.exo/templates/:

bash
# Create override directory
mkdir -p ~/.exo/templates/docker
# Copy and customize the Dockerfile template
cp $(exo template show docker/dockerfile.tmpl) ~/.exo/templates/docker/dockerfile.tmpl
# Edit to your needs
vim ~/.exo/templates/docker/dockerfile.tmpl
# Exo will now use YOUR template instead of the embedded one
exo gen docker