web-production-saas-starter/go-b2b-starter/docs/README.md
2025-12-16 18:54:41 +04:00

3.1 KiB

Go B2B SaaS Starter Kit

A production-ready Go backend for B2B SaaS applications with multi-tenant architecture, authentication, billing, and file management.

Quick Start

make run-deps      # Start PostgreSQL & Redis
make migrateup     # Run migrations
make dev           # Start dev server with hot reload

Documentation

Core Systems

  • Architecture - Clean Architecture, dependency injection, module patterns
  • Database - SQLC workflow, migrations, store adapters
  • Authentication - Stytch integration, RBAC, middleware
  • Billing - Polar.sh integration, subscriptions, paywall

Infrastructure

Project Structure

The codebase follows Clean Architecture with three main layers:

API Layer (src/api/) - HTTP handlers and routes Application Layer (src/app/) - Business logic organized by modules Shared Layer (src/pkg/) - Reusable infrastructure packages

Each application module contains:

  • domain/ - Entities, interfaces, business rules
  • app/ - Services (use cases)
  • infra/ - Repository implementations
  • module.go - Dependency injection setup

Common Commands

# Development
make dev                # Run dev server with hot reload (Air)
make server             # Run server without hot reload
make build              # Build production binary

# Dependencies
make run-deps           # Start PostgreSQL & Redis in Docker
make stop-deps          # Stop and remove Docker containers

# Database
make migrateup          # Apply all migrations
make migratedown        # Rollback migrations
make sqlc               # Generate code from SQL
make create-migration   # Create new migration file

# Code Generation
make swagger            # Generate Swagger docs

# Testing
make test               # Run tests with coverage

# Utilities
make clear-rbac-cache   # Clear RBAC and JWKS caches from Redis

Tech Stack

  • Language: Go 1.25+
  • HTTP: Gin framework
  • Database: PostgreSQL with SQLC
  • Auth: Stytch B2B
  • Payments: Polar.sh
  • Storage: Cloudflare R2
  • DI: uber-go/dig

Environment Setup

Copy example.env to app.env and configure:

# Database
DATABASE_HOST=localhost
DATABASE_NAME=b2b_starter

# Authentication
STYTCH_PROJECT_ID=your-project-id
STYTCH_SECRET=your-secret

# Billing
POLAR_ACCESS_TOKEN=your-token
POLAR_WEBHOOK_SECRET=your-secret

# File Storage
R2_ACCOUNT_ID=your-account
R2_ACCESS_KEY_ID=your-key
R2_SECRET_ACCESS_KEY=your-secret
R2_BUCKET_NAME=files

See example.env for all configuration options.

Getting Started

  1. Understand the architecture: Read Architecture
  2. Set up the database: Follow Database
  3. Configure authentication: See Authentication
  4. Build your first API: Follow API Development