Skip to content

Repository files navigation

πŸš€ Flowfull Go Starter Kit

A production-ready Go backend starter template built with Fiber, GORM, and the Flowfull/Flowless ecosystem. This starter kit implements all 7 core concepts of Flowfull architecture.

✨ Features

  • πŸ” Bridge Validation - Distributed session validation with Flowless
  • πŸ›‘οΈ Validation Modes - Layered security (DISABLED, STANDARD, ADVANCED, STRICT)
  • ⚑ HybridCache - 3-tier caching (Ristretto β†’ Redis β†’ Database)
  • πŸ”‘ Trust Tokens - PASETO v4 tokens for secure authentication
  • 🎯 Auth Middleware - Flexible route protection (RequireAuth, OptionalAuth, RequireUserType)
  • πŸ’Ύ Multi-Database - Support for PostgreSQL, MySQL, and SQLite
  • βš™οΈ Environment Config - Validated configuration with Viper

πŸ“¦ Tech Stack

πŸ—οΈ Project Structure

flowfull-go-starter/
β”œβ”€β”€ cmd/
β”‚   └── server/
β”‚       └── main.go              # Application entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── environment.go       # Configuration with Viper
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   β”œβ”€β”€ bridge_validator.go    # Bridge Validation
β”‚   β”‚   β”‚   β”œβ”€β”€ middleware.go          # Auth Middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ validation_mode.go     # Validation Modes
β”‚   β”‚   β”‚   └── types.go               # Auth types
β”‚   β”‚   β”œβ”€β”€ cache/
β”‚   β”‚   β”‚   └── hybrid_cache.go        # HybridCache implementation
β”‚   β”‚   β”œβ”€β”€ database/
β”‚   β”‚   β”‚   └── connection.go          # Database connection
β”‚   β”‚   β”œβ”€β”€ tokens/
β”‚   β”‚   β”‚   └── trust_tokens.go        # PASETO tokens
β”‚   β”‚   └── utils/
β”‚   β”‚       └── logger.go              # Zap logger
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── task.go              # Example GORM model
β”‚   └── routes/
β”‚       β”œβ”€β”€ health.go            # Health check routes
β”‚       └── api.go               # API routes
β”œβ”€β”€ scripts/
β”‚   └── generate_paseto_key.go   # Generate PASETO keys
β”œβ”€β”€ .env.example                 # Environment variables template
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .air.toml                    # Live reload config
β”œβ”€β”€ go.mod
β”œβ”€β”€ Makefile
└── README.md

πŸš€ Quick Start

Prerequisites

  • Go 1.22+ - Download
  • PostgreSQL/MySQL/SQLite - Choose your database
  • Redis (optional but recommended)

1. Clone and Setup

# Clone the repository
git clone https://github.com/yourusername/flowfull-go-starter.git
cd flowfull-go-starter

# Install dependencies
make install

# Copy environment file
cp .env.example .env

2. Configure Environment

Edit .env with your settings:

# Server
PORT=3001
ENVIRONMENT=development

# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/mydb

# Flowless Integration
FLOWLESS_API_URL=http://localhost:3000
BRIDGE_VALIDATION_SECRET=your-secret-key-min-32-chars

# Redis (optional)
REDIS_URL=redis://localhost:6379

# Auth Validation Mode
AUTH_VALIDATION_MODE=STANDARD  # DISABLED | STANDARD | ADVANCED | STRICT

3. Generate PASETO Key (Optional)

make generate-key
# Copy the generated private key to .env

4. Run Development Server

# With live reload
make dev

# Or without live reload
make build
make run

The server will start at http://localhost:3001

πŸ“š API Endpoints

Health Checks

GET /health          # Basic health check
GET /health/db       # Database health
GET /health/cache    # Cache health
GET /health/all      # Complete health check

Public Routes

GET /                # Service info
GET /api/public      # Public endpoint (no auth)

Protected Routes (Require Authentication)

GET /api/protected   # Protected endpoint
GET /api/profile     # User profile
GET /api/tasks       # List user tasks
POST /api/tasks      # Create task
GET /api/tasks/:id   # Get task
PUT /api/tasks/:id   # Update task
DELETE /api/tasks/:id # Delete task

Optional Auth Routes

GET /api/optional    # Works with or without auth

πŸ” Authentication

This starter uses Bridge Validation with Flowless for authentication.

How it works:

  1. User authenticates with Flowless
  2. Flowless generates a session_id
  3. Frontend sends session_id in header: X-Session-Id
  4. Backend validates with Flowless via Bridge Validation
  5. Session is cached in HybridCache (Ristretto + Redis)
  6. Subsequent requests use cached session (sub-millisecond latency)

Example Request:

curl -H "X-Session-Id: your-session-id" \
     http://localhost:3001/api/protected

πŸ›‘οΈ Validation Modes

Configure security level in .env:

AUTH_VALIDATION_MODE=STANDARD
Mode IP Check User-Agent Device ID Use Case
DISABLED ❌ ❌ ❌ Development only
STANDARD βœ… ❌ ❌ Basic security
ADVANCED βœ… βœ… ❌ Recommended
STRICT βœ… βœ… βœ… High security

⚑ Performance

  • Cache Hit Rate: >95% (Ristretto + Redis)
  • Auth Latency (cached): <1ms (Ristretto)
  • Auth Latency (Redis): <5ms
  • Auth Latency (Bridge): <50ms
  • Throughput: >50k req/s with cache

πŸ§ͺ Testing

# Run tests
make test

# Run tests with coverage
make test-coverage

# Run linter
make lint

# Format code
make fmt

πŸ“¦ Available Commands

make help           # Show all commands
make install        # Install dependencies
make dev            # Run with live reload
make build          # Build binary
make run            # Run binary
make test           # Run tests
make lint           # Run linter
make clean          # Clean artifacts
make generate-key   # Generate PASETO key

🐳 Docker Support

# Build image
make docker-build

# Run with docker-compose
make docker-up

# Stop
make docker-down

πŸ“– Documentation

For detailed documentation, see the /docs folder or visit:

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

πŸ“„ License

MIT License - see LICENSE for details.

πŸ™ Acknowledgments

Built with the Flowfull/Flowless ecosystem.


Made with ❀️ by the Pubflow Team

About

Engineered for massive concurrency. Build hyper-fast APIs with Gin that easily handle thousands of requests per second.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages