A high-performance, secure TMDB API proxy backend written in Go. This project replicates the functionality of a Node.js streaming backend, providing a robust foundation for TV streaming applications.
This backend acts as a secure proxy to The Movie Database (TMDB) API, hiding API keys from the frontend while providing intelligent caching, monitoring, and production-grade security features.
- π Secure API Proxy: Hides TMDB API keys from frontend requests
- β‘ Intelligent Caching: In-memory cache with configurable TTL (default 1 hour)
- π‘οΈ Production Security: CORS, security headers, rate limiting, gzip compression
- π Monitoring: Health checks and performance metrics endpoints
- π Static File Serving: Serves frontend assets with SPA fallback
- π Docker Ready: Multi-stage Docker build for efficient deployment
- π§ͺ Well Tested: Unit tests for core functionality
- π Performance Optimized: Efficient request routing and memory management
- Go 1.22 or later
- TMDB API key (get one at TMDB)
-
Clone the repository
git clone https://github.com/code-xon/streaming-backend.git cd streaming-backend -
Install dependencies
go mod tidy
-
Set up environment variables
cp .env.example .env # Edit .env with your TMDB_KEY -
Run the server
go run cmd/server/main.go
The server will start on http://localhost:3000
| Variable | Default | Description |
|---|---|---|
TMDB_KEY |
TMDB API key (required) | |
PORT |
3000 | Server port |
NODE_ENV |
development | Environment (development/production) |
CACHE_TTL |
3600 | Cache TTL in seconds |
CACHE_CHECK_PERIOD |
120 | Cache cleanup interval in seconds |
RATE_LIMIT_WINDOW_MS |
900000 | Rate limit window in milliseconds |
RATE_LIMIT_MAX_REQUESTS |
100 | Max requests per window |
FRONTEND_URL |
"" | CORS allowed origin (leave empty for all) |
GET /health- System health checkGET /metrics- Performance metricsGET /api/*- TMDB API proxy
# Get trending movies
curl "http://localhost:3000/api/trending/movie/week"
# Search for movies
curl "http://localhost:3000/api/search/movie?query=batman"
# Get movie details
curl "http://localhost:3000/api/movie/550"
# Get popular TV shows
curl "http://localhost:3000/api/tv/popular"{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00Z",
"environment": "production",
"version": "1.0.0",
"uptime": 3600,
"memory": {
"used": "45.2 MB",
"total": "128.0 MB"
},
"cache": {
"stats": {
"hits": 150,
"misses": 20
},
"keys": 25
},
"api": {
"tmdb_configured": true,
"base_url": "https://api.themoviedb.org/3"
},
"server": {
"port": 3000,
"go_version": "go1.22.0"
}
}go test ./...Use Apache Bench for load testing:
# Test health endpoint
ab -n 1000 -c 10 http://localhost:3000/health
# Test TMDB proxy (replace with actual endpoint)
ab -n 100 -c 5 "http://localhost:3000/api/trending/movie/week"# Test with curl
curl -i http://localhost:3000/health
curl -i "http://localhost:3000/api/search/movie?query=test"# Build image
docker build -t streaming-backend .
# Run container
docker run -p 3000:3000 \
-e TMDB_KEY=your_api_key \
-e NODE_ENV=production \
streaming-backend- Connect your GitHub repository to Render
- Create a new Web Service
- Set the following:
- Build Command:
go build ./cmd/server - Start Command:
./server - Health Check Path:
/health
- Build Command:
- Add environment variables in Render dashboard
- Deploy!
The application can be deployed to any platform supporting Go applications:
- Heroku: Use Go buildpack
- Railway: Connect repo and set commands
- Fly.io: Use provided Dockerfile
- AWS/GCP/Azure: Container or binary deployment
streaming-backend/
βββ cmd/server/ # Application entry point
βββ internal/
β βββ cache/ # In-memory caching logic
β βββ handlers/ # HTTP request handlers
β βββ metrics/ # Metrics collection
β βββ middleware/ # HTTP middleware
βββ public/ # Static frontend files
βββ Dockerfile # Multi-stage Docker build
βββ go.mod # Go module definition
βββ README.md
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes and add tests
- Run tests:
go test ./... - Submit a pull request
Please see our Security Policy for reporting security vulnerabilities.
This project is licensed under the MIT License - see the LICENSE file for details.
Lead Developer: Ramkrishna - Project architect and core implementation
- The Movie Database (TMDB) for their excellent API
- Gin Web Framework for the HTTP framework
- Ulule Limiter for rate limiting
Made with β€οΈ in Go by code-xon