Threadtalk-backend is a production-ready REST API for a lightweight threaded discussion forum inspired by Reddit! Built with Go and optimized for AWS Lambda serverless deployment with PostgreSQL.
Live Deployment: https://threadtalk-app.vercel.app
Frontend Repository: https://github.com/v1-nce/threadtalk-frontend
- 🔐 Authentication — JWT-based auth with HTTP-only cookies (Signup/Login/Logout)
- 🗂️ Topic Management — Create and browse discussion topics
- 📝 Post System — Create, view, and soft-delete posts with search
- 💬 Threaded Comments — Nested comment trees with unlimited depth
- ⚡ Pagination — Efficient cursor-based pagination for posts
- 🛡️ Security — BCrypt hashing, rate limiting, SQL injection prevention
- 🚀 Lambda Ready — Optimized connection pooling, context-based timeouts
| Category | Technology |
|---|---|
| Framework | Go 1.24, Gin |
| Database | PostgreSQL 16, pgx/v5 |
| Auth | JWT (golang-jwt/jwt/v5) |
| Infrastructure | AWS Lambda, Docker, ECR, RDS PostgreSQL |
| CI/CD | GitHub Actions, OIDC |
- Docker Desktop — Download here. Make sure it's running before proceeding.
git clone https://github.com/v1-nce/threadtalk-backend.git
cd threadtalk-backendCreate .env in project root:
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=threadtalk
DB_HOST=db
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}?sslmode=disable
JWT_SECRET=your-secret-key
FRONTEND_URL=http://localhost:3000
PORT=8080docker-compose up --buildThis builds the Docker images and starts:
- PostgreSQL 16 — Database with persistent volume
- Backend API — Go server on
http://localhost:8080
Migrations run automatically on startup. Wait for Connected to PostgreSQL Database in the logs.
docker-compose downNote: Add
-vto also delete the database volume:docker-compose down -v
| Scenario | Command |
|---|---|
| First time setup | docker-compose up --build |
| After modifying Go code | docker-compose up --build |
| Restart without code changes | docker-compose up |
| Stop all containers | docker-compose down |
| View real-time logs | docker-compose logs -f backend |
| Reset database | docker-compose down -v then docker-compose up --build |
Why
--build? The Docker setup compiles Go to a binary. Unlike interpreted languages, Go changes require recompiling. The--buildflag rebuilds the image with your latest code.
threadtalk-backend/
├── cmd/api/main.go # Entry point
├── internal/
│ ├── db/ # Database connection & migrations
│ ├── handlers/ # HTTP handlers (auth, forum)
│ ├── middleware/ # Auth & rate limiting middleware
│ ├── models/ # Data models (User, Post, Comment)
│ ├── router/ # Route definitions
│ └── utils/ # JWT utilities
├── .github/workflows/ # CI/CD pipeline
├── Dockerfile # Multi-stage build (local + lambda)
└── docker-compose.yml # Local development setup
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/auth/signup |
Create account | No |
POST |
/auth/login |
Login (JWT cookie) | No |
POST |
/auth/logout |
Logout | No |
GET |
/api/profile |
Get profile | ✅ |
GET |
/topics |
List topics | No |
POST |
/api/topics |
Create topic | ✅ |
GET |
/topics/:id/posts |
List posts (paginated) | No |
POST |
/api/posts |
Create post | ✅ |
GET |
/posts/:id |
Get post with comments | No |
DELETE |
/api/posts/:id |
Delete post | ✅ |
POST |
/api/comments |
Create comment | ✅ |
DELETE |
/api/comments/:id |
Delete comment | ✅ |
GET |
/health |
Health check | No |
See API.md for complete documentation with request/response examples.
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | ✅ |
JWT_SECRET |
JWT signing key (min 32 chars recommended) | ✅ |
FRONTEND_URL |
CORS origin (e.g., http://localhost:3000) |
✅ |
PORT |
Server port | No (default: 8080) |
This repository automatically deploys to AWS Lambda when you push to main.
- You push code to the
mainbranch - GitHub Actions detects the push and starts the pipeline
- The pipeline authenticates with AWS using OIDC (no passwords stored)
- It builds a Docker image optimized for Lambda
- The image is pushed to Amazon ECR (container registry)
- Lambda is updated to use the new image
- Your changes are live!
GitHub Secrets (Settings → Secrets → Actions):
| Secret | What It Is |
|---|---|
ECR_REPOSITORY |
Your ECR repository name (e.g., threadtalk-backend) |
LAMBDA_FUNCTION_NAME |
Your Lambda function name |
AWS Resources:
| Resource | Purpose |
|---|---|
| ECR Repository | Stores your Docker images |
| Lambda Function | Runs your API (configured for container images) |
| IAM Role | Lets GitHub authenticate via OIDC |
| RDS PostgreSQL | Production database |
The Dockerfile has two modes:
| Target | Command | Use Case |
|---|---|---|
local |
docker-compose up --build |
Local development |
lambda |
docker build --target lambda . |
Production (includes Lambda adapter) |
The Lambda build adds the AWS Lambda Web Adapter so the same Go HTTP server works on both your machine and Lambda.
- Password Hashing — BCrypt (cost 10)
- JWT Tokens — 24h expiration, HTTP-only cookies
- SQL Injection — Parameterized queries only
- Rate Limiting — 1 req/s (auth), 5 req/s (public)
- CORS — Restricted to configured origins
Want to contribute? Here's how:
Click the "Fork" button on GitHub to create your own copy.
git clone https://github.com/YOUR_USERNAME/threadtalk-backend.git
cd threadtalk-backendgit checkout -b feature/your-feature-nameUse descriptive names like feature/add-user-avatars or fix/login-timeout.
- Set up the local environment (see Quick Start)
- Make your code changes
- Test locally with
docker-compose up --build - Verify the API works as expected
git add .
git commit -m "Add: description of your changes"
git push origin feature/your-feature-name- Go to the original repository on GitHub
- Click "Pull Requests" → "New Pull Request"
- Select your fork and branch
- Describe your changes and submit
Gemini 3.0 Pro was only used for research, information gathering and to tutor myself to learn new technologies.