Skip to content

master-wayne7/url-shortner

Repository files navigation

URL Shortener with Go Fiber & Redis

A modern, fast URL shortener built with Go Fiber framework and Redis database, featuring a beautiful web interface and Docker deployment.

✨ Features

  • 🔗 URL Shortening: Convert long URLs into short, shareable links
  • ⏱️ Rate Limiting: 10 requests per IP per 30 minutes
  • Auto Expiry: Links expire after 24 hours
  • 🎨 Beautiful UI: Modern, responsive web interface
  • 🔧 Custom Short Codes: Optional custom URL codes
  • 📋 Copy to Clipboard: One-click copying
  • 🐳 Docker Ready: Containerized for easy deployment
  • ☁️ Cloud Deployable: Ready for Render, AWS, GCP, etc.

🏗️ Tech Stack

  • Backend: Go with Fiber framework
  • Database: Redis
  • Frontend: HTML, CSS, JavaScript
  • Containerization: Docker & Docker Compose
  • Deployment: Render (or any Docker-compatible platform)

🚀 Quick Start

Local Development

  1. Clone the repository:

    git clone <your-repo-url>
    cd shorten-url-fiber-redis
  2. Start with Docker Compose:

    docker-compose up
  3. Access the application:

    • Open http://localhost:3000 in your browser
    • Start shortening URLs!

Production Deployment

Deploy to Render in minutes:

  1. Fork this repository to your GitHub account

  2. Deploy to Render:

    • Go to render.com
    • Create new Blueprint
    • Connect your repository
    • Render will auto-detect render.yaml
  3. Access your live app:

    • Your URL: https://your-service-name.onrender.com

📖 Detailed deployment guide: DEPLOY.md

🎯 Usage

Web Interface

  1. Enter URL: Paste any long URL
  2. Custom Code (optional): Add your custom short code
  3. Shorten: Click the button to generate short URL
  4. Copy & Share: Use the copy button to share your link

API Endpoints

  • POST /api/v1 - Shorten a URL
  • GET /:shortCode - Redirect to original URL

API Example:

curl -X POST http://localhost:3000/api/v1 \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.example.com/very/long/url",
    "short": "custom123",
    "expiry": 24
  }'

Response:

{
  "url": "https://www.example.com/very/long/url",
  "short": "http://localhost:3000/custom123",
  "expiry": 24,
  "rate_limit_remaining": 9,
  "rate_limit_reset": 30
}

📁 Project Structure

shorten-url-fiber-redis/
├── api/                    # Go application
│   ├── database/          # Redis connection
│   ├── helpers/           # Utility functions
│   ├── routes/            # API routes
│   ├── static/            # Frontend files
│   ├── main.go           # Application entry point
│   ├── Dockerfile        # Container for local dev
│   └── .env              # Environment variables
├── db/                    # Redis configuration
├── docker-compose.yaml    # Local development setup
├── Dockerfile            # Production container
├── render.yaml           # Render deployment config
└── DEPLOY.md             # Deployment guide

⚙️ Configuration

Environment Variables

Variable Description Default
PORT Server port (set by deployment platform) 3000
APP_PORT Local development port :3000
DOMAIN Base domain for shortened URLs http://localhost:3000
API_QUOTA Rate limit per 30 minutes 10
DB_ADDR Redis connection string db:6379
DB_PASS Redis password (empty)

Local Development

Edit api/.env:

APP_PORT=:3000
DOMAIN=http://localhost:3000
API_QUOTA=10
DB_ADDR=db:6379
DB_PASS=

Production

Set environment variables in your deployment platform dashboard.

🔒 Security Features

  • ✅ Rate limiting per IP address
  • ✅ URL validation and sanitization
  • ✅ HTTPS enforcement in production
  • ✅ Non-root container execution
  • ✅ Input validation and error handling

🎨 Frontend Features

  • Responsive Design: Works on all devices
  • Real-time Rate Limiting: Shows remaining requests
  • Countdown Timer: Shows when rate limit resets
  • Error Handling: Clear error and success messages
  • Copy to Clipboard: Modern clipboard API with fallback
  • Form Validation: Client-side URL validation

🐳 Docker Support

Local Development

docker-compose up

Production Build

docker build -t url-shortener .
docker run -p 3000:3000 url-shortener

📊 Monitoring

  • Request Logs: Fiber middleware logging
  • Rate Limiting: Redis-based tracking
  • Error Handling: Comprehensive error responses
  • Health Checks: Built-in endpoint monitoring

🚀 Deployment Platforms

This application is ready to deploy on:

  • Render (recommended) - Deploy Guide
  • Heroku - Set environment variables and deploy
  • Railway - Connect GitHub and deploy
  • AWS/GCP - Use the production Dockerfile
  • DigitalOcean App Platform - Deploy from GitHub

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test locally with docker-compose up
  5. Submit a pull request

📄 License

This project is open source and available under the MIT License.

🆘 Support

  • Documentation: Check DEPLOY.md for deployment help
  • Issues: Create a GitHub issue for bugs or feature requests
  • Questions: Use GitHub Discussions for questions

Made with ❤️ using Go Fiber and Redis

🔗 Live Demo: Deploy your own | ⭐ Star this repo if you found it helpful!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published