What You Will Build
A production-ready Go REST API built on the chi router, generated from a paragraph. The generated app includes:
- The
chirouter with middleware composition - Idiomatic Go structs for every entity
sqlxdata access with prepared statements- Context-based JWT auth middleware
- Organisation-scoped multi-tenancy on every query
- A working
docker-compose.yml
Go is the right pick when you want a small, fast binary with minimal dependencies and predictable performance.
Prerequisites
- An Archiet account (free at archiet.com/register)
- Docker installed locally
- 10 minutes
Step 1: Write a Minimal PRD
Fleet is a B2B SaaS for logistics teams. Organisations sign up and invite
dispatchers. Dispatchers manage vehicles (plate, model, status) and trips
(origin, destination, vehicle, status). Only dispatchers in an organisation
see that organisation's vehicles and trips. We need registration, login, and
password reset. The service must be a fast JSON API.
Archiet extracts Organisation, User, Vehicle, and Trip, and recognises the performance-oriented JSON-API requirement that fits Go + chi.
Step 2: Open the Blueprint Wizard
Log in at archiet.com/login, click New Blueprint, paste the PRD, click Analyse, review the model.
Step 3: Choose Go (chi)
On the Generate screen, select Go (go-chi) and click Generate.
Step 4: What You Get
fleet/
├── cmd/
│ └── server/main.go # entrypoint, router wiring
├── internal/
│ ├── handlers/
│ │ ├── vehicles.go
│ │ └── trips.go
│ ├── middleware/
│ │ └── auth.go # JWT → context
│ ├── models/
│ │ ├── vehicle.go
│ │ └── trip.go
│ └── store/ # sqlx queries
├── migrations/
├── docker-compose.yml
└── go.mod
The struct and the chi handler are idiomatic Go:
// internal/models/vehicle.go
type Vehicle struct {
ID string `db:"id" json:"id"`
OrgID string `db:"org_id" json:"orgId"`
Plate string `db:"plate" json:"plate"`
Model string `db:"model" json:"model"`
Status string `db:"status" json:"status"`
}
// internal/handlers/vehicles.go
func (h *Handler) ListVehicles(w http.ResponseWriter, r *http.Request) {
orgID := middleware.OrgIDFromContext(r.Context())
var vehicles []models.Vehicle
err := h.db.SelectContext(r.Context(), &vehicles,
`SELECT id, org_id, plate, model, status FROM vehicles WHERE org_id = $1`, orgID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(vehicles)
}
The org_id is pulled from the request context (set by the auth middleware) and every query is scoped with WHERE org_id = $1.
Step 5: Run It Locally
cd fleet
cp .env.example .env
docker compose up -d
The API is at http://localhost:8080/api/. The binary starts in milliseconds. Register, log in, and the JWT middleware authenticates each request.
What to Do Next
Ship a single binary: go build ./cmd/server produces one static binary you can drop on any host.
Add goroutine workers: the generated structure leaves a clean place to add background workers if you need them — Go's concurrency primitives are right there.
Other stacks: if your team prefers a managed framework, Java Spring Boot or .NET offer the same enterprise structure with more batteries.
The generated ARCHITECTURE.md documents why chi, why sqlx, and how the auth context flows.