Skip to content

demonsjostle/goraft

Repository files navigation

Goraft

Golang RestAPI Template Goraft Logo

A Go-based backend rest api service + Hexagonal template.

📦 Tech Stack

Component Technology
Language Go
API RestAPI
Web Framework Echo
ORM Ent
Database PostgreSQL
Architecture Hexagonal (Ports & Adapters)

Project Structure

.
├── cmd/                             # Entry points ของแต่ละไบนารี (main.go)
│   ├── server/
│   │   └── main.go                  # HTTP server bootstrap
│   ├── worker/
│   │   └── main.go                  # Background worker entry point
│   └── cli/
│       └── main.go                  # CLI tool commands
│
├── pkg/                             # Public libraries ที่เปิดให้ใช้ข้ามโปรเจกต์ 
│
├── internal/
│   ├── core/                        # Business Core ตาม Hexagonal
│   │   ├── domain/                  # Entities & Value Objects
│   │   ├── port/
│   │   │   ├── inbound/             # Inbound Ports Interfaces (e.g. Handler interfaces)
│   │   │   └── outbound/            # Outbound Ports Interfaces (e.g. Repository interfaces)
│   │   └── service/                 # Application Services (Use Cases)
│   │
│   ├── adapters/                    # Secondary Adapters (implement Ports)
│   │   ├── persistence/             # Persistence Adapters (DB, Cache)
│   │   │   ├── postgres/            # PostgreSQL (Ent)
│   │   │   │   └── postgres.go
│   │   │   ├── redis/               # Redis adapter
│   │   │   └── mongo/               # MongoDB adapter
│   │   │
│   │   └── config/                  # Config Loader Adapter (Viper, Env)
│   │       ├── config.dev.yml
│   │       └── config.go
│   │
│   ├── handler/                     # Inbound Adapters (HTTP, Kafka, CLI)
│   │   ├── http/                    # Echo / Gin / Chi routers & controllers
│   │   │   └── router.go            # RegisterRoutes, Middlewares
│   │   └── kafka/                   # Kafka consumers / producers
│   │
│   └── util/                        # Utility packages (logging, middleware)
│
├── protocol/                        # API contracts / specs
│   ├── graphql/                     # GraphQL schema + codegen config
│   │   ├── schema.graphql
│   │   └── gqlgen.yml
│   ├── proto/                       # gRPC / Protobuf definitions
│   │   ├── user.proto
│   │   └── course.proto
│   ├── openapi/                     # OpenAPI / Swagger specs
│   │   ├── openapi.yaml
│   │   └── swagger-config.json
│   └── jsonschema/                  # JSON Schema definitions (optional)
│       ├── user.json
│       └── course.json
│
├── Dockerfile                       # Container build definition
├── docker-compose.yml               # Local development services
├── go.mod                           # Go module definition
└── go.sum                           # Go module checksums

Prerequisites

  • Go 1.24 or later
  • Docker and Docker Compose
  • PostgreSQL

Getting Started

Initial project

To initial new name for your project

go run ./cmd/cli/init.go

Set up environment variables:

cp .env.example .env
# Edit .env with your configuration

. Run the application:

go run cmd/server/main.go

Development

Database Migrations

The project uses Ent for database schema management. To create a new migration:

go generate ./ent

Dependencies

Main dependencies:

Hot Reload

  • (แนะนำ) air สำหรับ hot reload

About

Golang RestAPI Template

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published