Go Gin backend generator: schema to REST API

Auxen, by Auxen Prime, generates a Go Gin (Go) backend from your database schema or a plain-English description. The output is an ordinary Go Gin project that you download and own. Build it with the Go toolchain into a single binary.

What you get

The table is read from a real generated project (71 files for the example schema). The last column is the file in that project.

AreaWhat is generatedWhere in the project
REST APICreate, read, update and delete endpoints for each entity, under /api/<entity>internal/handlers/customer_handler.go
AuthenticationRegistration and login with JWT in this example. The builder also offers OAuth2, Session, API Key, Basic Auth and OpenID Connect.internal/handlers/auth_api.go
RBACRole and permission tables, and a permission check on the protected routesinternal/middleware/rbac_middleware.go
MigrationsAn initial migration for the schemamigrations/V1__initial_schema.sql
Tests2 test files in the example (unit and integration)internal/router/integration_test.go
DockerfileBuilds the image and runs the app as a non-root user (uid 10001)Dockerfile
docker-composeRuns the app with a PostgreSQL database beside itdocker-compose.yml
CI pipelineA GitHub Actions workflow, when you choose it.github/workflows/ci.yml
API descriptionAn OpenAPI description of the APIinternal/router/openapi.go
Health checkA health endpointinternal/router/router.go
ConfigurationAn .env.example listing the settings.env.example

The example it was generated from

Entities Customer and Invoice, with Invoice many-to-one Customer, on PostgreSQL, JWT with RBAC. Options: unit tests, integration tests, Docker, GitHub Actions pipeline and migrations. Auxen adds the authentication tables (users, roles, permissions, sessions and others) around them.

Folder layout, with file counts
.github/workflows/  1 file
cmd/server/  1 file
docs/  2 files
internal/  59 files
internal/database/  1 file
internal/dto/  9 files
internal/handlers/  8 files
internal/logger/  1 file
internal/middleware/  3 files
internal/models/  13 files
internal/queries/  13 files
internal/router/  4 files
internal/seeds/  1 file
internal/services/  2 files
internal/sessions/  1 file
internal/utils/  3 files
migrations/  1 file
(project root)  7 files

Real excerpts

A generated controller internal/handlers/customer_handler.go
func (h *CustomerHandler) GetAll(c *gin.Context) {
	// Parse pagination parameters
	page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
	limit, _ := strconv.Atoi(c.DefaultQuery("limit", "20"))
	sortBy := c.DefaultQuery("sort_by", "customer_id")
	sortOrder := c.DefaultQuery("sort_order", "asc")
	// Only known columns can be sorted on; anything else sorts by the default.
	// The column goes to GORM as an identifier, never as SQL text.
	if !customerSortColumns[sortBy] {
		sortBy = "customer_id"
	}

	if page < 1 {
		page = 1
The RBAC check internal/middleware/rbac_middleware.go
	"net/http"

	"github.com/gin-gonic/gin"
)

// RequireSessionAuth rejects a request that was authenticated by api-key or
// Basic: session-management routes (logout,
// GET/DELETE sessions, api-key management) stay session-only, so a leaked key
// or password can't mint or list credentials. JWTAuthMiddleware sets authVia
// to "session"/"apikey"/"basic"; a request with none of those never reaches
// here (JWTAuthMiddleware already aborted it).
func RequireSessionAuth() gin.HandlerFunc {
The first migration, for Customer migrations/V1__initial_schema.sql
CREATE TABLE IF NOT EXISTS "customer" (
    customer_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    customer_name VARCHAR(255) NOT NULL,
    customer_email VARCHAR(255) UNIQUE NOT NULL,
    customer_birthday DATE,
    customer_active BOOLEAN NOT NULL,
    customer_gender VARCHAR(255) NOT NULL,
    customer_notes TEXT,
    customer_created_at TIMESTAMP NOT NULL
);
The Dockerfile Dockerfile
FROM golang:1.26-alpine AS build
WORKDIR /app
COPY go.mod ./
RUN go mod download
COPY . .
RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/server

FROM alpine:latest
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /app
COPY --from=build /app/main .
# Run as an unprivileged user (uid and gid 10001) that owns /app.
RUN addgroup -S -g 10001 app && adduser -S -D -H -G app -u 10001 app && chown -R app:app /app
USER 10001:10001
EXPOSE 8080
A generated test internal/router/integration_test.go
func TestSmokeCRUD(t *testing.T) {
	// Its own in-memory database: the other tests in this package share
	// file::memory: and register users first, and only the first user is an admin.
	os.Setenv("JWT_ACCESS_SECRET", "auxen-test-access-secret-at-least-32-characters")
	os.Setenv("JWT_REFRESH_SECRET", "auxen-test-refresh-secret-at-least-32-characters")

	// A private in-memory SQLite database with the app's tables: no database server needed.
	db, err := gorm.Open(sqlite.Open("file:smoke_crud?mode=memory&cache=shared"), &gorm.Config{TranslateError: true})
	if err == nil {
		err = database.Migrate(db)
	}
	if err != nil {

What it is built on

Read from the generated manifest: Gin (go.mod), GORM (go.mod), golang-jwt (go.mod), zap logging (go.mod).

Databases

Go Gin generates for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server and Amazon Redshift. It does not generate for MongoDB and Oracle.

How the generator is tested

These checks live in the Auxen repository and run against the generators themselves. They are listed here as what they do, not as a guarantee about every schema you might write.

  • Generation test (npm run test:gen): generates this stack for several example schemas, then compiles the result with the Go toolchain.
  • Runtime test (npm run test:runtime): starts the generated application, connects it to a real database, registers a user, logs in, then creates and lists records over HTTP.
  • Security scan: the generated project, including its Dockerfile and CI files, is scanned with Trivy for vulnerabilities, secrets and misconfiguration. The check fails on any secret, and on any high or critical finding that has a fix.
  • Docker build test (npm run test:docker, run on demand): builds each stack's own Dockerfile.

Running and deploying it

Build it with the Go toolchain into a single binary. You download the project and deploy it wherever you run software. Auxen does not deploy the generated backend for you yet. It has a hosted sandbox where you can run the code and try its API before you download it.

Review the code before it carries real traffic, as you would any code you did not write. The terms of service say the same: generated code is provided as is, and you are responsible for reviewing, testing and securing it.

More

Auxen is made by Auxen Prime Technologies Limited and lives at auxenprime.com. It is not affiliated with other companies that use the name Auxen.