Prerequisites

Ensure you have the following installed:
  • Go 1.21+: Download and Install
  • PostgreSQL: Used for all persistence.
  • Redis: Used for authentication caching.
  • NATS: Used for cross-service event synchronization (Orders, CRM, Invoices, and permission cache invalidation).

Installation

  1. Navigate to the Go backend directory:
    cd backend/go
    
  2. Download dependencies:
    go mod download
    
  3. Initialize the environment file:
    cp .env.example .env
    

Configuration

Edit the .env file with the following required variables:

Database (PostgreSQL)

POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=go_core_dev
POSTGRES_USER=postgres
POSTGRES_PASSWORD=yourpassword
POSTGRES_SSL=disable

Authentication (Better Auth)

# Must match the secret used in the Bun monolith
BETTER_AUTH_SECRET=your_hex_secret_here
Note: The Go backend queries user, organization, and role data from the shared PostgreSQL database, which is populated by Better Auth plugins (admin and organization) running on the Bun backend. Ensure the Bun backend is deployed with Better Auth plugins configured before using the Go backend.

Infrastructure

REDIS_URL=redis://localhost:6379
NATS_URL=nats://localhost:4222

Database Migrations

The project uses GORM’s AutoMigrate for schema synchronization. To run migrations and seed default data (plans, etc.):
go run cmd/migrate/main.go
To seed sample data (demo organizations, users):
go run cmd/migrate/main.go --seed-sample

Running the Server

Development Mode (with Live Reload)

We use air for hot reloading:
# Ensure air is installed
go install github.com/air-verse/air@latest

# Run air
./bin/air

Standard Run

go run cmd/server/main.go
The server will be available at http://localhost:8080.

Health Check

Verify the setup by visiting http://localhost:8080/health. It returns 200 OK if PostgreSQL, NATS, and the server are all functioning correctly.