# Hexagonal Project Generator (Go CLI) A command-line tool that scaffolds production-ready **Hexagonal Architecture (Ports & Adapters)** services in Go. Reference: [Hexagon](https://en.wikipedia.org/wiki/Hexagonal_architecture_(software)) This generator creates: - Full domain layer - Application/use-case layer - Infrastructure adapters - HTTP controller & router - External client adapter - DynamoDB repository - Configuration loader - `go.mod` - Makefile - Complete project folder structure - Dynamic naming based on the service name Everything is produced using `.tmpl` template files and rendered into a clean Go project. --- ## ๐ Features - Generate an entire Go project with **one command** - Full Hexagonal Architecture (Domain โ Application โ Infrastructure) - Dynamic templates using Goโs `text/template` - Automatic folder creation - AWS DynamoDB repository scaffolding - HTTP controller + router - External service adapter (generic) - Config loader - Makefile included - Ready to `go build` and `go run` --- ## ๐ Installation Install globally: ```bash go install github.com/<your-github>/go-hexagonal-cli@latest
Make sure your Go bin is in PATH:
export PATH=$PATH:$(go env GOPATH)/bin
๐ Usage
Generate a new hexagonal Go service:
hexagon init your--service
This creates a folder:
with all layers pre-configured.
๐ Generated Folder Structure
your--service/
โ
โโโ go.mod
โโโ Makefile
โ
โโโ cmd/
โ โโโ your--service/
โ โโโ main.go
โ
โโโ internal/
โโโ domain/
โ โโโ your-service/
โ โโโ entity.go
โ โโโ repository.go
โ โโโ service.go
โ
โโโ application/
โ โโโ your-service/
โ โโโ handler.go
โ โโโ request.go
โ โโโ command.go
โ
โโโ infrastructure/
โโโ http/
โ โโโ controller.go
โ โโโ router.go
โ
โโโ external/
โ โโโ client.go
โ
โโโ repository/
โ โโโ dynamo.go
โ
โโโ config/
โโโ config.go
๐ Dynamic Naming
Example:
hexagon init your--service
Automatically generates:
| Input | Output |
|---|---|
your--service |
project module: your--service |
your--service |
package name: your-service |
your--service |
service name: your-Service |
Template variables:
{{ .Project }}{{ .Package }}{{ .Service }}
Are injected into all template files.
โ๏ธ Build & Run
Build:
Run:
Dev mode:
๐งช Testing
๐ง Development (contributing to the CLI)
Run CLI directly from source:
go run cmd/hexagon/main.go init demo
Build binary:
Clean artifacts:
๐ฆ Template System
All templates live in:
Examples:
domain/entity.go.tmplapplication/handler.go.tmplinfrastructure/http/controller.go.tmplgo.mod.tmpl
These are standard Go templates processed by text/template.
๐ Contributions
Pull requests are welcome! Template improvements, new adapters, codegen features, and documentation PRs are appreciated.
๐ License
MIT Free to use, modify, and distribute.