DEV Community

Cover image for rdev-go-api-template: Production-ready Go API Scaffolder & CLI Generator
RL Loz
RL Loz

Posted on

rdev-go-api-template: Production-ready Go API Scaffolder & CLI Generator

rdev-go-api-template

πŸš€ The Concept

A unified Go development utility that functions simultaneously as a production-ready architectural blueprint and an automation tool. Tailored specifically for high-performance Go-Gin HTTP routing and Bun ORM data layers, it builds a secure backend foundation and automates continuous vertical-slice feature generation.


πŸ› οΈ Why, What, and How

Why

Manual backend bootstrapping and database layer setup introduce repetitive friction, architecture drift, and security vulnerabilities. This project was built to solve those challenges by providing a highly optimized stack out of the box, offering a major evolutionary leap over our previous rdev-go-ddgen utility:

  • From rdev-go-ddgen to rdev-go-api-template: The old iteration was a loose, single-purpose domain code generator. This new variation elevates the entire workflow by introducing a unified sub-command engine that handles both initial repository creation and domain generation, backed by explicit path traversal safety guards.
  • Modern Stack Integration: Replaces generic database setups with an efficient, SQL-first workflow using Bun ORM alongside the ultra-fast Go-Gin web framework.

What

A compiled, self-contained CLI tool that handles two distinct lifecycle phases:

  1. init: Scaffolds a complete API directory tree pre-configured with Gin routers, Bun connection abstractions, Docker environments, and hidden workspace management.
  2. generate: Dynamically injects architectural domain components (handlers, services, repositories) cleanly into your existing codebase.

How

Install the compiled utility globally:

go install github.com/XaiPhyr/rdev-go-api-template@v1.0.0
Enter fullscreen mode Exit fullscreen mode

1. Scaffold a New Project Tree

rdev-go-api-template init github.com/username/project
Enter fullscreen mode Exit fullscreen mode

2. Generate a Complete Domain Feature Slice

rdev-go-api-template generate -d orders
Enter fullscreen mode Exit fullscreen mode

3. Generate an Isolated Architectural Component

rdev-go-api-template generate -d orders -f handler
Enter fullscreen mode Exit fullscreen mode

βš–οΈ Trade-offs

  • SQL-First Performance vs. Heavy Abstraction: Utilizing Bun ORM yields raw SQL performance and type-safe query compilation without the bloated runtime overhead of heavier ORMs. The trade-off is that developers must write idiomatic SQL/Go code rather than relying entirely on magic graphical abstractions, keeping the application highly performant under high concurrency.
  • Immutable Compilation: All blueprint templates are baked directly into the compiled machine binary using Go's //go:embed filesystem. This ensures complete tool independence, but requires rebuilding the binary (go install) if you modify the underlying scaffolding templates.

πŸ’‘ Layman's Terms

Think of our previous tool, rdev-go-ddgen, like a specialized mechanical drill that only made holes for wall plugs. It was helpful, but you still had to build the entire house by hand first.

This new version is like a complete, heavy-duty factory machine. Not only does it instantly clear the land and assemble the entire structural frame of the house (init), but it installs the high-performance water plumbing (Go-Gin) and the electric grid wires (Bun ORM) automatically. When you need a new room added later, you just tap a button (generate), and it snaps a pre-labeled, fully wired room right into place perfectly!

Top comments (0)