A production-ready Go backend for a social content aggregation platform built with Gin, Supabase, and JWT authentication.
- Fast REST API with Gin framework (~40ร faster than Martini)
- Supabase Integration for PostgreSQL database and authentication
- JWT Middleware for secure route protection
- Clean Architecture with organized project structure
- Docker Ready with multi-stage builds
- Production Optimized for horizontal scaling
| Layer | Technology | Why |
|---|---|---|
| Web Framework | Gin | Fast and ergonomic routing |
| Database & Auth | Supabase (PostgreSQL + GoTrue) | Serverless Postgres + managed identity |
| Supabase SDKs | postgrest-go, auth-go | Strongly-typed Go clients |
| JWT | golang-jwt/jwt/v5 | Standardized token flow |
| Containerization | Multi-stage Dockerfile | Small final image (~15MB) |
backend/
โโโ cmd/
โ โโโ server/
โ โโโ main.go # Application entry point
โโโ internal/
โ โโโ api/
โ โ โโโ handlers/
โ โ โ โโโ auth.go # Authentication handlers
โ โ โ โโโ content.go # Content management
โ โ โ โโโ users.go # User profiles & following
โ โ โโโ middleware/
โ โ โ โโโ jwt.go # JWT authentication middleware
โ โ โโโ routes.go # Route registration
โ โโโ supabase/
โ โ โโโ client.go # Supabase client wrapper
โ โ โโโ models.go # Database models
โ โโโ config/
โ โโโ config.go # Configuration management
โโโ Dockerfile # Multi-stage container build
โโโ docker-compose.yml # Local development setup
โโโ go.mod # Go module dependencies
โโโ README.md # This file
Create a .env file in the root directory:
PORT=8080
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your_public_key
SUPABASE_SERVICE_KEY=your_service_role_key
JWT_SECRET=your_jwt_secret_change_meRun this SQL in your Supabase SQL editor:
-- Enable UUID extension
create extension if not exists "uuid-ossp";
-- User profiles table
create table profiles (
id uuid primary key references auth.users(id),
username text unique,
bio text,
created_at timestamp with time zone default now()
);
-- Content table
create table content (
id uuid primary key default uuid_generate_v4(),
platform text check (platform in ('YouTube','Twitter','Reddit','IG')),
url text not null,
title text,
thumbnail text,
created_at timestamp with time zone default now()
);
-- Saved content relationship
create table saved_content (
id uuid primary key default uuid_generate_v4(),
user_id uuid references profiles(id),
content_id uuid references content(id),
created_at timestamp with time zone default now(),
unique(user_id, content_id)
);
-- User following relationship
create table follows (
follower_id uuid references profiles(id),
following_id uuid references profiles(id),
created_at timestamp with time zone default now(),
primary key (follower_id, following_id)
);-
Clone and setup:
git clone <repository> cd backend
-
Install dependencies:
go mod tidy
-
Set up environment:
cp .env.example .env # Edit .env with your Supabase credentials -
Run locally:
go run cmd/server/main.go
# Build and run with Docker Compose
docker compose up --build
# The API will be available at http://localhost:8080| Method | Path | Auth Required | Description |
|---|---|---|---|
GET |
/health |
โ | Health check |
POST |
/auth/signup |
โ | User registration |
POST |
/auth/login |
โ | User login (returns JWT) |
GET |
/profile/:id |
โ | Get public profile |
GET |
/feed |
โ | Get personalized feed |
POST |
/content |
โ | Save content link |
POST |
/follow/:id |
โ | Follow user |
DELETE |
/follow/:id |
โ | Unfollow user |
Sign Up:
curl -X POST http://localhost:8080/auth/signup \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"password123"}'Login:
curl -X POST http://localhost:8080/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"password123"}'Add Content (requires auth):
curl -X POST http://localhost:8080/content \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{"platform":"YouTube","url":"https://youtube.com/watch?v=example","title":"Example Video"}'docker build -t social-agg-backend .-
Push to ECR:
aws ecr create-repository --repository-name social-agg-backend docker tag social-agg-backend:latest YOUR_ECR_URI docker push YOUR_ECR_URI
-
Create ECS Task Definition with environment variables
-
Deploy with ALB for load balancing
-
Enable auto-scaling based on CPU/memory metrics
PORT=8080
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your_public_key
SUPABASE_SERVICE_KEY=your_service_role_key
JWT_SECRET=your_strong_production_secretgo test ./...CGO_ENABLED=0 GOOS=linux go build -o server ./cmd/server- Horizontal Scaling: Deploy multiple instances behind a load balancer
- Database: Supabase handles PostgreSQL scaling automatically
- Caching: Add Redis for session/feed caching when needed
- Monitoring: Integrate with CloudWatch, Grafana, or similar
- Framework Swap: Consider Fiber for even better performance
- Real-time: Add WebSocket support for live feeds
- ML Ranking: Integrate ML-based feed ranking algorithms
- API Wrappers: Use Supabase FDW for direct social platform integration
MIT License - see LICENSE file for details